def test_route(self): api = WebFlyer(origin='san', destination='pdx') self.assertEqual(('SAN', 'PDX'), api.route) self.assertEqual( 'http://www.webflyer.com' \ '/travel/mileage_calculator/getmileage.php' \ '?city=SAN&city=PDX', api.endpoint )
def lambda_handler(event, context): origin = event['pathParameters']['origin'] destination = event['pathParameters']['destination'] try: api = WebFlyer(origin=origin, destination=destination) return {'statusCode': 200, 'body': json.dumps({'miles': api.miles})} except WebFlyerError as e: return {'statusCode': 400, 'body': json.dumps({'error': e.msg})} except ExternalServiceError as e: return {'statusCode': 500, 'body': json.dumps({'error': e.msg})}
def test_server_error(self): httpretty.register_uri( httpretty.GET, 'http://www.webflyer.com/travel/mileage_calculator/getmileage.php', body='Internal Server Error', status=500, ) with self.assertRaises(WebFlyerExternalError) as cm: api = WebFlyer(origin='SAN', destination='PDX') api.miles self.assertEqual(500, cm.exception.response.status_code)
def test_ambiguous_airport(self): with self.assertRaises(AmbiguousAirport) as cm: api = WebFlyer(origin='SAN', destination='L') api.miles self.assertEqual('Ambiguous airport code: L', cm.exception.msg)
def test_invalid_airport(self): with self.assertRaises(InvalidAirport) as cm: api = WebFlyer(origin='SAN', destination='XXX') api.miles self.assertEqual('Invalid airport code: XXX', cm.exception.msg)
def test_sfo_san(self): api = WebFlyer(origin='SAN', destination='NRT') self.assertEqual(5540, api.miles)
def test_sfo_san(self): api = WebFlyer(origin='SFO', destination='SAN') self.assertEqual(447, api.miles)
def test_san_pdx(self): api = WebFlyer(origin='SAN', destination='PDX') self.assertEqual(933, api.miles)