From b0252b8a415e256a11ab911e1954042aee3ff72e Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Mon, 25 Sep 2023 14:57:10 -0700 Subject: [PATCH] Fix number_approved_dars test for change in table ordering 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. --- primed/dbgap/tables.py | 4 +-- primed/dbgap/tests/test_tables.py | 56 +++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/primed/dbgap/tables.py b/primed/dbgap/tables.py index 98dd621a..622bbad2 100644 --- a/primed/dbgap/tables.py +++ b/primed/dbgap/tables.py @@ -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 diff --git a/primed/dbgap/tests/test_tables.py b/primed/dbgap/tests/test_tables.py index 4a5981f8..01d8b538 100644 --- a/primed/dbgap/tests/test_tables.py +++ b/primed/dbgap/tests/test_tables.py @@ -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."""