Skip to content

Commit

Permalink
Fix number_approved_dars test for change in table ordering
Browse files Browse the repository at this point in the history
The test for rendering number_approved_dars for the dbGaPDataAccessSnapshot
table started failing when we changed the ordering of the table.
Change the test so is it more robust to that change by testing the
render function directly instead of pulling the value out of the
table rows and assuming an ordering. Also add a test for the number
of requested dars.
  • Loading branch information
amstilp committed Sep 25, 2023
1 parent 8893395 commit b0252b8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
4 changes: 2 additions & 2 deletions primed/dbgap/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ class Meta:
def render_pk(self, record):
return "See details"

def render_number_approved_dars(self, value, record):
def render_number_approved_dars(self, record):
n_dars = record.dbgapdataaccessrequest_set.approved().count()
return n_dars

def render_number_requested_dars(self, value, record):
def render_number_requested_dars(self, record):
n_dars = record.dbgapdataaccessrequest_set.count()
return n_dars

Expand Down
56 changes: 46 additions & 10 deletions primed/dbgap/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,40 +418,76 @@ def test_row_count_with_two_objects(self):
self.assertEqual(len(table.rows), 2)

def test_number_approved_dars(self):
snapshot = self.model_factory.create()
snapshot_1 = self.model_factory.create()
factories.dbGaPDataAccessRequestFactory.create(
dbgap_data_access_snapshot=snapshot,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.CLOSED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.REJECTED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.EXPIRED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.NEW,
)
other_snapshot = self.model_factory.create()
snapshot_2 = self.model_factory.create()
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=other_snapshot,
dbgap_data_access_snapshot=snapshot_2,
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.rows[0].get_cell_value("number_approved_dars"), 1)
self.assertEqual(table.rows[1].get_cell_value("number_approved_dars"), 2)
self.assertEqual(table.render_number_approved_dars(snapshot_1), 1)
self.assertEqual(table.render_number_approved_dars(snapshot_2), 2)

def test_number_requested_dars(self):
snapshot_1 = self.model_factory.create()
factories.dbGaPDataAccessRequestFactory.create(
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.CLOSED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.REJECTED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.EXPIRED,
)
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot_1,
dbgap_current_status=models.dbGaPDataAccessRequest.NEW,
)
snapshot_2 = self.model_factory.create()
factories.dbGaPDataAccessRequestFactory.create_batch(
2,
dbgap_data_access_snapshot=snapshot_2,
dbgap_current_status=models.dbGaPDataAccessRequest.APPROVED,
)
table = self.table_class(self.model.objects.all())
self.assertEqual(table.render_number_requested_dars(snapshot_1), 9)
self.assertEqual(table.render_number_requested_dars(snapshot_2), 2)

def test_ordering(self):
"""Instances are ordered by decreasing snapshot date."""
Expand Down

0 comments on commit b0252b8

Please sign in to comment.