Skip to content

Commit

Permalink
Clean up test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
amstilp committed Jun 18, 2024
1 parent fecded2 commit 746736a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions primed/dbgap/tests/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,3 +1420,10 @@ def test_queryset(self):
self.assertEqual(record.user, dbgap_application_2.principal_investigator)
self.assertEqual(record.member, None)
self.assertEqual(record.note, collaborator_audit.dbGaPCollaboratorAudit.PI_NO_ACCOUNT)

def test_queryset_wrong_class(self):
"""Raises ValueError if queryset is not a QuerySet."""
with self.assertRaises(ValueError):
collaborator_audit.dbGaPCollaboratorAudit(queryset="foo")
with self.assertRaises(ValueError):
collaborator_audit.dbGaPCollaboratorAudit(queryset=models.dbGaPStudyAccession.objects.all())
4 changes: 3 additions & 1 deletion primed/primed_anvil/tables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import django_tables2 as tables
from anvil_consortium_manager.models import Account, Workspace
from anvil_consortium_manager.models import Account, ManagedGroup, Workspace
from django.contrib.auth import get_user_model
from django.core.exceptions import ImproperlyConfigured
from django.utils.html import format_html
Expand Down Expand Up @@ -174,6 +174,8 @@ class Meta:
def __init__(self, *args, managed_group=None, **kwargs):
if managed_group is None:
raise ValueError("managed_group must be provided.")
if not isinstance(managed_group, ManagedGroup):
raise ValueError("managed_group must be an instance of ManagedGroup.")
self.managed_group = managed_group
super().__init__(*args, **kwargs)

Expand Down
10 changes: 10 additions & 0 deletions primed/primed_anvil/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,13 @@ def test_ordering(self):
table = tables.UserAccountSingleGroupMembershipTable(User.objects.all(), managed_group=self.managed_group)
self.assertEqual(table.data[0], user_bar)
self.assertEqual(table.data[1], user_foo)

def test_managed_group_not_provided(self):
with self.assertRaises(ValueError) as e:
tables.UserAccountSingleGroupMembershipTable(User.objects.all())
self.assertEqual(str(e.exception), "managed_group must be provided.")

def test_managed_group_wrong_class(self):
with self.assertRaises(ValueError) as e:
tables.UserAccountSingleGroupMembershipTable(User.objects.all(), managed_group=AccountFactory.create())
self.assertEqual(str(e.exception), "managed_group must be an instance of ManagedGroup.")

0 comments on commit 746736a

Please sign in to comment.