From f6b5d1102dd58edf6a2ab058a67b5a741408a4b0 Mon Sep 17 00:00:00 2001 From: FelixFrizzy <39409092+FelixFrizzy@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:40:28 +0100 Subject: [PATCH] Add tests for term-id - Tests reflect the allowed characters of term subjects (term ids) --- evoks/tests/views/test_vocabulary_views.py | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/evoks/tests/views/test_vocabulary_views.py b/evoks/tests/views/test_vocabulary_views.py index 3fc06c7..fdb84b1 100755 --- a/evoks/tests/views/test_vocabulary_views.py +++ b/evoks/tests/views/test_vocabulary_views.py @@ -468,7 +468,7 @@ def test_overview_search(self): # create term so that search finds something self.c.post( '/vocabularies/{0}/terms'.format(self.vocabulary.name), - {'create-term': '', 'term-subject': 'testterm', 'term-label': 'testlabel'} + {'create-term': '', 'term-subject': 'testterm_43-2_23', 'term-label': 'testlabel'} ) response = self.c.get( @@ -502,20 +502,41 @@ def test_terms_view_add_term(self): def test_create_term(self): response = self.c.post( '/vocabularies/{0}/terms'.format(self.vocabulary.name), - {'create-term': '', 'term-subject': 'testterm', 'term-label': 'testlabel'}, + {'create-term': '', 'term-subject': 'testterm_43-2_23', 'term-label': 'testlabel'}, follow=True ) self.assertEqual(response.status_code, 200) voc = Vocabulary.objects.get(name=self.vocabulary.name) - self.assertTrue(voc.term_set.filter(name='testterm').exists()) + self.assertTrue(voc.term_set.filter(name='testterm_43-2_23').exists()) # create same term again error_response = self.c.post( '/vocabularies/{0}/terms'.format(self.vocabulary.name), - {'create-term': '', 'term-subject': 'testterm', 'term-label': 'testlabel'} + {'create-term': '', 'term-subject': 'testterm_43-2_23', 'term-label': 'testlabel'} ) self.assertEqual(error_response.status_code, 409) + # create term with empty subject + error_response = self.c.post( + '/vocabularies/{0}/terms'.format(self.vocabulary.name), + {'create-term': '', 'term-subject': '', 'term-label': 'testlabelempty'} + ) + self.assertEqual(error_response.status_code, 400) + + # create term with space in subject + error_response = self.c.post( + '/vocabularies/{0}/terms'.format(self.vocabulary.name), + {'create-term': '', 'term-subject': 'test term', 'term-label': 'testlabelspace'} + ) + self.assertEqual(error_response.status_code, 400) + + # create term with disallowed character in subject + error_response = self.c.post( + '/vocabularies/{0}/terms'.format(self.vocabulary.name), + {'create-term': '', 'term-subject': 'testterm!', 'term-label': 'testlabelquestionmark'} + ) + self.assertEqual(error_response.status_code, 400) + # base view tests def test_base_view(self): @@ -571,7 +592,7 @@ def test_base_search(self): # create term so that search finds something self.c.post( '/vocabularies/{0}/terms'.format(self.vocabulary.name), - {'create-term': '', 'term-subject': 'testterm', 'term-label': 'testlabel'} + {'create-term': '', 'term-subject': 'testterm_43-2_23', 'term-label': 'testlabel'} ) response = self.c.get(