Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3 #6

Merged
merged 5 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions ckanext/vitality_prototype/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ def generate_whitelist(fields):
return copy.deepcopy(fields)

def default_public_fields(fields):
'''
Returns a dictionary containing only the default public fields.
'''

# default_keys = ['id', 'notes_translated', 'notes', 'resources', 'type', 'name', 'state', 'organization]
# result = {k: v for k, v in result.items() if k.encode('utf-8') not in default_keys}
# fields.clear()
# return result

# Result dict
result = copy.deepcopy(fields)
Expand All @@ -219,9 +227,21 @@ def default_public_fields(fields):


def generate_default_fields():
""" Hard-coded fields for each dataset.
"""
Generates a dictionary containing the default fields and associated uuids.

Parameters
----------
None

Returns
-------
A dictionary containing hard-coded default values as keys and their corresponding uuids as values.
"""

# TODO - Structure these field names for easier readability.
# TODO - Consider benefit of including descriptors in the code.
# TODO - Does this deserve its own class constant?
field_names = [
"notes_translated",
"bbox-east-long",
Expand Down Expand Up @@ -291,7 +311,8 @@ def generate_default_fields():
"temporal-extent"
]

# Result dict
# Generate uuids for result dictionary.
# return {k: str(uuid.uuid4()) for k in field_names}
result = {}

for entry in field_names:
Expand Down
21 changes: 20 additions & 1 deletion ckanext/vitality_prototype/tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
"""Tests for plugin.py."""
from uuid import uuid4
import ckanext.vitality_prototype.plugin as plugin

testClass = plugin.Vitality_PrototypePlugin()

def test_plugin():
pass
pass

def test_compute_tabs():
teststring = plugin.computeTabs(2)
expected = "\t\t"
assert(teststring == expected)

def test_default_keys():
testDict = {'id': "An identifier", 'not_a_default_field': "not_default_value"}
testCase = plugin.default_public_fields(testDict)
assert(testDict.keys == ['id'])

def test_generate_default_fields():
default_fields = plugin.generate_default_fields()
sample_default_keys = ['id', 'state', 'tags', 'unique-resource-identifier-full', 'relationships-as-subject']
assert(sample_default_keys.issubset(default_fields.keys()))
assert(default_fields.all(lambda x : x is uuid4))