diff --git a/ckanext/vitality_prototype/plugin.py b/ckanext/vitality_prototype/plugin.py index 70276a4..b06c29d 100644 --- a/ckanext/vitality_prototype/plugin.py +++ b/ckanext/vitality_prototype/plugin.py @@ -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) @@ -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", @@ -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: diff --git a/ckanext/vitality_prototype/tests/test_plugin.py b/ckanext/vitality_prototype/tests/test_plugin.py index 120f9d3..9e9f880 100644 --- a/ckanext/vitality_prototype/tests/test_plugin.py +++ b/ckanext/vitality_prototype/tests/test_plugin.py @@ -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 \ No newline at end of file + 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)) \ No newline at end of file