Skip to content

Commit

Permalink
Add dbGaP application info to user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
amstilp committed Jun 18, 2024
1 parent 216c78f commit fecded2
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
25 changes: 25 additions & 0 deletions primed/templates/users/user_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h5><i class="bi bi-globe"></i> Study Site{% if object.study_sites.all.count > 1
</div>
</div>
<div class='col'>

<div class='card card-shadow-sm'>
<div class='card-header'>
<h3><i class="bi bi-link-45deg"></i> {% if object == request.user %}My{% else %}User{% endif %} AnVIL Account</h3>
Expand Down Expand Up @@ -96,6 +97,30 @@ <h5>Verified Date</h5>
<p class='alert alert-secondary mt-3'><i class="bi bi-question-circle-fill"></i> If this is incorrect, please contact the CC at <a href="mailto:{{ DCC_CONTACT_EMAIL }}">{{ DCC_CONTACT_EMAIL }}</a></p>
</div><i class="bi bi-c-square"></i>
</div>

{% if object == request.user %}

<div class='card card-shadow-sm mt-3'>
<div class='card-header'>
<h3><i class="bi bi-clipboard-check"></i> My data access mechanisms </h3>
</div>
<div class='card-body'>
<h4>dbGaP</h4>
<ul class="list-group">
{% for app in object.pi_dbgap_applications.all %}
<li class="list-group-item"><strong>Principal Investigator: </strong><a href="{{ app.get_absolute_url }}">{{ app }}</a></li>
{% endfor %}
{% for app in object.collaborator_dbgap_applications.all %}
<li class="list-group-item"><strong>Collaborator: </strong><a href="{{ app.get_absolute_url }}">{{ app }}</a></li>
{% endfor %}

<p class='alert alert-secondary mt-3'><i class="bi bi-question-circle-fill"></i> If this is incorrect, please contact the CC at <a href="mailto:{{ DCC_CONTACT_EMAIL }}">{{ DCC_CONTACT_EMAIL }}</a></p>
</ul>
</div>
</div>

{% endif %}

</div>
</div>

Expand Down
80 changes: 80 additions & 0 deletions primed/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit fecded2

Please sign in to comment.