Skip to content

Commit

Permalink
Freeze time in email sending tests
Browse files Browse the repository at this point in the history
This will stop these tests flaking.
  • Loading branch information
bfirsh committed Jul 20, 2019
1 parent d4fc65a commit b79e324
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions modernomad/core/tests/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -44,14 +46,13 @@ class MockResponse():
self.admin = self.create_user('admin1', admin=True, email='[email protected]')
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()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b79e324

Please sign in to comment.