From c2071507a29fbda2330b33f15f593614237f30b3 Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Fri, 5 Apr 2024 16:53:02 -0700 Subject: [PATCH] Improve tests for data summary view Test that dbGaP workspaces and open access workspaces are included in separate tests. Add dbgap to the names of the tests in the helper function tests. --- primed/primed_anvil/tests/test_helpers.py | 14 +++++++------- primed/primed_anvil/tests/test_views.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/primed/primed_anvil/tests/test_helpers.py b/primed/primed_anvil/tests/test_helpers.py index d62b5507..a79aa586 100644 --- a/primed/primed_anvil/tests/test_helpers.py +++ b/primed/primed_anvil/tests/test_helpers.py @@ -59,7 +59,7 @@ def test_one_open_access_workspace_one_study_not_shared_no_available_data(self): self.assertIn("Foo", res[0]) self.assertEqual(res[0]["Foo"], False) - def test_one_workspace_one_study_not_shared_with_one_available_data(self): + def test_one_dbgap_workspace_one_study_not_shared_with_one_available_data(self): available_data = AvailableDataFactory.create(name="Foo") study = StudyFactory.create(short_name="TEST") dbgap_workspace = dbGaPWorkspaceFactory.create( @@ -79,7 +79,7 @@ def test_one_workspace_one_study_not_shared_with_one_available_data(self): self.assertIn("Foo", res[0]) self.assertEqual(res[0]["Foo"], True) - def test_one_workspace_one_study_not_shared_with_two_available_data(self): + def test_one_dbgap_workspace_one_study_not_shared_with_two_available_data(self): available_data_1 = AvailableDataFactory.create(name="Foo") available_data_2 = AvailableDataFactory.create(name="Bar") study = StudyFactory.create(short_name="TEST") @@ -101,7 +101,7 @@ def test_one_workspace_one_study_not_shared_with_two_available_data(self): self.assertIn("Foo", res[0]) self.assertEqual(res[0]["Foo"], True) - def test_one_workspace_two_studies_not_shared_no_available_data(self): + def test_one_dbgap_workspace_two_studies_not_shared_no_available_data(self): AvailableDataFactory.create(name="Foo") study_1 = StudyFactory.create(short_name="TEST") study_2 = StudyFactory.create(short_name="Other") @@ -119,7 +119,7 @@ def test_one_workspace_two_studies_not_shared_no_available_data(self): self.assertIn("Foo", res[0]) self.assertEqual(res[0]["Foo"], False) - def test_one_workspace_one_study_shared_no_available_data(self): + def test_one_dbgap_workspace_one_study_shared_no_available_data(self): AvailableDataFactory.create(name="Foo") study = StudyFactory.create(short_name="TEST") dbgap_workspace = dbGaPWorkspaceFactory.create( @@ -141,7 +141,7 @@ def test_one_workspace_one_study_shared_no_available_data(self): self.assertIn("Foo", res[0]) self.assertEqual(res[0]["Foo"], False) - def test_two_workspaces_one_study(self): + def test_two_dbgap_workspaces_one_study(self): AvailableDataFactory.create(name="Foo") study = StudyFactory.create(short_name="TEST") dbGaPWorkspaceFactory.create(dbgap_study_accession__studies=[study]) @@ -159,7 +159,7 @@ def test_two_workspaces_one_study(self): self.assertIn("Foo", res[0]) self.assertEqual(res[0]["Foo"], False) - def test_two_workspaces_one_study_one_shared(self): + def test_two_dbgap_workspaces_one_study_one_shared(self): available_data_1 = AvailableDataFactory.create(name="Foo") available_data_2 = AvailableDataFactory.create(name="Bar") study = StudyFactory.create(short_name="TEST") @@ -197,7 +197,7 @@ def test_two_workspaces_one_study_one_shared(self): res, ) - def test_two_workspaces_multiple_studies(self): + def test_two_dbgap_workspaces_multiple_studies(self): AvailableDataFactory.create(name="Foo") study_1 = StudyFactory.create(short_name="TEST") study_2 = StudyFactory.create(short_name="Other") diff --git a/primed/primed_anvil/tests/test_views.py b/primed/primed_anvil/tests/test_views.py index 9e1b079f..e2a53555 100644 --- a/primed/primed_anvil/tests/test_views.py +++ b/primed/primed_anvil/tests/test_views.py @@ -1239,3 +1239,25 @@ def test_table_rows(self): response = self.client.get(self.get_url()) self.assertIn("summary_table", response.context_data) self.assertEqual(len(response.context_data["summary_table"].rows), 2) + + def test_includes_open_access_workspaces(self): + """Open access workspaces are included in the table.""" + study = StudyFactory.create() + open_workspace = OpenAccessWorkspaceFactory.create() + open_workspace.studies.add(study) + open_workspace.available_data.add(self.available_data) + self.client.force_login(self.user) + response = self.client.get(self.get_url()) + self.assertIn("summary_table", response.context_data) + self.assertEqual(len(response.context_data["summary_table"].rows), 1) + + def test_includes_dbgap_workspaces(self): + """dbGaP workspaces are included in the table.""" + # One open access workspace with one study, with one available data type. + # One dbGaP workspae with two studies. + study = StudyFactory.create() + dbGaPWorkspaceFactory.create(dbgap_study_accession__studies=[study]) + self.client.force_login(self.user) + response = self.client.get(self.get_url()) + self.assertIn("summary_table", response.context_data) + self.assertEqual(len(response.context_data["summary_table"].rows), 1)