diff --git a/opengever/api/tests/test_vocabularies.py b/opengever/api/tests/test_vocabularies.py index 705ebf57dbc..80ba69069e5 100644 --- a/opengever/api/tests/test_vocabularies.py +++ b/opengever/api/tests/test_vocabularies.py @@ -1,4 +1,5 @@ from ftw.testbrowser import browsing +from opengever.base.behaviors.classification import IClassification from opengever.testing import IntegrationTestCase from plone import api @@ -158,3 +159,70 @@ def test_all_non_sensitive_vocabularies_are_accessable_by_a_member(self, browser @browsing def test_all_non_sensitive_vocabularies_are_accessable_by_a_contributor(self, browser): self.assert_permission_for_non_sensitive_vocabulaires(browser, 'Contributor') + + +class TestGetVocabularies(IntegrationTestCase): + + @browsing + def test_get_vocabulary_for_edit(self, browser): + self.login(self.regular_user, browser) + url = self.empty_dossier.absolute_url() + '/@vocabularies/opengever.document.document_types' + response = browser.open( + url, + method='GET', + headers=http_headers(), + ).json + self.assertEqual(url, response.get('@id')) + self.assertEqual(8, response.get('items_total')) + expected_tokens = [u'contract', u'directive', u'offer', u'protocol', + u'question', u'regulations', u'report', u'request'] + self.assertItemsEqual(expected_tokens, + [item['token'] for item in response.get('items')]) + + @browsing + def test_get_vocabulary_for_add(self, browser): + self.login(self.regular_user, browser) + url = self.empty_dossier.absolute_url() + '/@vocabularies/opengever.document.document/opengever.document.document_types' + response = browser.open( + url, + method='GET', + headers=http_headers(), + ).json + self.assertEqual(url, response.get('@id')) + self.assertEqual(8, response.get('items_total')) + expected_tokens = [u'contract', u'directive', u'offer', u'protocol', + u'question', u'regulations', u'report', u'request'] + self.assertItemsEqual(expected_tokens, + [item['token'] for item in response.get('items')]) + + @browsing + def test_get_restricted_vocabulary_for_add(self, browser): + self.login(self.regular_user, browser) + + url = self.leaf_repofolder.absolute_url() + '/@vocabularies/opengever.dossier.businesscasedossier/classification_classification_vocabulary' + response = browser.open( + url, + method='GET', + headers=http_headers(), + ).json + + field = IClassification['classification'] + field.set(field.interface(self.leaf_repofolder), u'confidential') + restricted_response = browser.open( + url, + method='GET', + headers=http_headers(), + ).json + + self.assertEqual(url, response.get('@id')) + self.assertEqual(url, restricted_response.get('@id')) + self.assertTrue( + response.get('items_total') > restricted_response.get('items_total')) + self.assertIn( + u'unprotected', + [item.get('token') for item in response.get('items')] + ) + self.assertNotIn( + u'unprotected', + [item.get('token') for item in restricted_response.get('items')] + )