Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ckanext-odsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Transparenzportal
ckanext-odsh
Commits
74cc4f50
Commit
74cc4f50
authored
5 years ago
by
Benjamin Becker
Browse files
Options
Downloads
Patches
Plain Diff
adds tests for gather_collection_info, refactors for testability
parent
8930bf50
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ckanext/odsh/collection/helpers.py
+21
-12
21 additions, 12 deletions
ckanext/odsh/collection/helpers.py
ckanext/odsh/tests_tpsh/test_helpers_collection.py
+148
-0
148 additions, 0 deletions
ckanext/odsh/tests_tpsh/test_helpers_collection.py
with
169 additions
and
12 deletions
ckanext/odsh/collection/helpers.py
+
21
−
12
View file @
74cc4f50
...
...
@@ -62,9 +62,6 @@ def get_datasets_from_solr(dataset_names):
def
gather_collection_info
(
collection_dict
,
datasets_in_collection
,
dataset_dict
=
None
):
url_from_id
=
lambda
id
:
helpers
.
url_for
(
controller
=
'
package
'
,
action
=
'
read
'
,
id
=
id
)
name_first_dataset
=
datasets_in_collection
[
0
].
get
(
'
name
'
)
url_first_dataset
=
url_from_id
(
name_first_dataset
)
...
...
@@ -72,25 +69,27 @@ def gather_collection_info(collection_dict, datasets_in_collection, dataset_dict
url_last_dataset
=
url_from_id
(
name_last_dataset
)
name_collection
=
collection_dict
.
get
(
'
name
'
)
persistent_link_last_member
=
helpers
.
url_for
(
controller
=
'
ckanext.odsh.collection.controller:LatestDatasetController
'
,
action
=
'
latest
'
,
id
=
name_collection
)
persistent_link_last_member
=
url_last_member
(
name_collection
)
if
dataset_dict
:
name_current_dataset
=
dataset_dict
.
get
(
'
name
'
)
dataset_names
=
[
d
.
get
(
'
name
'
)
for
d
in
datasets_in_collection
]
def
get_predecessor
():
try
:
id_current
=
dataset_names
.
index
(
name_current_dataset
)
if
id_current
and
id_current
>
0
:
except
ValueError
:
return
None
if
id_current
>
0
:
return
dataset_names
[
id_current
-
1
]
return
None
def
get_successor
():
try
:
id_current
=
dataset_names
.
index
(
name_current_dataset
)
if
id_current
and
id_current
<
len
(
dataset_names
)
-
1
:
except
ValueError
:
return
None
if
id_current
<
len
(
dataset_names
)
-
1
:
return
dataset_names
[
id_current
+
1
]
return
None
...
...
@@ -122,6 +121,16 @@ def gather_collection_info(collection_dict, datasets_in_collection, dataset_dict
'
persistent_link_last_member
'
:
persistent_link_last_member
,
}
def
url_from_id
(
package_id
):
return
helpers
.
url_for
(
controller
=
'
package
'
,
action
=
'
read
'
,
id
=
package_id
)
def
url_last_member
(
name_collection
):
return
helpers
.
url_for
(
controller
=
'
ckanext.odsh.collection.controller:LatestDatasetController
'
,
action
=
'
latest
'
,
id
=
name_collection
)
def
get_latest_dataset
(
collection_name
):
collection_info
=
get_collection_info
(
collection_name
)
...
...
This diff is collapsed.
Click to expand it.
ckanext/odsh/tests_tpsh/test_helpers_collection.py
0 → 100644
+
148
−
0
View file @
74cc4f50
import
nose.tools
as
nt
from
mock
import
patch
import
ckanext.odsh.collection.helpers
as
helpers_collection
class
TestGatherCollectionInfo
(
object
):
def
setUp
(
self
):
# construct datasets that shall be in following order:
# name date
# public2 2014-07-01
# public3 2014-07-01
# public4 2014-07-02
# public1 2014-07-03
self
.
names_collection_members
=
[
u
'
public3
'
,
u
'
public2
'
,
u
'
public1
'
,
u
'
public4
'
,
u
'
private3
'
,
u
'
private2
'
,
u
'
private1
'
]
self
.
dates_collection_members
=
[
u
'
2014-07-01T00:00:00
'
,
# public3
u
'
2014-07-01T00:00:00
'
,
# public2
u
'
2014-07-03T00:00:00
'
,
# public1
u
'
2014-07-02T00:00:00
'
,
# public4
u
'
2014-07-05T00:00:00
'
,
# private3
u
'
2014-07-06T00:00:00
'
,
# private2
u
'
2014-07-07T00:00:00
'
,
# private1
]
self
.
pkg_dicts_collection_members
=
[
{
u
'
name
'
:
name
,
u
'
extras
'
:
{
u
'
issued
'
:
date
}
}
for
(
name
,
date
)
in
zip
(
self
.
names_collection_members
,
self
.
dates_collection_members
)
]
self
.
patch_url_from_id
=
patch
.
object
(
helpers_collection
,
'
url_from_id
'
,
new
=
lambda
id
:
'
http://{}
'
.
format
(
id
)
)
self
.
patch_url_from_id
.
start
()
self
.
patch_url_last_member
=
patch
.
object
(
helpers_collection
,
'
url_last_member
'
,
new
=
lambda
collection_name
:
'
http://{}/last
'
.
format
(
collection_name
)
)
self
.
patch_url_last_member
.
start
()
self
.
collection_dict
=
{
'
name
'
:
'
collection name
'
,
'
title
'
:
'
collection title
'
,
}
self
.
datasets_in_collection
=
[
{
'
name
'
:
'
dataset 1
'
,
},
{
'
name
'
:
'
dataset 2
'
,
},
{
'
name
'
:
'
dataset 3
'
,
},
]
def
tearDown
(
self
):
self
.
patch_url_from_id
.
stop
()
self
.
patch_url_last_member
.
stop
()
def
test_patch_url_from_id
(
self
):
nt
.
assert_equal
(
helpers_collection
.
url_from_id
(
'
some_id
'
),
'
http://some_id
'
)
def
test_patch_url_last_member
(
self
):
nt
.
assert_equal
(
helpers_collection
.
url_last_member
(
'
some_collection
'
),
'
http://some_collection/last
'
)
def
test_gather_collection_info_without_reference_package
(
self
):
collection_info
=
helpers_collection
.
gather_collection_info
(
self
.
collection_dict
,
self
.
datasets_in_collection
,
dataset_dict
=
None
)
collection_info_expected
=
{
'
first_member
'
:
{
'
name
'
:
'
dataset 1
'
,
'
url
'
:
'
http://dataset 1
'
},
'
last_member
'
:
{
'
name
'
:
'
dataset 3
'
,
'
url
'
:
'
http://dataset 3
'
},
'
members
'
:
[
{
'
name
'
:
'
dataset 1
'
},
{
'
name
'
:
'
dataset 2
'
},
{
'
name
'
:
'
dataset 3
'
}],
'
persistent_link_last_member
'
:
'
http://collection name/last
'
,
'
predecessor
'
:
{
'
url
'
:
None
},
'
successor
'
:
{
'
url
'
:
None
},
'
title
'
:
'
collection title
'
}
nt
.
assert_equal
(
collection_info
,
collection_info_expected
)
def
test_gather_collection_info_with_reference_package_1
(
self
):
collection_info
=
helpers_collection
.
gather_collection_info
(
self
.
collection_dict
,
self
.
datasets_in_collection
,
dataset_dict
=
{
'
name
'
:
'
dataset 1
'
})
collection_info_expected
=
{
'
first_member
'
:
{
'
name
'
:
'
dataset 1
'
,
'
url
'
:
'
http://dataset 1
'
},
'
last_member
'
:
{
'
name
'
:
'
dataset 3
'
,
'
url
'
:
'
http://dataset 3
'
},
'
members
'
:
[
{
'
name
'
:
'
dataset 1
'
},
{
'
name
'
:
'
dataset 2
'
},
{
'
name
'
:
'
dataset 3
'
}],
'
persistent_link_last_member
'
:
'
http://collection name/last
'
,
'
predecessor
'
:
{
'
url
'
:
None
},
'
successor
'
:
{
'
url
'
:
'
http://dataset 2
'
},
'
title
'
:
'
collection title
'
}
nt
.
assert_equal
(
collection_info
,
collection_info_expected
)
def
test_gather_collection_info_with_reference_package_2
(
self
):
collection_info
=
helpers_collection
.
gather_collection_info
(
self
.
collection_dict
,
self
.
datasets_in_collection
,
dataset_dict
=
{
'
name
'
:
'
dataset 2
'
})
collection_info_expected
=
{
'
first_member
'
:
{
'
name
'
:
'
dataset 1
'
,
'
url
'
:
'
http://dataset 1
'
},
'
last_member
'
:
{
'
name
'
:
'
dataset 3
'
,
'
url
'
:
'
http://dataset 3
'
},
'
members
'
:
[
{
'
name
'
:
'
dataset 1
'
},
{
'
name
'
:
'
dataset 2
'
},
{
'
name
'
:
'
dataset 3
'
}],
'
persistent_link_last_member
'
:
'
http://collection name/last
'
,
'
predecessor
'
:
{
'
url
'
:
'
http://dataset 1
'
},
'
successor
'
:
{
'
url
'
:
'
http://dataset 3
'
},
'
title
'
:
'
collection title
'
}
nt
.
assert_equal
(
collection_info
,
collection_info_expected
)
def
test_gather_collection_info_with_reference_package_3
(
self
):
collection_info
=
helpers_collection
.
gather_collection_info
(
self
.
collection_dict
,
self
.
datasets_in_collection
,
dataset_dict
=
{
'
name
'
:
'
dataset 3
'
})
collection_info_expected
=
{
'
first_member
'
:
{
'
name
'
:
'
dataset 1
'
,
'
url
'
:
'
http://dataset 1
'
},
'
last_member
'
:
{
'
name
'
:
'
dataset 3
'
,
'
url
'
:
'
http://dataset 3
'
},
'
members
'
:
[
{
'
name
'
:
'
dataset 1
'
},
{
'
name
'
:
'
dataset 2
'
},
{
'
name
'
:
'
dataset 3
'
}],
'
persistent_link_last_member
'
:
'
http://collection name/last
'
,
'
predecessor
'
:
{
'
url
'
:
'
http://dataset 2
'
},
'
successor
'
:
{
'
url
'
:
None
},
'
title
'
:
'
collection title
'
}
nt
.
assert_equal
(
collection_info
,
collection_info_expected
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment