Skip to content

Commit

Permalink
Merge pull request #6 from cioos-atlantic/issue-3
Browse files Browse the repository at this point in the history
Issue 3
  • Loading branch information
aianta authored Jul 7, 2021
2 parents 13e881d + 69a8d14 commit bc1f030
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
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))

0 comments on commit bc1f030

Please sign in to comment.