def iot(event, context): try: number_of_departures = 1 service = DarwinService(WSDL, token) from_crs, to_crs = extract_crs(event) departures = TrainApp(service).next_departures(from_crs, to_crs, number_of_departures) if (len(departures) > 0): response = build_response_object( 200, departures[0].estimated_departure_time()) else: response = build_response_object(200, -1) except Exception as e: body = str(e) response = build_response_object(500, body) finally: return response
def next(event, context): try: number_of_departures = 4 service = DarwinService(WSDL, token) from_crs, to_crs = extract_crs(event) departures = TrainApp(service).next_departures(from_crs, to_crs, number_of_departures) data = {"departures": ServiceListEncoder().to_json(departures)} response = build_response_object(200, json.dumps(data)) except Exception as e: body = str(e) response = build_response_object(500, body) finally: return response
def test_extract_crs_should_return_from_and_to_crs_from_event_and_uppercase(self): event = { "pathParameters" : { "from" :"from", "to":"to"}} from_crs, to_crs = extract_crs(event) self.assertEqual(from_crs, "FROM") self.assertEqual(to_crs, "TO")
def test_extract_crs_should_raise_if_event_dictionary_doesnt_contain_station(self): with pytest.raises(Exception) as e_info: event = {} from_crs, to_crs = extract_crs(event)