From fecded27aaf389cfb342176c284f9f44f5e5108b Mon Sep 17 00:00:00 2001 From: Adrienne Stilp Date: Tue, 18 Jun 2024 11:03:50 -0700 Subject: [PATCH] Add dbGaP application info to user profile --- primed/templates/users/user_detail.html | 25 ++++++++ primed/users/tests/test_views.py | 80 +++++++++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/primed/templates/users/user_detail.html b/primed/templates/users/user_detail.html index c58c5171..2a6cb0db 100644 --- a/primed/templates/users/user_detail.html +++ b/primed/templates/users/user_detail.html @@ -49,6 +49,7 @@
Study Site{% if object.study_sites.all.count > 1
+

{% if object == request.user %}My{% else %}User{% endif %} AnVIL Account

@@ -96,6 +97,30 @@
Verified Date

If this is incorrect, please contact the CC at {{ DCC_CONTACT_EMAIL }}

+ + {% if object == request.user %} + +
+
+

My data access mechanisms

+
+
+

dbGaP

+
    + {% for app in object.pi_dbgap_applications.all %} +
  • Principal Investigator: {{ app }}
  • + {% endfor %} + {% for app in object.collaborator_dbgap_applications.all %} +
  • Collaborator: {{ app }}
  • + {% endfor %} + +

    If this is incorrect, please contact the CC at {{ DCC_CONTACT_EMAIL }}

    +
+
+
+ + {% endif %} +
diff --git a/primed/users/tests/test_views.py b/primed/users/tests/test_views.py index b4785706..cac9aa4c 100644 --- a/primed/users/tests/test_views.py +++ b/primed/users/tests/test_views.py @@ -16,6 +16,7 @@ from django.test import RequestFactory, TestCase from django.urls import reverse +from primed.dbgap.tests.factories import dbGaPApplicationFactory from primed.primed_anvil.tests.factories import StudySiteFactory from primed.users.forms import UserChangeForm from primed.users.models import User @@ -183,6 +184,85 @@ def test_view_links(self, client, user: User, rf: RequestFactory): assert account.get_absolute_url() not in str(response.content) +class UserDetailTest(TestCase): + def setUp(self): + self.factory = RequestFactory() + self.user = UserFactory.create() + + def test_data_access_my_profile(self): + self.client.force_login(self.user) + response = self.client.get(self.user.get_absolute_url()) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "My data access mechanisms") + self.assertContains(response, "dbGaP") + + def test_data_access_other_profile(self): + other_user = UserFactory.create() + self.client.force_login(self.user) + response = self.client.get(other_user.get_absolute_url()) + self.assertEqual(response.status_code, 200) + self.assertNotContains(response, "My data access mechanisms") + + def test_pi_of_one_dbgap_application(self): + dbgap_application = dbGaPApplicationFactory.create(principal_investigator=self.user) + self.client.force_login(self.user) + response = self.client.get(self.user.get_absolute_url()) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Principal Investigator") + self.assertContains(response, dbgap_application.dbgap_project_id) + self.assertContains(response, dbgap_application.get_absolute_url()) + + def test_pi_of_two_dbgap_applications(self): + dbgap_application_1 = dbGaPApplicationFactory.create(principal_investigator=self.user) + dbgap_application_2 = dbGaPApplicationFactory.create(principal_investigator=self.user) + self.client.force_login(self.user) + response = self.client.get(self.user.get_absolute_url()) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Principal Investigator") + self.assertContains(response, dbgap_application_1.dbgap_project_id) + self.assertContains(response, dbgap_application_1.get_absolute_url()) + self.assertContains(response, dbgap_application_2.dbgap_project_id) + self.assertContains(response, dbgap_application_2.get_absolute_url()) + + def test_collaborator_on_one_dbgap_application(self): + dbgap_application = dbGaPApplicationFactory.create() + dbgap_application.collaborators.add(self.user) + self.client.force_login(self.user) + response = self.client.get(self.user.get_absolute_url()) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Collaborator") + self.assertContains(response, dbgap_application.dbgap_project_id) + self.assertContains(response, dbgap_application.get_absolute_url()) + + def test_collaborator_on_two_dbgap_applications(self): + dbgap_application_1 = dbGaPApplicationFactory.create() + dbgap_application_1.collaborators.add(self.user) + dbgap_application_2 = dbGaPApplicationFactory.create() + dbgap_application_2.collaborators.add(self.user) + self.client.force_login(self.user) + response = self.client.get(self.user.get_absolute_url()) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Collaborator") + self.assertContains(response, dbgap_application_1.dbgap_project_id) + self.assertContains(response, dbgap_application_1.get_absolute_url()) + self.assertContains(response, dbgap_application_2.dbgap_project_id) + self.assertContains(response, dbgap_application_2.get_absolute_url()) + + def test_dbgap_pi_and_collaborator(self): + dbgap_application_1 = dbGaPApplicationFactory.create(principal_investigator=self.user) + dbgap_application_2 = dbGaPApplicationFactory.create() + dbgap_application_2.collaborators.add(self.user) + self.client.force_login(self.user) + response = self.client.get(self.user.get_absolute_url()) + self.assertEqual(response.status_code, 200) + self.assertContains(response, "Principal Investigator") + self.assertContains(response, "Collaborator") + self.assertContains(response, dbgap_application_1.dbgap_project_id) + self.assertContains(response, dbgap_application_1.get_absolute_url()) + self.assertContains(response, dbgap_application_2.dbgap_project_id) + self.assertContains(response, dbgap_application_2.get_absolute_url()) + + class UserAutocompleteTest(TestCase): def setUp(self): """Set up test class."""