mirror of
https://github.com/pyro2927/SouthwestCheckin.git
synced 2025-12-06 01:13:19 +00:00
Correcting tests and thread usage
This commit is contained in:
@@ -19,12 +19,13 @@ from datetime import timedelta
|
||||
from dateutil.parser import parse
|
||||
from docopt import docopt
|
||||
from math import trunc
|
||||
from threading import Thread
|
||||
from tzlocal import get_localzone
|
||||
import json
|
||||
import pytz
|
||||
import requests
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
|
||||
API_KEY = 'l7xxb3dcccc4a5674bada48fc6fcf0946bc8'
|
||||
USER_EXPERIENCE_KEY = 'AAAA3198-4545-46F4-9A05-BB3E868BEFF5'
|
||||
@@ -142,7 +143,9 @@ def auto_checkin(reservation_number, first_name, last_name, email=None, mobile=N
|
||||
# found a flight for checkin!
|
||||
print("Flight information found, departing {} at {}".format(airport, date.strftime('%b %d %I:%M%p')))
|
||||
# Checkin with a thread
|
||||
threads.push(threading.Thread(target=schedule_checkin, args=(date, reservation_number, first_name, last_name, email, mobile)))
|
||||
t = Thread(target=schedule_checkin, args=(date, reservation_number, first_name, last_name, email, mobile))
|
||||
t.start()
|
||||
threads.append(t)
|
||||
|
||||
# cleanup threads
|
||||
for t in threads:
|
||||
|
||||
@@ -2,15 +2,26 @@ import checkin
|
||||
import json
|
||||
import pytest
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from pytz import timezone
|
||||
|
||||
def template_time(file_name):
|
||||
in_string = open(file_name, 'r').read()
|
||||
t = datetime.now() + timedelta(seconds=5)
|
||||
in_string = in_string.replace('DATE_HERE', t.strftime('%Y-%m-%d'))
|
||||
in_string = in_string.replace('TIME_HERE', t.strftime('%H:%M'))
|
||||
return in_string
|
||||
|
||||
|
||||
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=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())
|
||||
requests_mock.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
|
||||
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('POST', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in', text=template_time('fixtures/checkin-post.json'))
|
||||
requests_mock.register_uri('POST', '/php/apsearch.php', text=template_time('fixtures/openflights.json'))
|
||||
try:
|
||||
checkin.auto_checkin('XXXX', 'John', 'Smith', None, None)
|
||||
except:
|
||||
pytest.fail("Error checking in")
|
||||
|
||||
def test_timezone_localization():
|
||||
tz = timezone('America/Los_Angeles')
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
"arrivalAirport": "LAX",
|
||||
"arrivalTime": "15:10",
|
||||
"dates": {
|
||||
"first": "2018-01-01",
|
||||
"first": "2218-01-01",
|
||||
"second": null
|
||||
},
|
||||
"departureAirport": "SFO",
|
||||
"departureDate": "2018-01-01",
|
||||
"departureDate": "2218-01-01",
|
||||
"departureTime": "13:45",
|
||||
"destinationDescription": "Los Angeles",
|
||||
"flights": [
|
||||
|
||||
@@ -47,10 +47,10 @@
|
||||
"name": "San Francisco",
|
||||
"state": "CA"
|
||||
},
|
||||
"departureDate": "2018-01-01",
|
||||
"departureDate": "DATE_HERE",
|
||||
"departureStatus": null,
|
||||
"departureStatusType": null,
|
||||
"departureTime": "13:45",
|
||||
"departureTime": "TIME_HERE",
|
||||
"fareType": "Companion",
|
||||
"flights": [
|
||||
{
|
||||
@@ -71,7 +71,7 @@
|
||||
"companion": null,
|
||||
"confirmationNumber": "XXXX",
|
||||
"dates": {
|
||||
"first": "2018-01-01",
|
||||
"first": "2218-01-01",
|
||||
"second": null
|
||||
},
|
||||
"destinationAirport": {
|
||||
|
||||
Reference in New Issue
Block a user