Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UTC for email sending tasks and fix tests #588

Merged
merged 2 commits into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions modernomad/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from modernomad.log import catch_exceptions
from django.contrib.sites.models import Site
import datetime
from django.utils import timezone
import requests
import json
from django.core import urlresolvers
Expand Down Expand Up @@ -39,7 +38,7 @@ def send_guest_welcome():
did_send_email = False

for location in locations:
soon = datetime.datetime.today() + datetime.timedelta(days=location.welcome_email_days_ahead)
soon = datetime.date.today() + datetime.timedelta(days=location.welcome_email_days_ahead)
upcoming = Use.objects.filter(location=location).filter(arrive=soon).filter(status='confirmed')
for booking in upcoming:
guest_welcome(booking)
Expand All @@ -58,7 +57,7 @@ def send_departure_email():
# get all bookings departing today
locations = Location.objects.all()
for location in locations:
today = timezone.localtime(timezone.now())
today = datetime.date.today()
departing = Use.objects.filter(location=location).filter(depart=today).filter(status='confirmed')
for use in departing:
goodbye_email(use)
Expand All @@ -70,7 +69,7 @@ def send_departure_email():
@catch_exceptions
def generate_subscription_bills():
logger.info("Running task: generate_subscription_bills")
today = timezone.localtime(timezone.now()).date()
today = datetime.date.today()
# using the exclude is an easier way to filter for subscriptions with an
# end date of None *or* in the future.
locations = Location.objects.all()
Expand Down Expand Up @@ -119,7 +118,7 @@ def slack_embassysf_daily():

logger.info("Running task: slack_embassysf_daily")
webhook = "https://hooks.slack.com/services/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"
today = timezone.localtime(timezone.now())
today = datetime.date.today()
location = Location.objects.get(slug="embassysf")
arriving_today = Use.objects.filter(location=location).filter(arrive=today).filter(status='confirmed')
departing_today = Use.objects.filter(location=location).filter(depart=today).filter(status='confirmed')
Expand Down
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