From 21d9fe62cc367bbed492e2e2293e3d0d7f0b7dee Mon Sep 17 00:00:00 2001 From: pyro2927 Date: Mon, 18 Feb 2019 10:29:28 -0800 Subject: [PATCH] Getting tests working on notifications --- southwest/southwest.py | 7 +- tests/checkin_test.py | 3 + tests/fixtures/cassettes/test_checkin.yml | 174 ++++++++++++++++++++++ tests/my_vcr.py | 3 +- 4 files changed, 184 insertions(+), 3 deletions(-) diff --git a/southwest/southwest.py b/southwest/southwest.py index 4fcc319..cd8e9eb 100644 --- a/southwest/southwest.py +++ b/southwest/southwest.py @@ -1,3 +1,4 @@ +from time import sleep import requests import sys @@ -36,7 +37,7 @@ class Reservation(): print(data['message']) if attempts > MAX_ATTEMPTS: sys.exit("Unable to get data, killing self") - time.sleep(CHECKIN_INTERVAL_SECONDS) + sleep(CHECKIN_INTERVAL_SECONDS) continue return data except ValueError: @@ -45,6 +46,8 @@ class Reservation(): def load_json_page(self, url, body=None): data = self.safe_request(url, body) + if not data: + return for k, v in list(data.items()): if k.endswith("Page"): return v @@ -76,7 +79,7 @@ class Reservation(): info_needed = mbpdata['_links'] url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href']) print("Attempting to send boarding pass...") - body = info_needed['body'] for n in self.notifications: + body = info_needed['body'].copy() body.update(n) self.safe_request(url, body) diff --git a/tests/checkin_test.py b/tests/checkin_test.py index 0d6d82d..7f2161c 100644 --- a/tests/checkin_test.py +++ b/tests/checkin_test.py @@ -22,6 +22,9 @@ def test_reservation_lookup(): @my_vcr.use_cassette() def test_checkin(): + phone = southwest.Notifications.Phone('1234567890') + email = southwest.Notifications.Email('test@example.com') + r.notifications = [phone, email] try: r.checkin() except Exception: diff --git a/tests/fixtures/cassettes/test_checkin.yml b/tests/fixtures/cassettes/test_checkin.yml index 6f7ac11..6a1518a 100644 --- a/tests/fixtures/cassettes/test_checkin.yml +++ b/tests/fixtures/cassettes/test_checkin.yml @@ -104,4 +104,178 @@ interactions: X-User-Experience-ID: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] content-length: ['12674'] status: {code: 200, message: OK} +- request: + body: '{}' + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + Content-Length: ['6009'] + Content-Type: [application/json] + Host: [mobile.southwest.com] + User-Agent: [python-requests/2.21.0] + X-API-Key: [l7xxb3dcccc4a5674bada48fc6fcf0946bc8] + X-User-Experience-Id: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + method: POST + uri: https://mobile.southwest.com/api/mobile-air-operations/v1/mobile-air-operations/page/check-in + response: + body: {string: '{"checkInConfirmationPage": {"messages": null, "flights": [{"boundIndex": + 0, "departureTime": "13:45", "gate": "C15", "passengers": "[REDACTED]", "flightNumber": + "1614", "hasWifi": true, "travelTime": "2h 20m"}], "_v1_infoNeededToViewBoardingPasses": + {"href": "/v1/mobile/record-locator/XXXXXX/mobile-boarding-passes", "method": + "GET", "query": {"first-name": "[REDACTED]", "last-name": "[REDACTED]"}}, + "_links": {"boardingPasses": {"href": "/v1/mobile-air-operations/page/check-in/view-boarding-pass", + "method": "POST", "body": {"recordLocator": "[REDACTED]", "firstName": "[REDACTED]", + "lastName": "[REDACTED]", "checkInSessionToken": "[REDACTED]", "travelerID": + "2005DBDA00087702"}}, "viewBoardingPassIssuance": {"href": "/v1/mobile-air-operations/page/check-in/mobile-issuance/XXXXXX", + "method": "POST", "body": {"passengers": "[REDACTED]"}}}}}'} + headers: + Access-Control-Allow-Credentials: ['true'] + Access-Control-Allow-Headers: ['origin, content-type, accept, authorization, + token, User-Agent, X-Forwarded-For, X-User-Experience-ID, X-Request-ID, + X-API-Key, X-Account-Number, X-Swa-Region, X-Channel-Id, X-Api-IDToken, + true-host'] + Access-Control-Allow-Methods: ['GET, POST, PUT, DELETE, OPTIONS, HEAD'] + Access-Control-Allow-Origin: [''] + Access-Control-Expose-Headers: ['X-User-Experience-ID, X-Request-ID'] + Access-Control-Max-Age: ['1'] + Cache-Control: ['max-age=0, no-cache, no-store'] + Connection: [keep-alive] + Content-Type: [application/json] + Date: ['Mon, 18 Feb 2019 18:10:17 GMT'] + Expires: ['Mon, 18 Feb 2019 18:10:17 GMT'] + Pragma: [no-cache] + Server: [Apache-Coyote/1.1] + Strict-Transport-Security: [max-age=60] + Vary: [Accept-Encoding] + X-Request-ID: [nqkkq63YTjK32ta1sWMlCA] + X-User-Experience-ID: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + content-length: ['12851'] + status: {code: 200, message: OK} +- request: + body: '{"travelerID": "2005DBDA00087702"}' + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + Content-Length: ['6043'] + Content-Type: [application/json] + Host: [mobile.southwest.com] + User-Agent: [python-requests/2.21.0] + X-API-Key: [l7xxb3dcccc4a5674bada48fc6fcf0946bc8] + X-User-Experience-Id: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + method: POST + uri: https://mobile.southwest.com/api/mobile-air-operations/v1/mobile-air-operations/page/check-in/view-boarding-pass + response: + body: {string: '{"checkInViewBoardingPassPage": {"messages": null, "mobileBoardingPassURLs": + ["https://mbp.southwest.com/mobiqa/wap/3e422f2/kSqHRGJvSGA/"], "mobileBoardingPassTabs": + [{"title": "PDX - LAX", "departureDate": "Feb 18", "destinationDescription": + "Los Angeles"}], "destinationDescription": "Los Angeles", "originAirportCode": + "PDX", "destinationAirportCode": "LAX", "dates": {"first": "2019-02-18", "second": + null}, "_v1_infoNeededForSharingBoardingPass": {"href": "/v1/mobile/record-locator/XXXXXX/operation-infos/mobile-boarding-pass/notifications", + "method": "POST", "body": {"firstName": "[REDACTED]", "lastName": "[REDACTED]"}}, + "_links": {"href": "/v1/mobile-air-operations/feature/check-in/send-boarding-pass", + "method": "POST", "body": {"recordLocator": "[REDACTED]", "checkInSessionToken": + "[REDACTED]", "travelerID": "2005DBDA00087702"}}}}'} + headers: + Access-Control-Allow-Credentials: ['true'] + Access-Control-Allow-Headers: ['origin, content-type, accept, authorization, + token, User-Agent, X-Forwarded-For, X-User-Experience-ID, X-Request-ID, + X-API-Key, X-Account-Number, X-Swa-Region, X-Channel-Id, X-Api-IDToken, + true-host'] + Access-Control-Allow-Methods: ['GET, POST, PUT, DELETE, OPTIONS, HEAD'] + Access-Control-Allow-Origin: [''] + Access-Control-Expose-Headers: ['X-User-Experience-ID, X-Request-ID'] + Access-Control-Max-Age: ['1'] + Cache-Control: ['max-age=0, no-cache, no-store'] + Connection: [keep-alive] + Content-Type: [application/json] + Date: ['Mon, 18 Feb 2019 18:10:18 GMT'] + Expires: ['Mon, 18 Feb 2019 18:10:18 GMT'] + Pragma: [no-cache] + Server: [Apache-Coyote/1.1] + Strict-Transport-Security: [max-age=60] + Vary: [Accept-Encoding] + X-Request-ID: [BPQyXOwiS2C7PQd72_9rjQ] + X-User-Experience-ID: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + content-length: ['3927'] + status: {code: 200, message: OK} +- request: + body: '{"travelerID": "2005DBDA00087702", "recordLocator": "[REDACTED]", "checkInSessionToken": "[REDACTED]", "mediaType": "SMS", "phoneNumber": "1234567890"}' + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + Content-Length: ['160'] + Content-Type: [application/json] + Host: [mobile.southwest.com] + User-Agent: [python-requests/2.21.0] + X-API-Key: [l7xxb3dcccc4a5674bada48fc6fcf0946bc8] + X-User-Experience-Id: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + method: POST + uri: https://mobile.southwest.com/api/mobile-air-operations/v1/mobile-air-operations/feature/check-in/send-boarding-pass + response: + body: {string: ''} + headers: + Access-Control-Allow-Credentials: ['true'] + Access-Control-Allow-Headers: ['origin, content-type, accept, authorization, + token, User-Agent, X-Forwarded-For, X-User-Experience-ID, X-Request-ID, + X-API-Key, X-Account-Number, X-Swa-Region, X-Channel-Id, X-Api-IDToken, + true-host'] + Access-Control-Allow-Methods: ['GET, POST, PUT, DELETE, OPTIONS, HEAD'] + Access-Control-Allow-Origin: [''] + Access-Control-Expose-Headers: ['X-User-Experience-ID, X-Request-ID'] + Access-Control-Max-Age: ['1'] + Cache-Control: ['max-age=0, no-cache, no-store'] + Connection: [keep-alive] + Content-Type: [application/json] + Date: ['Mon, 18 Feb 2019 18:10:18 GMT'] + Expires: ['Mon, 18 Feb 2019 18:10:18 GMT'] + Pragma: [no-cache] + Server: [Apache-Coyote/1.1] + Strict-Transport-Security: [max-age=60] + Vary: [Accept-Encoding] + X-Request-ID: [BPQyXOwiS2C7PQd72_9rjQ] + X-User-Experience-ID: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + content-length: ['0'] + status: {code: 204, message: OK} +- request: + body: '{"travelerID": "2005DBDA00087702", "recordLocator": "[REDACTED]", "checkInSessionToken": "[REDACTED]", "mediaType": "EMAIL", "phoneNumber": "test@example.com"}' + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + Content-Length: ['160'] + Content-Type: [application/json] + Host: [mobile.southwest.com] + User-Agent: [python-requests/2.21.0] + X-API-Key: [l7xxb3dcccc4a5674bada48fc6fcf0946bc8] + X-User-Experience-Id: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + method: POST + uri: https://mobile.southwest.com/api/mobile-air-operations/v1/mobile-air-operations/feature/check-in/send-boarding-pass + response: + body: {string: ''} + headers: + Access-Control-Allow-Credentials: ['true'] + Access-Control-Allow-Headers: ['origin, content-type, accept, authorization, + token, User-Agent, X-Forwarded-For, X-User-Experience-ID, X-Request-ID, + X-API-Key, X-Account-Number, X-Swa-Region, X-Channel-Id, X-Api-IDToken, + true-host'] + Access-Control-Allow-Methods: ['GET, POST, PUT, DELETE, OPTIONS, HEAD'] + Access-Control-Allow-Origin: [''] + Access-Control-Expose-Headers: ['X-User-Experience-ID, X-Request-ID'] + Access-Control-Max-Age: ['1'] + Cache-Control: ['max-age=0, no-cache, no-store'] + Connection: [keep-alive] + Content-Type: [application/json] + Date: ['Mon, 18 Feb 2019 18:10:18 GMT'] + Expires: ['Mon, 18 Feb 2019 18:10:18 GMT'] + Pragma: [no-cache] + Server: [Apache-Coyote/1.1] + Strict-Transport-Security: [max-age=60] + Vary: [Accept-Encoding] + X-Request-ID: [BPQyXOwiS2C7PQd72_9rjQ] + X-User-Experience-ID: [AAAA3198-4545-46F4-9A05-BB3E868BEFF5] + content-length: ['0'] + status: {code: 204, message: OK} version: 1 diff --git a/tests/my_vcr.py b/tests/my_vcr.py index 3953dc7..792e2b2 100644 --- a/tests/my_vcr.py +++ b/tests/my_vcr.py @@ -48,5 +48,6 @@ def custom_vcr(): path_transformer=VCR.ensure_suffix('.yml'), filter_query_parameters=bad_fields, before_record_response=filter_payload, - filter_post_data_parameters=bad_fields + filter_post_data_parameters=bad_fields, + match_on=['path', 'method'] )