diff --git a/.gitignore b/.gitignore index 8c09524..9ede137 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc -*.swp \ No newline at end of file +*.swp +.cache/ \ No newline at end of file diff --git a/checkin_test.py b/checkin_test.py new file mode 100644 index 0000000..d53b7ff --- /dev/null +++ b/checkin_test.py @@ -0,0 +1,17 @@ +import pytest +import checkin +import requests_mock +from datetime import datetime +from pytz import timezone + +@requests_mock.Mocker() +def test_checkin(m): + 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()) + 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()) + m.register_uri('POST', '/api/mobile-air-operations/v1/mobile-air-operations/page/check-in', text=open('fixtures/checkin-post.json', 'r').read()) + assert checkin.auto_checkin('XXXX', 'John', 'Smith') == None + +def test_timzone_localization(): + tz = timezone('America/Los_Angeles') + date = tz.localize(datetime.strptime('2018-01-01 13:00', '%Y-%m-%d %H:%M')) + assert date.strftime('%z') == '-0800' diff --git a/fixtures/checkin-get.json b/fixtures/checkin-get.json new file mode 100644 index 0000000..ee7460c --- /dev/null +++ b/fixtures/checkin-get.json @@ -0,0 +1,64 @@ +{ + "checkInSessionToken": "", + "checkInViewReservationPage": { + "_links": { + "checkIn": { + "body": { + "checkInSessionToken": "", + "firstName": "John", + "lastName": "Smith", + "recordLocator": "XXXX" + }, + "href": "/v1/mobile-air-operations/page/check-in", + "method": "POST" + }, + "travelDocuments": null + }, + "_v1_infoNeededToCheckin": { + "body": { + "names": [ + { + "firstName": "JOHN", + "lastName": "SMITH" + } + ] + }, + "href": "/v1/mobile/reservations/record-locator/XXXX/boarding-passes", + "method": "POST" + }, + "cards": [ + { + "arrivalAirport": "LAX", + "arrivalTime": "15:10", + "dates": { + "first": "2018-01-01", + "second": null + }, + "departureAirport": "SFO", + "departureDate": "2018-01-01", + "departureTime": "13:45", + "destinationDescription": "Los Angeles", + "flights": [ + { + "departureDate": "Jan 01", + "destinationAirportCode": "LAX", + "destinationStationName": "Los Angeles", + "flightNumber": "1234", + "hasWifi": true, + "originAirportCode": "SFO" + } + ], + "hazmatCheckInDisclaimer": "By tapping 'Check in' you acknowledge that you understand the hazardous materials restrictions and penalties.", + "travelTime": "1h 25m" + } + ], + "hazmatText": "Federal law forbids the carriage of hazardous materials such as aerosols, fireworks, lithium batteries and flammable liquids aboard the aircraft in your checked or carryon baggage. E-cigarettes are not permitted in checked baggage and must be transported in carryon baggage only.", + "pnr": { + "confirmationNumber": "XXXX", + "passengers": [ + "John Smith" + ] + } + }, + "prefillPassengerAPISDocuments": null +} \ No newline at end of file diff --git a/fixtures/checkin-post.json b/fixtures/checkin-post.json new file mode 100644 index 0000000..e8b0422 --- /dev/null +++ b/fixtures/checkin-post.json @@ -0,0 +1,45 @@ +{ + "checkInConfirmationPage": { + "_links": { + "boardingPasses": { + "body": { + "checkInSessionToken": "XXXX", + "firstName": "JOHN", + "lastName": "SMITH", + "recordLocator": "XXXX" + }, + "href": "/v1/mobile-air-operations/page/check-in/view-boarding-pass", + "method": "POST" + } + }, + "_v1_infoNeededToViewBoardingPasses": { + "href": "/v1/mobile/record-locator/XXXX/mobile-boarding-passes", + "method": "GET", + "query": { + "first-name": "JOHN", + "last-name": "SMITH" + } + }, + "flights": [ + { + "boundIndex": 0, + "flightNumber": "1234", + "gate": null, + "hasWifi": true, + "passengers": [ + { + "boardingGroup": "A", + "boardingPosition": "31", + "checkedIn": true, + "confirmationNumber": "XXXX", + "hasPrecheck": true, + "mobileBoardingPassEligible": true, + "mobileBoardingPassIneligibilityErrorCode": "", + "name": "John Smith" + } + ], + "travelTime": "1h 25m" + } + ] + } +} \ No newline at end of file diff --git a/fixtures/view-reservation.json b/fixtures/view-reservation.json new file mode 100644 index 0000000..666517f --- /dev/null +++ b/fixtures/view-reservation.json @@ -0,0 +1,114 @@ +{ + "viewReservationViewPage": { + "_links": { + "cancel": null, + "change": null, + "checkIn": null, + "checkInSessionToken": null, + "passportEmergencyContacts": null, + "viewBoardingPass": null, + "viewBoardingPositions": null, + "viewStandbyList": null + }, + "_v1_infoNeededToAddCompanion": null, + "_v1_infoNeededToCancel": { + "href": "/v1/mobile/reservations/record-locator/XXXX", + "method": "GET", + "query": { + "action": "CANCEL", + "first-name": "John", + "last-name": "Smith" + } + }, + "_v1_infoNeededToChange": { + "href": "/v1/mobile/reservations/record-locator/XXXX", + "method": "GET", + "query": { + "action": "CHANGE", + "first-name": "John", + "last-name": "Smith" + } + }, + "bounds": [ + { + "arrivalAirport": { + "code": "LAX", + "country": null, + "name": "Los Angeles", + "state": "CA" + }, + "arrivalStatus": null, + "arrivalStatusType": null, + "arrivalTime": "15:10", + "boundType": "DEPARTING", + "departureAirport": { + "code": "SFO", + "country": null, + "name": "San Francisco", + "state": "CA" + }, + "departureDate": "2018-01-01", + "departureStatus": null, + "departureStatusType": null, + "departureTime": "13:45", + "fareType": "Companion", + "flights": [ + { + "number": "1234", + "wifiOnBoard": true + } + ], + "isNextDayArrival": false, + "passengerTypeCounts": { + "adult": 1, + "senior": 0 + }, + "stops": [], + "travelTime": "1h 25m" + } + ], + "checkInIneligibilityReason": null, + "companion": null, + "confirmationNumber": "XXXX", + "dates": { + "first": "2018-01-01", + "second": null + }, + "destinationAirport": { + "code": "LAX", + "country": null, + "name": "Los Angeles", + "state": "CA" + }, + "destinationDescription": "Los Angeles", + "hasAnyCancelledFlights": false, + "hasUnaccompaniedMinor": false, + "isCheckInEligible": false, + "isCheckedIn": false, + "isDynamicWaiver": false, + "isInternational": false, + "isNonRevPnr": false, + "originAirport": { + "code": "SFO", + "country": null, + "name": "San Francisco", + "state": "CA" + }, + "pageHeader": "SFO - LAX", + "passengers": [ + { + "accountNumber": "111111111", + "checkInIneligibilityReason": null, + "hasAnyEarlyBird": false, + "hasCompletePassportInfo": false, + "isCheckInEligible": false, + "isCheckedIn": false, + "isUnaccompaniedMinor": false, + "name": "John Smith", + "passengerReference": "2" + } + ], + "shouldShowAddEarlyBirdButton": false, + "standbyFlight": null + } +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c677cde..3868297 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,9 @@ datetime docopts geopy +pytest python-dateutil pytz requests +requests_mock tzlocal