Skip to content

Commit

Permalink
Add DCTLocationVocabularyFactory for DCTLocation items.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmassmann committed Feb 8, 2018
1 parent 01e179f commit dedb6a0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/pkan/dcatapde/vocabularies/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
name="pkan.dcatapde.vocabularies.DCTLicenseDocument"
/>

<utility
component=".content_types.DCTLocationVocabularyFactory"
name="pkan.dcatapde.vocabularies.DCTLocation"
/>

<utility
component=".content_types.DCTMediaTypeOrExtentVocabularyFactory"
name="pkan.dcatapde.vocabularies.DCTMediaTypeOrExtent"
Expand Down
10 changes: 10 additions & 0 deletions src/pkan/dcatapde/vocabularies/content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ class DCTLicenseDocumentVocabulary(BaseContentTypeVocabulary):
DCTLicenseDocumentVocabularyFactory = DCTLicenseDocumentVocabulary()


@implementer(IVocabularyFactory)
class DCTLocationVocabulary(BaseContentTypeVocabulary):
"""A vocabulary returning DCTLocation items."""

portal_type = constants.CT_DCT_LOCATION


DCTLocationVocabularyFactory = DCTLocationVocabulary()


@implementer(IVocabularyFactory)
class DCTMediaTypeOrExtentVocabulary(BaseContentTypeVocabulary):
"""A vocabulary returning DCTMediaTypeOrExtent items."""
Expand Down
50 changes: 50 additions & 0 deletions src/pkan/dcatapde/vocabularies/tests/test_content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,56 @@ def test_vocabulary(self):
)


class TestDCTLocationVocabulary(unittest.TestCase):
"""Validate the `DCTLocationVocabulary` vocabulary."""

layer = testing.INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.item1 = api.content.create(
container=self.portal.get(constants.FOLDER_LOCATIONS),
type=constants.CT_DCT_LOCATION,
id='location-1',
dct_title={u'en': u'Location 1'},
rdfs_isDefinedBy='https://example.com/location-1',
)
self.item2 = api.content.create(
container=self.portal.get(constants.FOLDER_LOCATIONS),
type=constants.CT_DCT_LOCATION,
id='location-2',
dct_title={u'en': u'Location 2'},
rdfs_isDefinedBy='https://example.com/location-2',
)

def test_vocabulary(self):
"""Validate the vocabulary."""
vocab_name = 'pkan.dcatapde.vocabularies.DCTLocation'
factory = getUtility(IVocabularyFactory, vocab_name)
self.assertTrue(IVocabularyFactory.providedBy(factory))

vocabulary = factory(self.portal)
self.assertTrue(IVocabularyTokenized.providedBy(vocabulary))

self.assertEqual(len(vocabulary), 2)
self.assertEqual(
vocabulary.getTerm(self.item1.UID()).title,
'{0} ({1})'.format(
self.item1.Title(),
self.item1.rdfs_isDefinedBy,
),
)
self.assertEqual(
vocabulary.getTerm(self.item2.UID()).title,
'{0} ({1})'.format(
self.item2.Title(),
self.item2.rdfs_isDefinedBy,
),
)


class TestDCTMediaTypeOrExtentVocabulary(unittest.TestCase):
"""Validate the `DCTMediaTypeOrExtentVocabulary` vocabulary."""

Expand Down

0 comments on commit dedb6a0

Please sign in to comment.