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

subject contains info about default flying team location

parent 6e1bf5d9
No related branches found
No related tags found
1 merge request!62Resolve "subjects with flying team location should have default flying team location defined"
...@@ -52,6 +52,12 @@ class Subject(models.Model): ...@@ -52,6 +52,12 @@ class Subject(models.Model):
default_location = models.ForeignKey(Location, default_location = models.ForeignKey(Location,
verbose_name='Default appointment location', verbose_name='Default appointment location',
) )
flying_team = models.ForeignKey("web.FlyingTeam",
verbose_name='Default flying team location (if applicable)',
null=True, blank=True
)
first_name = models.CharField(max_length=50, first_name = models.CharField(max_length=50,
verbose_name='First name' verbose_name='First name'
) )
......
...@@ -3,7 +3,8 @@ import datetime ...@@ -3,7 +3,8 @@ import datetime
import os import os
from django.contrib.auth.models import User from django.contrib.auth.models import User
from web.models import Location, AppointmentType, Subject, Worker, Visit, Appointment, ConfigurationItem, Language from web.models import Location, AppointmentType, Subject, Worker, Visit, Appointment, ConfigurationItem, Language, \
FlyingTeam
from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL from web.models.constants import SEX_CHOICES_MALE, SUBJECT_TYPE_CHOICES_CONTROL
from web.views.notifications import get_today_midnight_date from web.views.notifications import get_today_midnight_date
...@@ -104,6 +105,11 @@ def create_configuration_item(): ...@@ -104,6 +105,11 @@ def create_configuration_item():
return item return item
def create_flying_team():
result = FlyingTeam.objects.create()
return result
def create_language(name="French", locale="fr_FR"): def create_language(name="French", locale="fr_FR"):
language = Language(name=name, locale=locale) language = Language(name=name, locale=locale)
language.save() language.save()
......
...@@ -2,7 +2,7 @@ import datetime ...@@ -2,7 +2,7 @@ import datetime
from django.urls import reverse from django.urls import reverse
from functions import create_subject, create_visit, create_appointment, create_worker from functions import create_subject, create_visit, create_appointment, create_worker, create_flying_team
from web.forms import AppointmentEditForm, SubjectEditForm from web.forms import AppointmentEditForm, SubjectEditForm
from web.models import Appointment, Subject from web.models import Appointment, Subject
from web.views.notifications import get_today_midnight_date from web.views.notifications import get_today_midnight_date
...@@ -10,6 +10,10 @@ from . import LoggedInTestCase ...@@ -10,6 +10,10 @@ from . import LoggedInTestCase
class AppointmentsViewTests(LoggedInTestCase): class AppointmentsViewTests(LoggedInTestCase):
def setUp(self):
super(AppointmentsViewTests, self).setUp()
create_worker(self.user, True)
def test_appointments_list_request(self): def test_appointments_list_request(self):
response = self.client.get(reverse('web.views.appointments')) response = self.client.get(reverse('web.views.appointments'))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
...@@ -18,7 +22,6 @@ class AppointmentsViewTests(LoggedInTestCase): ...@@ -18,7 +22,6 @@ class AppointmentsViewTests(LoggedInTestCase):
subject = create_subject() subject = create_subject()
visit = create_visit(subject) visit = create_visit(subject)
appointment = create_appointment(visit, when=datetime.datetime.now()) appointment = create_appointment(visit, when=datetime.datetime.now())
create_worker(self.user, True)
new_comment = 'new comment' new_comment = 'new comment'
new_status = appointment.APPOINTMENT_STATUS_NO_SHOW new_status = appointment.APPOINTMENT_STATUS_NO_SHOW
new_last_name = "new last name" new_last_name = "new last name"
...@@ -44,8 +47,6 @@ class AppointmentsViewTests(LoggedInTestCase): ...@@ -44,8 +47,6 @@ class AppointmentsViewTests(LoggedInTestCase):
self.assertEqual(new_last_name, updated_subject.last_name) self.assertEqual(new_last_name, updated_subject.last_name)
def test_appointments_edit_without_visit(self): def test_appointments_edit_without_visit(self):
create_worker(self.user)
appointment = create_appointment() appointment = create_appointment()
appointment.visit = None appointment.visit = None
appointment.save() appointment.save()
...@@ -55,8 +56,6 @@ class AppointmentsViewTests(LoggedInTestCase): ...@@ -55,8 +56,6 @@ class AppointmentsViewTests(LoggedInTestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_save_appointments_edit_without_visit(self): def test_save_appointments_edit_without_visit(self):
create_worker(self.user)
appointment = create_appointment() appointment = create_appointment()
appointment.visit = None appointment.visit = None
appointment.save() appointment.save()
...@@ -73,10 +72,21 @@ class AppointmentsViewTests(LoggedInTestCase): ...@@ -73,10 +72,21 @@ class AppointmentsViewTests(LoggedInTestCase):
def test_save_appointments_edit(self): def test_save_appointments_edit(self):
subject = create_subject() subject = create_subject()
create_worker(self.user, True)
visit = create_visit(subject) visit = create_visit(subject)
appointment = create_appointment(visit, get_today_midnight_date()) appointment = create_appointment(visit, get_today_midnight_date())
form_data = self.prepare_form(appointment, subject)
form_data["appointment-status"] = Appointment.APPOINTMENT_STATUS_FINISHED
response = self.client.post(
reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data)
self.assertEqual(response.status_code, 302)
updated_subject = Subject.objects.get(id=subject.id)
self.assertTrue(updated_subject.information_sent)
def prepare_form(self, appointment, subject):
form_appointment = AppointmentEditForm(user=self.user, instance=appointment, prefix="appointment") form_appointment = AppointmentEditForm(user=self.user, instance=appointment, prefix="appointment")
form_subject = SubjectEditForm(instance=subject, prefix="subject") form_subject = SubjectEditForm(instance=subject, prefix="subject")
form_data = {} form_data = {}
...@@ -90,12 +100,20 @@ class AppointmentsViewTests(LoggedInTestCase): ...@@ -90,12 +100,20 @@ class AppointmentsViewTests(LoggedInTestCase):
form_data['subject-{}'.format(key)] = value.strftime('%Y-%m-%d %H:%M') form_data['subject-{}'.format(key)] = value.strftime('%Y-%m-%d %H:%M')
elif value is not None: elif value is not None:
form_data['subject-{}'.format(key)] = value form_data['subject-{}'.format(key)] = value
return form_data
def test_subject_flying_team_location(self):
subject = create_subject()
visit = create_visit(subject)
appointment = create_appointment(visit, get_today_midnight_date())
form_data = self.prepare_form(appointment, subject)
form_data["appointment-status"] = Appointment.APPOINTMENT_STATUS_FINISHED form_data["appointment-status"] = Appointment.APPOINTMENT_STATUS_FINISHED
form_data["appointment-flying_team"] = create_flying_team().id
form_data['appointment-status'] = Appointment.APPOINTMENT_STATUS_FINISHED
response = self.client.post( response = self.client.post(
reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data) reverse('web.views.appointment_edit', kwargs={'id': appointment.id}), data=form_data)
self.assertEqual(response.status_code, 302)
updated_subject = Subject.objects.get(id=subject.id) updated_subject = Subject.objects.get(id=subject.id)
self.assertTrue(updated_subject.information_sent) self.assertIsNotNone(updated_subject.flying_team)
...@@ -81,6 +81,8 @@ def appointment_edit(request, id): ...@@ -81,6 +81,8 @@ def appointment_edit(request, id):
if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED: if the_appointment.status == Appointment.APPOINTMENT_STATUS_FINISHED:
subject = Subject.objects.get(id=the_appointment.visit.subject.id) subject = Subject.objects.get(id=the_appointment.visit.subject.id)
subject.information_sent = True subject.information_sent = True
if the_appointment.flying_team is not None and subject.flying_team is None:
subject.flying_team = the_appointment.flying_team
subject.save() subject.save()
messages.success(request, "Modifications saved") messages.success(request, "Modifications saved")
......
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