Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check-in changes #282

Merged
merged 12 commits into from
Aug 16, 2024
14 changes: 8 additions & 6 deletions lib/checkin_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,20 @@ def _attempt_check_in(self) -> JSON:

def _check_in_to_flight(self) -> JSON:
"""
First, make a GET request to get the needed check-in information. Then, make
a POST request to submit the check in.
First, initiate a POST request to get the needed check-in information. Subsequently, execute
another POST request to submit the check in.
"""
headers = self.checkin_scheduler.headers
info = {
"first-name": self.first_name,
"last-name": self.last_name,
"firstName": self.first_name,
"lastName": self.last_name,
"passengerSearchToken": "",
"recordLocator": self.flight.confirmation_number,
}
site = CHECKIN_URL + self.flight.confirmation_number

logger.debug("Making GET request to check in")
response = make_request("GET", site, headers, info)
logger.debug("Making POST request to check in")
response = make_request("POST", site, headers, info, random_sleep=False)

info = response["checkInViewReservationPage"]["_links"]["checkIn"]
site = f"mobile-air-operations{info['href']}"
Expand Down
7 changes: 4 additions & 3 deletions lib/checkin_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ def _get_flights(self, confirmation_number: str) -> List[Flight]:

def _get_reservation_info(self, confirmation_number: str) -> Dict[str, Any]:
info = {
"first-name": self.reservation_monitor.first_name,
"last-name": self.reservation_monitor.last_name,
"firstName": self.reservation_monitor.first_name,
"lastName": self.reservation_monitor.last_name,
"recordLocator": confirmation_number,
}
site = VIEW_RESERVATION_URL + confirmation_number

try:
logger.debug("Retrieving reservation information")
response = make_request("GET", site, self.headers, info)
response = make_request("POST", site, self.headers, info)
except RequestError as err:
# Don't send a notification if flights have already been scheduled and all flights
# from this reservation are old. This is how old flights are removed.
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/test_check_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def test_check_in(
handler.first_name = "Garry"
handler.last_name = "Lin"

get_response = {
post_response1 = {
"checkInViewReservationPage": {
"_links": {"checkIn": {"body": {"test": "checkin"}, "href": "/post_check_in"}}
}
}

post_response = {
post_response2 = {
"checkInConfirmationPage": {
"flights": [
{
Expand All @@ -68,25 +68,25 @@ def test_check_in(
}
}

requests_mock.get(
BASE_URL + CHECKIN_URL + "TEST?first-name=Garry&last-name=Lin",
[{"json": get_response, "status_code": 200}],
requests_mock.post(
BASE_URL + CHECKIN_URL + "TEST",
[{"json": post_response1, "status_code": 200}],
)
requests_mock.post(
BASE_URL + "mobile-air-operations/post_check_in",
[{"json": post_response, "status_code": 200}],
[{"json": post_response2, "status_code": 200}],
)

if same_day_flight:
# Add a flight before to make sure a same day flight selects the second flight
second_post_response = copy.deepcopy(post_response)
second_post_response["checkInConfirmationPage"]["flights"].insert(0, {})
same_day_post_response = copy.deepcopy(post_response2)
same_day_post_response["checkInConfirmationPage"]["flights"].insert(0, {})

requests_mock.post(
BASE_URL + "mobile-air-operations/post_check_in",
[
{"json": post_response, "status_code": 200},
{"json": second_post_response, "status_code": 200},
{"json": post_response2, "status_code": 200},
{"json": same_day_post_response, "status_code": 200},
],
)

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_monitoring_and_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def mock_get_driver(self) -> mock.Mock:
side_effect=[datetime(2020, 10, 5, 18, 29), datetime(2020, 10, 14, 18, 29)],
)

requests_mock.get(
requests_mock.post(
TEST_RESERVATION_URL,
[{"json": reservation1, "status_code": 200}, {"json": reservation1, "status_code": 200}],
)
Expand Down Expand Up @@ -212,7 +212,7 @@ def mock_get_driver(self) -> mock.Mock:
}
}

requests_mock.get(TEST_RESERVATION_URL, [{"json": reservation, "status_code": 200}])
requests_mock.post(TEST_RESERVATION_URL, [{"json": reservation, "status_code": 200}])

monitor = AccountMonitor(config.accounts[0], Lock())
with pytest.raises(StopIteration):
Expand Down
Loading