Skip to content
Snippets Groups Projects
Commit 5887818c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unit tests for study edit page

parent daa8f423
No related branches found
No related tags found
1 merge request!139Configuration page for a study
Pipeline #
import logging
from django.urls import reverse
from web.forms import StudyEditForm, StudyNotificationParametersEditForm, StudyColumnsEditForm
from web.models.constants import GLOBAL_STUDY_ID
from web.tests import LoggedInWithWorkerTestCase
from web.tests.functions import get_test_study, format_form_field
logger = logging.getLogger(__name__)
class SubjectsViewTests(LoggedInWithWorkerTestCase):
def setUp(self):
super(SubjectsViewTests, self).setUp()
self.study = get_test_study()
def test_render_study_edit(self):
response = self.client.get(reverse('web.views.edit_study', kwargs={'study_id': GLOBAL_STUDY_ID}))
self.assertEqual(response.status_code, 200)
def test_save_study(self):
form_data = self.create_edit_form_data_for_study()
response = self.client.post(
reverse('web.views.edit_study', kwargs={'study_id': GLOBAL_STUDY_ID}), data=form_data)
self.assertEqual(response.status_code, 302)
self.assertFalse("edit" in response['Location'])
def test_save_invalid_data(self):
form_data = {}
response = self.client.post(
reverse('web.views.edit_study', kwargs={'study_id': GLOBAL_STUDY_ID}), data=form_data)
self.assertEqual(response.status_code, 200)
def test_save_study_without_changing_page(self):
form_data = self.create_edit_form_data_for_study()
form_data['_continue'] = True
response = self.client.post(
reverse('web.views.edit_study', kwargs={'study_id': GLOBAL_STUDY_ID}), data=form_data)
self.assertEqual(response.status_code, 302)
self.assertTrue("edit" in response['Location'])
def create_edit_form_data_for_study(self):
study_form = StudyEditForm(instance=self.study, prefix="study")
notifications_form = StudyNotificationParametersEditForm(instance=self.study.notification_parameters,
prefix="notifications")
study_columns_form = StudyColumnsEditForm(instance=self.study.columns,
prefix="columns")
form_data = {}
for key, value in study_form.initial.items():
form_data['study-{}'.format(key)] = format_form_field(value)
for key, value in notifications_form.initial.items():
form_data['notifications-{}'.format(key)] = format_form_field(value)
for key, value in study_columns_form.initial.items():
form_data['columns-{}'.format(key)] = format_form_field(value)
return form_data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment