From 6abe30207c99a5e32d68348fedfba6a459a76037 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Thu, 18 Jul 2019 11:20:26 +0100 Subject: [PATCH] Fix time in email sending tests This will stop these tests flaking. --- modernomad/core/tests/test_emails.py | 13 +++++++------ requirements.txt | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modernomad/core/tests/test_emails.py b/modernomad/core/tests/test_emails.py index 9363c2be..3b9745db 100644 --- a/modernomad/core/tests/test_emails.py +++ b/modernomad/core/tests/test_emails.py @@ -5,10 +5,12 @@ from modernomad.core.models import Payment, Use, Booking, UserProfile, LocationEmailTemplate from modernomad.core.emails.messages import new_booking_notify, send_booking_receipt, updated_booking_notify, admin_daily_update from modernomad.core.tasks import send_departure_email, send_guest_welcome, guests_residents_daily_update -from django.utils import timezone from datetime import datetime, timedelta, date +from freezegun import freeze_time +TODAY = date(2019, 3, 14) +@freeze_time(TODAY) class EmailsTestCase(TestCase): def create_booking(self, user, rate=100, status=Use.PENDING, arrive=date(4016, 1, 13), depart=date(4016, 1, 23)): @@ -44,14 +46,13 @@ class MockResponse(): self.admin = self.create_user('admin1', admin=True, email='admin1@bob.com') self.booking = self.create_booking(user=self.guest1) - today = timezone.localtime(timezone.now()) - yesterday = today + timedelta(days=-1) - in_two_days = today + timedelta(days=2) + yesterday = TODAY + timedelta(days=-1) + in_two_days = TODAY + timedelta(days=2) after_that = in_two_days + timedelta(days=1) - self.departing_today = self.create_booking(arrive=yesterday, depart=today, user=self.guest1, status="confirmed") + self.departing_today = self.create_booking(arrive=yesterday, depart=TODAY, user=self.guest1, status="confirmed") self.arriving_in_two_days = self.create_booking(arrive=in_two_days, depart=after_that, user=self.guest2, status="confirmed") - self.arriving_today = self.create_booking(arrive=today, depart=after_that, user=self.guest3, status="confirmed") + self.arriving_today = self.create_booking(arrive=TODAY, depart=after_that, user=self.guest3, status="confirmed") def tearDown(self): self.mock_mailgun_send.stop() diff --git a/requirements.txt b/requirements.txt index 0dd8496c..85d0cf1a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ django-uuidfield==0.5.0 django-webpack-loader==0.6.0 Django==1.11.20 djangorestframework==3.6.4 +freezegun==0.3.12 graphene-django==2.2.0 graphene==2.1.6 graphql-core==2.1.0