diff --git a/irodsadmin/tests/test_commands.py b/irodsadmin/tests/test_commands.py index a577b58e..c74b0227 100644 --- a/irodsadmin/tests/test_commands.py +++ b/irodsadmin/tests/test_commands.py @@ -48,15 +48,13 @@ class TestIrodsOrphans( """Tests for the irodsorphans management command""" def setUp(self): - super().setUp() + # Init roles + self.init_roles() # Init super user self.user = self.make_user('user') self.user.is_superuser = True self.user.is_staff = True self.user.save() - # Init roles - self.init_roles() - # Init category with owner # Init project with owner self.project = self.make_project( 'TestProject', diff --git a/irodsinfo/tests/test_permissions.py b/irodsinfo/tests/test_permissions.py index 1a0f620d..48a1ea82 100644 --- a/irodsinfo/tests/test_permissions.py +++ b/irodsinfo/tests/test_permissions.py @@ -13,7 +13,6 @@ def setUp(self): # Create users self.superuser = self.make_user('superuser') self.superuser.is_superuser = True - self.superuser.is_staff = True self.superuser.save() self.regular_user = self.make_user('regular_user') # No user diff --git a/irodsinfo/tests/test_views.py b/irodsinfo/tests/test_views.py index 162fd385..327654d8 100644 --- a/irodsinfo/tests/test_views.py +++ b/irodsinfo/tests/test_views.py @@ -27,10 +27,8 @@ def setUp(self): # Create users self.superuser = self.make_user('superuser') self.superuser.is_superuser = True - self.superuser.is_staff = True self.superuser.save() self.regular_user = self.make_user('regular_user') - # No user self.anonymous = None diff --git a/ontologyaccess/tests/test_api.py b/ontologyaccess/tests/test_api.py index df55056e..ddc26510 100644 --- a/ontologyaccess/tests/test_api.py +++ b/ontologyaccess/tests/test_api.py @@ -38,16 +38,11 @@ def setUp(self): # Create users self.superuser = self.make_user('superuser') self.superuser.is_superuser = True - self.superuser.is_staff = True self.superuser.save() - self.regular_user = self.make_user('regular_user') - - # No user self.anonymous = None - # Create Ontology and term - self.ontology = self._make_obo_ontology( + self.ontology = self.make_obo_ontology( name=OBO_NAME, file=OBO_FILE, ontology_id=OBO_ONTOLOGY_ID, @@ -58,7 +53,7 @@ def setUp(self): default_namespace=OBO_DEFAULT_NAMESPACE, term_url=DEFAULT_TERM_URL, ) - self.term = self._make_obo_term( + self.term = self.make_obo_term( ontology=self.ontology, term_id=OBO_TERM_ID, name=OBO_TERM_NAME, @@ -68,7 +63,6 @@ def setUp(self): namespace=OBO_TERM_NAMESPACE, comment=OBO_TERM_COMMENT, ) - # Get API self.ontology_api = get_backend_api('ontologyaccess_backend') diff --git a/ontologyaccess/tests/test_io.py b/ontologyaccess/tests/test_io.py index 48881678..a91c77ca 100644 --- a/ontologyaccess/tests/test_io.py +++ b/ontologyaccess/tests/test_io.py @@ -2,6 +2,7 @@ import fastobo import os + from urllib.request import urlopen from test_plus.test import TestCase @@ -29,10 +30,10 @@ # 'http://purl.obolibrary.org/obo/cl.obo', # TODO: Fix (see #1064) # TODO: Also see issue #944 ] - OWL_BATCH_URLS = [ 'http://purl.obolibrary.org/obo/duo.owl', - 'http://data.bioontology.org/ontologies/ROLEO/submissions/3/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb', + 'http://data.bioontology.org/ontologies/ROLEO/submissions/3/download?' + 'apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb', ] @@ -44,8 +45,6 @@ def setUp(self): def test_import(self): """Test importing an example ontology""" - - # Assert preconditions self.assertEqual(OBOFormatOntology.objects.count(), 0) self.assertEqual(OBOFormatOntologyTerm.objects.count(), 0) @@ -54,7 +53,6 @@ def test_import(self): obo_doc=obo_doc, name=OBO_NAME, file=OBO_PATH ) - # Assert postconditions self.assertEqual(OBOFormatOntology.objects.count(), 1) self.assertEqual(OBOFormatOntologyTerm.objects.count(), 7) @@ -63,29 +61,22 @@ def test_import(self): self.assertEqual( term.synonyms[0], 'First synonym for example term 0000002' ) - term = ontology.get_term_by_id(EX_OBO_TERM_IDS['alt_ids']) self.assertEqual(len(term.alt_ids), 2) self.assertEqual(term.alt_ids[0], 'EX:8888883') - term = ontology.get_term_by_id(EX_OBO_TERM_IDS['comment']) self.assertIsNotNone(term.comment) - term = ontology.get_term_by_id(EX_OBO_TERM_IDS['namespace']) self.assertIsNotNone(term.namespace) - term = ontology.get_term_by_id(EX_OBO_TERM_IDS['is_obsolete']) self.assertTrue(term.is_obsolete) self.assertEqual(term.replaced_by, 'EX:0000005') - term = ontology.get_term_by_id(EX_OBO_TERM_IDS['no_def']) self.assertIsNone(term.definition) def test_import_batch(self): """Test importing ontologies in a batch (this may take a while)""" - for url in OBO_BATCH_URLS: - # Assert preconditions self.assertEqual(OBOFormatOntology.objects.count(), 0) self.assertEqual(OBOFormatOntologyTerm.objects.count(), 0) @@ -95,7 +86,6 @@ def test_import_batch(self): obo_doc=obo_doc, name=file_name.split('.')[0].upper(), file=url ) - # Assert postconditions self.assertIsNotNone(ontology, msg=file_name) self.assertEqual( OBOFormatOntology.objects.count(), 1, msg=file_name @@ -106,10 +96,8 @@ def test_import_batch(self): ontology.delete() def test_import_batch_owl(self): - """Test converting and importing OWL ontologies in a batch (this may take a while)""" - + """Test importing OWL ontologies in batch (this may take a while)""" for url in OWL_BATCH_URLS: - # Assert preconditions self.assertEqual(OBOFormatOntology.objects.count(), 0) self.assertEqual(OBOFormatOntologyTerm.objects.count(), 0) @@ -120,7 +108,6 @@ def test_import_batch_owl(self): obo_doc=obo_doc, name=file_name.split('.')[0].upper(), file=url ) - # Assert postconditions self.assertIsNotNone(ontology, msg=file_name) self.assertEqual( OBOFormatOntology.objects.count(), 1, msg=file_name diff --git a/ontologyaccess/tests/test_models.py b/ontologyaccess/tests/test_models.py index 2abaedab..78e77083 100644 --- a/ontologyaccess/tests/test_models.py +++ b/ontologyaccess/tests/test_models.py @@ -43,7 +43,7 @@ class OBOFormatOntologyModelMixin: """Helpers for OBOFormatOntology models creation""" @classmethod - def _make_obo_ontology( + def make_obo_ontology( cls, name, file, @@ -72,7 +72,7 @@ def _make_obo_ontology( return OBOFormatOntology.objects.create(**values) @classmethod - def _make_obo_term( + def make_obo_term( cls, ontology, term_id, @@ -105,7 +105,7 @@ class TestOBOFormatOntologyBase(OBOFormatOntologyModelMixin, TestCase): """Base class for OBOFormatOntology model tests""" def setUp(self): - self.ontology = self._make_obo_ontology( + self.ontology = self.make_obo_ontology( ontology_id=OBO_ONTOLOGY_ID, name=OBO_NAME, file=OBO_FILE, @@ -116,7 +116,7 @@ def setUp(self): default_namespace=OBO_DEFAULT_NAMESPACE, term_url=DEFAULT_TERM_URL, ) - self.term = self._make_obo_term( + self.term = self.make_obo_term( ontology=self.ontology, term_id=OBO_TERM_ID, name=OBO_TERM_NAME, diff --git a/ontologyaccess/tests/test_permissions.py b/ontologyaccess/tests/test_permissions.py index c751c7a7..8a5eef32 100644 --- a/ontologyaccess/tests/test_permissions.py +++ b/ontologyaccess/tests/test_permissions.py @@ -43,7 +43,7 @@ def setUp(self): # No user self.anonymous = None # Create Ontology and term - self.ontology = self._make_obo_ontology( + self.ontology = self.make_obo_ontology( name=OBO_NAME, file=OBO_FILE, ontology_id=OBO_ONTOLOGY_ID, @@ -54,7 +54,7 @@ def setUp(self): default_namespace=OBO_DEFAULT_NAMESPACE, term_url=DEFAULT_TERM_URL, ) - self.term = self._make_obo_term( + self.term = self.make_obo_term( ontology=self.ontology, term_id=OBO_TERM_ID, name=OBO_TERM_NAME, diff --git a/ontologyaccess/tests/test_views.py b/ontologyaccess/tests/test_views.py index 09381a0e..e4d9859e 100644 --- a/ontologyaccess/tests/test_views.py +++ b/ontologyaccess/tests/test_views.py @@ -44,14 +44,10 @@ def setUp(self): self.superuser.is_superuser = True self.superuser.is_staff = True self.superuser.save() - self.regular_user = self.make_user('regular_user') - - # No user self.anonymous = None - # Create Ontology and term - self.ontology = self._make_obo_ontology( + self.ontology = self.make_obo_ontology( name=OBO_NAME, file=OBO_FILE, ontology_id=OBO_ONTOLOGY_ID, @@ -62,7 +58,7 @@ def setUp(self): default_namespace=OBO_DEFAULT_NAMESPACE, term_url=DEFAULT_TERM_URL, ) - self.term = self._make_obo_term( + self.term = self.make_obo_term( ontology=self.ontology, term_id=OBO_TERM_ID, name=OBO_TERM_NAME, @@ -128,9 +124,7 @@ def test_render(self): def test_import(self): """Test importing an ontology""" - # Assert precondition self.assertEqual(OBOFormatOntology.objects.count(), 1) - with open(OBO_PATH) as file: post_data = { 'file_upload': file, @@ -142,11 +136,8 @@ def test_import(self): response = self.client.post( reverse('ontologyaccess:obo_import'), post_data ) - self.assertEqual(response.status_code, 302) self.assertEqual(response.url, reverse('ontologyaccess:list')) - - # Assert postconditions self.assertEqual(OBOFormatOntology.objects.count(), 2) # TODO: Add test for OWL import @@ -168,15 +159,12 @@ def test_render(self): def test_update(self): """Test updating an ontology""" - # Assert precondition self.assertEqual(OBOFormatOntology.objects.count(), 1) - post_data = { 'name': OBO_NAME, 'title': OBO_TITLE_UPDATED, 'term_url': OBO_TERM_URL_ALT, } - with self.login(self.superuser): response = self.client.post( reverse( @@ -185,11 +173,8 @@ def test_update(self): ), post_data, ) - self.assertEqual(response.status_code, 302) self.assertEqual(response.url, reverse('ontologyaccess:list')) - - # Assert postconditions self.assertEqual(OBOFormatOntology.objects.count(), 1) self.ontology.refresh_from_db() self.assertEqual(self.ontology.title, OBO_TITLE_UPDATED) @@ -212,9 +197,7 @@ def test_render(self): def test_delete(self): """Test deleting an ontology""" - # Assert precondition self.assertEqual(OBOFormatOntology.objects.count(), 1) - with self.login(self.superuser): response = self.client.post( reverse( @@ -222,9 +205,7 @@ def test_delete(self): kwargs={'oboformatontology': self.ontology.sodar_uuid}, ) ) - self.assertEqual(response.status_code, 302) self.assertEqual(response.url, reverse('ontologyaccess:list')) - # Assert postconditions self.assertEqual(OBOFormatOntology.objects.count(), 0) self.assertEqual(OBOFormatOntologyTerm.objects.count(), 0) diff --git a/ontologyaccess/tests/test_views_ajax.py b/ontologyaccess/tests/test_views_ajax.py index 37f827a7..410ac926 100644 --- a/ontologyaccess/tests/test_views_ajax.py +++ b/ontologyaccess/tests/test_views_ajax.py @@ -10,6 +10,7 @@ ) +# Local constants OBO_ONTOLOGY_ID_ALT = 'alt.obo' OBO_ONTOLOGY_NAME_ALT = 'ALT' OBO_ONTOLOGY_FILE_ALT = 'alt.obo' @@ -25,7 +26,6 @@ def test_list(self): """Test listing ontologies""" with self.login(self.superuser): response = self.client.get(reverse('ontologyaccess:ajax_obo_list')) - self.assertEqual(response.status_code, 200) response_data = json.loads(response.content) expected = { @@ -49,15 +49,14 @@ class TestOBOTermQueryAjaxView(TestOntologyAccessViewBase): def setUp(self): super().setUp() - # Create second ontology and term - self.ontology2 = self._make_obo_ontology( + self.ontology2 = self.make_obo_ontology( name=OBO_ONTOLOGY_NAME_ALT, file=OBO_ONTOLOGY_FILE_ALT, ontology_id=OBO_ONTOLOGY_ID_ALT, title=OBO_ONTOLOGY_TITLE_ALT, ) - self.term2 = self._make_obo_term( + self.term2 = self.make_obo_term( ontology=self.ontology2, term_id=OBO_TERM_ID_ALT, name=OBO_TERM_NAME_ALT, @@ -103,7 +102,6 @@ def test_query_limit(self): reverse('ontologyaccess:ajax_obo_term_query'), data=query_data, ) - self.assertEqual(response.status_code, 200) response_data = json.loads(response.content) self.assertEqual(len(response_data['terms']), 1) @@ -196,15 +194,14 @@ class TestOBOTermListAjaxView(TestOntologyAccessViewBase): def setUp(self): super().setUp() - # Create second ontology and term - self.ontology2 = self._make_obo_ontology( + self.ontology2 = self.make_obo_ontology( name=OBO_ONTOLOGY_NAME_ALT, file=OBO_ONTOLOGY_FILE_ALT, ontology_id=OBO_ONTOLOGY_ID_ALT, title=OBO_ONTOLOGY_TITLE_ALT, ) - self.term2 = self._make_obo_term( + self.term2 = self.make_obo_term( ontology=self.ontology2, term_id=OBO_TERM_ID_ALT, name=OBO_TERM_NAME_ALT,