diff --git a/smash/web/tests/test_view_appointments.py b/smash/web/tests/test_view_appointments.py index bf721ebe836316136b26bb85ed47ae8f030c091f..7bb1f5118ed39775fc3ba461600f3b51ab9533d3 100644 --- a/smash/web/tests/test_view_appointments.py +++ b/smash/web/tests/test_view_appointments.py @@ -1,4 +1,5 @@ import datetime +import logging from django.urls import reverse @@ -9,6 +10,8 @@ from web.models import Appointment, Subject from web.views.notifications import get_today_midnight_date from . import LoggedInTestCase +logger = logging.getLogger(__name__) + class AppointmentsViewTests(LoggedInTestCase): def setUp(self): @@ -71,6 +74,22 @@ class AppointmentsViewTests(LoggedInTestCase): self.assertEqual(response.status_code, 200) + def test_save_as_finished_appointments_edit_without_visit(self): + appointment = create_appointment(None, get_today_midnight_date()) + appointment.visit = None + appointment.save() + + form_appointment = AppointmentEditForm(user=self.user, instance=appointment, prefix="appointment") + form_data = {} + for key, value in form_appointment.initial.items(): + if value is not None: + form_data['appointment-{}'.format(key)] = format_form_field(value) + form_data['appointment-status'.format(key)] = Appointment.APPOINTMENT_STATUS_FINISHED + self.client.post(reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) + + appointment_result = Appointment.objects.filter(id=appointment.id)[0] + self.assertEqual(Appointment.APPOINTMENT_STATUS_FINISHED, appointment_result.status) + def test_save_appointments_edit(self): subject = create_subject() visit = create_visit(subject) diff --git a/smash/web/views/appointment.py b/smash/web/views/appointment.py index 5f0e6d7d5265997afa2be09493ed84d3fc88a5ee..c0462a996675c62a820e99de9db2e80e5c57e303 100644 --- a/smash/web/views/appointment.py +++ b/smash/web/views/appointment.py @@ -80,7 +80,7 @@ def appointment_edit(request, id): subject_form.save() the_appointment = get_object_or_404(Appointment, id=id) - if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED: + if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED and the_appointment.visit is not None: subject = Subject.objects.get(id=the_appointment.visit.subject.id) subject.information_sent = True if the_appointment.flying_team is not None and subject.flying_team is None: