Skip to content

Commit

Permalink
add test for events agreement
Browse files Browse the repository at this point in the history
Added two tests
1. Edits event to switch the event agreement
2. Participant joins an event and sings the agreement
  • Loading branch information
amitupreti committed Mar 15, 2023
1 parent a938be1 commit fc5c9a0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
13 changes: 13 additions & 0 deletions physionet-django/events/fixtures/demo-events.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,18 @@
"access_template": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tincidunt lobortis feugiat vivamus at augue eget.</p>",
"creator": 1
}
},
{
"model": "events.eventagreement",
"pk": 2,
"fields": {
"name": "PhysioNet Restricted Health Data Use Agreement",
"slug": "vafgtyathsgh",
"version": "1.2",
"is_active": true,
"html_content": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tincidunt lobortis feugiat vivamus at augue eget.</p>",
"access_template": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tincidunt lobortis feugiat vivamus at augue eget.</p>",
"creator": 1
}
}
]
52 changes: 51 additions & 1 deletion physionet-django/events/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.urls import reverse

from events.models import Event, EventApplication
from events.models import Event, EventApplication, EventAgreementSignature
from user.test_views import TestMixin


Expand Down Expand Up @@ -264,3 +264,53 @@ def test_event_participation_rejected(self):
# check the status on the event application
event_application.refresh_from_db()
self.assertEqual(event_application.status, EventApplication.EventApplicationStatus.NOT_APPROVED)

def test_event_edit_change_event_agreement(self):
"""tests the view that edits an event and changes the event agreement"""

# create an event
self.test_add_event_valid()

event = Event.objects.get(title=self.new_event_name)
slug = event.slug

# login as the host and edit the event
self.client.login(username='admin', password='Tester11!')

response = self.client.post(
reverse('update_event', kwargs={'event_slug': slug}),
data={
'title': event.title,
'description': event.description,
'start_date': event.start_date,
'end_date': event.end_date,
'category': event.category,
'event_agreement': ['2'],
'allowed_domains': '',
})
self.assertEqual(response.status_code, 302)
event = Event.objects.get(slug=slug)
self.assertEqual(event.event_agreement.pk, 2)

def test_sign_event_agreement(self):
"""tests the view that signs an event agreement"""

# create an event, login as participant, join the event, and login as host and approve the user
self.test_event_participation_approved()

event = Event.objects.get(title=self.new_event_name)

# login as the participant
self.client.login(username='amitupreti', password='Tester11!')

# sign the event agreement
response = self.client.post(
reverse('sign_event_agreement', kwargs={'event_slug': event.slug}),
data={
'agree': ''
})
self.assertEqual(response.status_code, 302)

# check if the user signed the event agreement
EventAgreementSignature.objects.filter(event=event, user__username='amitupreti',
event_agreement=event.event_agreement).exists()

0 comments on commit fc5c9a0

Please sign in to comment.