From 764d44312f41caf0fe2d8689823dbae360921fc6 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 28 Nov 2017 17:17:57 +0100 Subject: [PATCH] unit test and fix on rendering edit appointment --- smash/web/templates/appointments/edit.html | 31 +++++++++++++++++-- smash/web/tests/api_views/test_worker.py | 2 +- .../tests/forms/test_StudySubjectEditForm.py | 4 +-- smash/web/tests/view/test_appointments.py | 18 +++++++++++ smash/web/tests/view/test_configuration.py | 3 -- smash/web/views/appointment.py | 2 +- 6 files changed, 49 insertions(+), 11 deletions(-) diff --git a/smash/web/templates/appointments/edit.html b/smash/web/templates/appointments/edit.html index d87475c2..1d7cfa2a 100644 --- a/smash/web/templates/appointments/edit.html +++ b/smash/web/templates/appointments/edit.html @@ -42,7 +42,7 @@ <h3 class="box-title">Appointment's details</h3> </div> <div class="box-body"> - {% for field in form %} + {% for field in appointment_form %} <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}"> <label for="{# TODO #}" class="col-sm-4 control-label"> {{ field.label }} @@ -87,6 +87,30 @@ </div><!-- /.box-body --> </fieldset> + <fieldset> + <div class="box-header with-border"> + <h3 class="box-title">Subject's study details</h3> + </div> + + <div class="box-body"> + {% for field in study_subject_form %} + <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> + <label for="{# TODO #}" class="col-sm-4 control-label"> + {{ field.label }} + </label> + + <div class="col-sm-8"> + {{ field|add_class:'form-control' }} + </div> + + {% if field.errors %} + <span class="help-block"> {{ field.errors }} </span> + {% endif %} + </div> + {% endfor %} + </div><!-- /.box-body --> + + </fieldset> {% endif %} <div class="box-footer"> <div class="col-sm-3"> @@ -138,9 +162,10 @@ "autoWidth": false }); }); - appointment_type_behaviour($("input[name='appointment-appointment_types']"), $("input[name='appointment-length']"), "{% url 'web.api.appointment_types' %}"); + var appointmentLengthInput = $("input[name='appointment-length']"); + appointment_type_behaviour($("input[name='appointment-appointment_types']"), appointmentLengthInput, "{% url 'web.api.appointment_types' %}"); appointment_flying_team_place_behaviour($("select[name='appointment-flying_team']"), $("select[name='appointment-location']")); - appointment_date_change_behaviour($("input[name='appointment-datetime_when']"), $("select[name='appointment-worker_assigned']"), $("input[name='appointment-length']"), {{ appointment.id }}); + appointment_date_change_behaviour($("input[name='appointment-datetime_when']"), $("select[name='appointment-worker_assigned']"), appointmentLengthInput, {{ appointment.id }}); </script> diff --git a/smash/web/tests/api_views/test_worker.py b/smash/web/tests/api_views/test_worker.py index 33e4b71d..0b32a0b3 100644 --- a/smash/web/tests/api_views/test_worker.py +++ b/smash/web/tests/api_views/test_worker.py @@ -73,7 +73,7 @@ class TestApi(LoggedInWithWorkerTestCase): result = availabilities(request) entries = json.loads(result.content)['availabilities'] - count = 0; + count = 0 for entry in entries: count += len(entry["workers"]) self.assertTrue(count > 0) diff --git a/smash/web/tests/forms/test_StudySubjectEditForm.py b/smash/web/tests/forms/test_StudySubjectEditForm.py index f8662f91..5f838cff 100644 --- a/smash/web/tests/forms/test_StudySubjectEditForm.py +++ b/smash/web/tests/forms/test_StudySubjectEditForm.py @@ -1,11 +1,9 @@ import logging -from web.forms import StudySubjectAddForm from web.forms import StudySubjectEditForm from web.models import StudySubject -from web.models.constants import SUBJECT_TYPE_CHOICES_CONTROL from web.tests import LoggedInWithWorkerTestCase -from web.tests.functions import create_subject, create_location, create_study_subject +from web.tests.functions import create_study_subject logger = logging.getLogger(__name__) diff --git a/smash/web/tests/view/test_appointments.py b/smash/web/tests/view/test_appointments.py index bad1cfee..97f26eb5 100644 --- a/smash/web/tests/view/test_appointments.py +++ b/smash/web/tests/view/test_appointments.py @@ -52,6 +52,24 @@ class AppointmentsViewTests(LoggedInTestCase): reverse('web.views.appointment_edit', kwargs={'id': appointment.id})) self.assertEqual(response.status_code, 200) + def test_render_appointments_edit(self): + appointment = create_appointment() + appointment.comment = "APPOINTMENT_COMMENT_DATA" + appointment.save() + appointment.visit.subject.comments = "STUDY_SUBJECT_COMMENT_DATA" + appointment.visit.subject.save() + appointment.visit.subject.subject.first_name = "SUBJECT_FIRST_NAME_DATA" + appointment.visit.subject.subject.save() + + response = self.client.get( + reverse('web.views.appointment_edit', kwargs={'id': appointment.id})) + self.assertEqual(response.status_code, 200) + self.assertTrue(appointment.comment in response.content, msg="Appointment data not visible in rendered page") + self.assertTrue(appointment.visit.subject.comments in response.content, + msg="Subject study data not visible in rendered page") + self.assertTrue(appointment.visit.subject.subject.first_name in response.content, + msg="Subject data not visible in rendered page") + def test_save_appointments_edit_without_visit(self): appointment = create_appointment() appointment.visit = None diff --git a/smash/web/tests/view/test_configuration.py b/smash/web/tests/view/test_configuration.py index 23a14779..024f5e24 100644 --- a/smash/web/tests/view/test_configuration.py +++ b/smash/web/tests/view/test_configuration.py @@ -1,5 +1,3 @@ -import datetime - from django.urls import reverse from web.tests import LoggedInTestCase @@ -9,4 +7,3 @@ class ConfigurationViewTests(LoggedInTestCase): def test_visit_details_request(self): response = self.client.get(reverse('web.views.configuration')) self.assertEqual(response.status_code, 200) - diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index b351e86e..e7f08ea3 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -117,7 +117,7 @@ def appointment_edit(request, id): appointment_form = AppointmentEditForm(instance=the_appointment, user=request.user, prefix="appointment") if the_appointment.visit is not None: - study_subject_form = StudySubjectEditForm(instance=the_appointment.visit.subject, prefix="subject") + study_subject_form = StudySubjectEditForm(instance=the_appointment.visit.subject, prefix="study-subject") subject_form = SubjectEditForm(instance=the_appointment.visit.subject.subject, prefix="subject") contact_attempts = the_appointment.visit.subject.contactattempt_set.order_by('-datetime_when').all() -- GitLab