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

Merge branch '171-workers-are-created-when-sending-emails' into 'master'

mail with kit request doesn't persist new worker

Closes #171

See merge request NCER-PD/scheduling-system!98
parents e698087e 7fe45817
No related branches found
No related tags found
1 merge request!98mail with kit request doesn't persist new worker
Pipeline #
import datetime
from django.core import mail
from django_cron.models import CronJobLog
from mockito import when
from web.models.constants import KIT_EMAIL_HOUR_CONFIGURATION_TYPE
from web.models import Item, AppointmentTypeLink, Worker, ConfigurationItem
from web.tests import LoggedInTestCase
from web.tests.functions import create_appointment_type, create_appointment
from web.views.kit import KitRequestEmailSendJob
from web.views.notifications import get_today_midnight_date
class KitRequestEmailSendJobTests(LoggedInTestCase):
def test_kit_requests_send_email(self):
CronJobLog.objects.all().delete()
configuration = ConfigurationItem.objects.get(type=KIT_EMAIL_HOUR_CONFIGURATION_TYPE)
configuration.value = "00:00"
configuration.save()
job = KitRequestEmailSendJob()
when(job).match_day_of_week().thenReturn(True)
item_name = "Test item to be ordered"
item = Item.objects.create(disposable=True, name=item_name)
appointment_type = create_appointment_type()
appointment_type.required_equipment.add(item)
appointment_type.save()
appointment = create_appointment()
appointment.datetime_when = get_today_midnight_date() + datetime.timedelta(days=2)
appointment.save()
AppointmentTypeLink.objects.create(appointment=appointment, appointment_type=appointment_type)
workers_count = Worker.objects.all().count()
status = job.do()
self.assertEqual("mail sent", status)
self.assertEqual(1, len(mail.outbox))
self.assertEqual(workers_count, Worker.objects.all().count())
......@@ -148,8 +148,10 @@ class KitRequestEmailSendJob(CronJobBase):
if jobs.count() == 0:
if pytz.utc.localize(datetime.datetime.utcnow()) > date:
if self.match_day_of_week():
data = get_kit_requests(Worker.objects.create())
worker = Worker.objects.create()
data = get_kit_requests(worker)
send_mail(data)
worker.delete()
return "mail sent"
else:
return "day of week doesn't match"
......
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