1
0
mirror of https://github.com/pyro2927/SouthwestCheckin.git synced 2025-12-15 15:53:42 +00:00

Adding tests around notifications

This commit is contained in:
Joseph Pintozzi
2019-02-02 20:02:24 -08:00
parent 875ceef805
commit 27122855ee
2 changed files with 23 additions and 2 deletions

View File

@@ -3,7 +3,8 @@ import json
import pytest import pytest
import requests import requests
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pytz import timezone from pytz import timezone, utc
from tzlocal import get_localzone
def template_time(file_name): def template_time(file_name):
in_string = open(file_name, 'r').read() in_string = open(file_name, 'r').read()
@@ -12,7 +13,6 @@ def template_time(file_name):
in_string = in_string.replace('TIME_HERE', t.strftime('%H:%M')) in_string = in_string.replace('TIME_HERE', t.strftime('%H:%M'))
return in_string return in_string
def test_checkin(requests_mock): def test_checkin(requests_mock):
requests_mock.register_uri('GET', '/api/mobile-misc/v1/mobile-misc/page/view-reservation/XXXX?first-name=John&last-name=Smith', text=template_time('fixtures/view-reservation.json')) requests_mock.register_uri('GET', '/api/mobile-misc/v1/mobile-misc/page/view-reservation/XXXX?first-name=John&last-name=Smith', text=template_time('fixtures/view-reservation.json'))
requests_mock.register_uri('GET', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in/XXXX?first-name=John&last-name=Smith', text=template_time('fixtures/checkin-get.json')) requests_mock.register_uri('GET', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in/XXXX?first-name=John&last-name=Smith', text=template_time('fixtures/checkin-get.json'))
@@ -38,3 +38,23 @@ def test_openflights_api():
tzresult = requests.post("https://openflights.org/php/apsearch.php", tzrequest) tzresult = requests.post("https://openflights.org/php/apsearch.php", tzrequest)
airport_tz = timezone(json.loads(tzresult.text)['airports'][0]['tz_id']) airport_tz = timezone(json.loads(tzresult.text)['airports'][0]['tz_id'])
assert airport_tz.zone == "America/Los_Angeles" assert airport_tz.zone == "America/Los_Angeles"
def test_notifications(requests_mock, mocker):
requests_mock.register_uri('GET', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in/XXXX?first-name=John&last-name=Smith', text=template_time('fixtures/checkin-get.json'))
data = template_time('fixtures/checkin-post.json')
requests_mock.register_uri('POST', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in', text=data)
data = json.loads(data)
requests_mock.register_uri('POST', '/php/apsearch.php', text=template_time('fixtures/openflights.json'))
mocked_checkin = mocker.patch('checkin.send_notification')
t = datetime.now(utc).astimezone(get_localzone()) + timedelta(minutes=5)
try:
checkin.schedule_checkin(t, 'XXXX', 'John', 'Smith', None, None)
checkin.send_notification.assert_not_called()
checkin.schedule_checkin(t, 'XXXX', 'John', 'Smith', 'test@example.com', None)
checkin.send_notification.assert_called_once_with(data['checkInConfirmationPage'], emailaddr='test@example.com')
checkin.send_notification.reset_mock()
checkin.schedule_checkin(t, 'XXXX', 'John', 'Smith', None, '1234567890')
checkin.send_notification.assert_called_once_with(data['checkInConfirmationPage'], mobilenum='1234567890')
except:
pytest.fail("Error checking in")

View File

@@ -1,6 +1,7 @@
datetime datetime
docopts docopts
pytest pytest
pytest-mock
python-dateutil python-dateutil
pytz pytz
requests requests