Skip to content

Commit

Permalink
cleanup other tests (#1617)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed May 2, 2023
1 parent 681ffad commit ebafbc8
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 67 deletions.
6 changes: 2 additions & 4 deletions irodsadmin/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion irodsinfo/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions irodsinfo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 2 additions & 8 deletions ontologyaccess/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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')

Expand Down
21 changes: 4 additions & 17 deletions ontologyaccess/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fastobo
import os

from urllib.request import urlopen

from test_plus.test import TestCase
Expand Down Expand Up @@ -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',
]


Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ontologyaccess/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class OBOFormatOntologyModelMixin:
"""Helpers for OBOFormatOntology models creation"""

@classmethod
def _make_obo_ontology(
def make_obo_ontology(
cls,
name,
file,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions ontologyaccess/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
23 changes: 2 additions & 21 deletions ontologyaccess/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -212,19 +197,15 @@ 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(
'ontologyaccess:obo_delete',
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)
13 changes: 5 additions & 8 deletions ontologyaccess/tests/test_views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)


# Local constants
OBO_ONTOLOGY_ID_ALT = 'alt.obo'
OBO_ONTOLOGY_NAME_ALT = 'ALT'
OBO_ONTOLOGY_FILE_ALT = 'alt.obo'
Expand All @@ -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 = {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ebafbc8

Please sign in to comment.