mirror of
https://github.com/pyro2927/SouthwestCheckin.git
synced 2025-12-06 01:13:19 +00:00
Fixing tests, adding Mock for openflights
This commit is contained in:
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3.7.1
|
||||||
@@ -115,7 +115,7 @@ def schedule_checkin(flight_time, number, first, last, email, mobile):
|
|||||||
send_notification(data, mobilenum=mobile)
|
send_notification(data, mobilenum=mobile)
|
||||||
|
|
||||||
|
|
||||||
def auto_checkin(reservation_number, first_name, last_name, email, mobile):
|
def auto_checkin(reservation_number, first_name, last_name, email=None, mobile=None):
|
||||||
body = lookup_existing_reservation(reservation_number, first_name, last_name)
|
body = lookup_existing_reservation(reservation_number, first_name, last_name)
|
||||||
|
|
||||||
# Get our local current time
|
# Get our local current time
|
||||||
|
|||||||
@@ -1,17 +1,29 @@
|
|||||||
import pytest
|
|
||||||
import checkin
|
import checkin
|
||||||
import requests_mock
|
import json
|
||||||
|
import pytest
|
||||||
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
def test_checkin(requests_mock):
|
||||||
def test_checkin(m):
|
requests_mock.register_uri('GET', '/api/mobile-misc/v1/mobile-misc/page/view-reservation/XXXX?first-name=John&last-name=Smith', text=open('fixtures/view-reservation.json', 'r').read())
|
||||||
m.register_uri('GET', '/api/mobile-misc/v1/mobile-misc/page/view-reservation/XXXX?first-name=John&last-name=Smith', text=open('fixtures/view-reservation.json', 'r').read())
|
requests_mock.register_uri('GET', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in/XXXX?first-name=John&last-name=Smith', text=open('fixtures/checkin-get.json', 'r').read())
|
||||||
m.register_uri('GET', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in/XXXX?first-name=John&last-name=Smith', text=open('fixtures/checkin-get.json', 'r').read())
|
requests_mock.register_uri('POST', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in', text=open('fixtures/checkin-post.json', 'r').read())
|
||||||
m.register_uri('POST', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in', text=open('fixtures/checkin-post.json', 'r').read())
|
requests_mock.register_uri('POST', '/php/apsearch.php', text=open('fixtures/openflights.json', 'r').read())
|
||||||
assert checkin.auto_checkin('XXXX', 'John', 'Smith') == None
|
assert checkin.auto_checkin('XXXX', 'John', 'Smith') == None
|
||||||
|
|
||||||
def test_timzone_localization():
|
def test_timezone_localization():
|
||||||
tz = timezone('America/Los_Angeles')
|
tz = timezone('America/Los_Angeles')
|
||||||
date = tz.localize(datetime.strptime('2018-01-01 13:00', '%Y-%m-%d %H:%M'))
|
date = tz.localize(datetime.strptime('2018-01-01 13:00', '%Y-%m-%d %H:%M'))
|
||||||
assert date.strftime('%z') == '-0800'
|
assert date.strftime('%z') == '-0800'
|
||||||
|
|
||||||
|
def test_openflights_api():
|
||||||
|
tzrequest = {'iata': 'LAX',
|
||||||
|
'country': 'ALL',
|
||||||
|
'db': 'airports',
|
||||||
|
'iatafilter': 'true',
|
||||||
|
'action': 'SEARCH',
|
||||||
|
'offset': '0'}
|
||||||
|
tzresult = requests.post("https://openflights.org/php/apsearch.php", tzrequest)
|
||||||
|
airport_tz = timezone(json.loads(tzresult.text)['airports'][0]['tz_id'])
|
||||||
|
assert airport_tz.zone == "America/Los_Angeles"
|
||||||
|
|||||||
1
fixtures/openflights.json
Normal file
1
fixtures/openflights.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"status":1,"offset":0,"max":"1","airports":[{"name":"Los Angeles International Airport","city":"Los Angeles","country":"United States","iata":"LAX","icao":"KLAX","x":"-118.4079971","y":"33.94250107","elevation":"125","apid":"3484","timezone":"-8","dst":"A","tz_id":"America\/Los_Angeles","type":"airport","source":"OurAirports","ap_uid":null,"ap_name":"Los Angeles International. (LAX), United States"}]}
|
||||||
Reference in New Issue
Block a user