def test_get_appointment_connection_error(): locator = get_random_value_hex(16) # Test that get_appointment handles a connection error appropriately. responses.add(responses.POST, get_appointment_endpoint, body=ConnectionError()) with pytest.raises(ConnectionError): teos_client.get_appointment(locator, dummy_user_sk, dummy_teos_id, teos_url)
def test_get_appointment_tower_error(): # Test that a TowerResponseError is raised if the response is invalid. locator = dummy_appointment_dict.get("locator") responses.add(responses.POST, get_appointment_endpoint, body="{ invalid json response", status=200) with pytest.raises(TowerResponseError): teos_client.get_appointment(locator, dummy_user_sk, dummy_teos_id, teos_url) assert len(responses.calls) == 1
def test_get_appointment(): # Response of get_appointment endpoint is an appointment with status added to it. response = { "locator": dummy_appointment_dict.get("locator"), "status": AppointmentStatus.BEING_WATCHED, "appointment": dummy_appointment_dict, } responses.add(responses.POST, get_appointment_endpoint, json=response, status=200) result = teos_client.get_appointment(dummy_appointment_dict.get("locator"), dummy_user_sk, dummy_teos_id, teos_url) assert len(responses.calls) == 1 assert responses.calls[0].request.url == get_appointment_endpoint assert result.get("locator") == response.get("locator")
def test_get_appointment_invalid_locator(): # Test that an invalid locator fails with InvalidParamater before any network request with pytest.raises(InvalidParameter, match="locator is not valid"): teos_client.get_appointment("deadbeef", dummy_user_sk, dummy_teos_id, teos_url)
def get_appointment_info(teos_id, locator, sk=user_sk): sleep(1) # Let's add a bit of delay so the state can be updated return teos_client.get_appointment(locator, sk, teos_id, teos_base_endpoint)