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

test for the bug

parent 5b5e28fe
No related branches found
Tags v4.5.0
1 merge request!333consider the case that an appoinment is not set to a particular visit. the...
Pipeline #45580 passed
......@@ -215,7 +215,7 @@ class MailTemplate(models.Model):
if isinstance(instance, Appointment):
appointment = instance
visit = instance.visit
#general appointment case
# general appointment case
if visit is not None:
study_subject = visit.subject
elif isinstance(instance, Visit):
......
......@@ -4,14 +4,14 @@ import io
from django.test import TestCase
from docx import Document
from web.models import MailTemplate, StudySubject, Language
from web.models import MailTemplate, StudySubject, Language, Appointment
from web.models.constants import MAIL_TEMPLATE_CONTEXT_APPOINTMENT, MAIL_TEMPLATE_CONTEXT_VISIT, \
MAIL_TEMPLATE_CONTEXT_SUBJECT, MAIL_TEMPLATE_CONTEXT_VOUCHER, CUSTOM_FIELD_TYPE_TEXT
from web.models.custom_data import CustomStudySubjectField
from web.models.mail_template import DATE_FORMAT_SHORT
from web.tests.functions import create_language, get_resource_path, create_appointment, create_user, \
create_study_subject, \
create_visit, create_voucher, create_worker, create_flying_team, get_test_study
create_visit, create_voucher, create_worker, create_flying_team, get_test_study, get_test_location
class MailTemplateModelTests(TestCase):
......@@ -270,3 +270,22 @@ class MailTemplateModelTests(TestCase):
worker = create_worker()
result = MailTemplate.get_generic_replacements(worker)
self.assertEqual(result['##WORKER_EMAIL##'], worker.email)
def test_apply_general_appointment(self):
appointment = Appointment.objects.create(
length=30,
location=get_test_location(),
status=Appointment.APPOINTMENT_STATUS_SCHEDULED)
template_name_french = "test_fr"
appointment_template_french = MailTemplate(name=template_name_french,
language=self.french_language,
context=MAIL_TEMPLATE_CONTEXT_APPOINTMENT,
template_file=self.template_file)
stream = io.BytesIO()
appointment_template_french.apply(appointment, self.user, stream)
doc = Document(stream)
worker_name = str(self.user.worker)
location = appointment.location.name
self.check_doc_contains(doc, [worker_name, location])
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