def test_get_flight_departures__with_begin_end_datetime__is_converted_to_int_and_flight_departures_object_is_returned( ): flight_departures_dict_list, expected_flight_departures_list = make_flight_connection_list( ) response = Mock() response.status_code = 200 response.content = flight_departures_dict_list response.json = Mock(return_value=flight_departures_dict_list) request_handler = Mock() request_handler.get = Mock(return_value=response) client = OpenskyNetworkClient(request_handler=request_handler) timestamp = datetime.now() params = {'airport': 'EDDF', 'begin': timestamp, 'end': timestamp} flight_departures = client.get_flight_departures(**params) assert expected_flight_departures_list == flight_departures call_args = request_handler.get.call_args[1] assert call_args['params']['airport'] == params['airport'] assert call_args['params']['begin'] == int(params['begin'].timestamp()) assert call_args['params']['end'] == int(params['end'].timestamp())
def test_get_states__states_object_is_returned(): states_dict, expected_states = make_states() response = Mock() response.status_code = 200 response.content = states_dict response.json = Mock(return_value=states_dict) request_handler = Mock() request_handler.get = Mock(return_value=response) client = OpenskyNetworkClient(request_handler=request_handler) params = { 'timestamp': 1517230800, 'icao24': '3c4ad0', 'bbox': BoundingBox(lamin=85.453421, lamax=80.545676, lomin=50.454257, lomax=45.871253) } states = client.get_states(**params) assert expected_states == states call_args = request_handler.get.call_args[1] assert call_args['params']['time'] == params['timestamp'] assert call_args['params']['icao24'] == params['icao24'] assert call_args['params']['lamin'] == params['bbox'].lamin assert call_args['params']['lamax'] == params['bbox'].lamax assert call_args['params']['lomin'] == params['bbox'].lomin assert call_args['params']['lomax'] == params['bbox'].lomax
def test_get_flight_departures__json_true__flight_departures_dict_is_returned( ): flight_departures_dict_list, _ = make_flight_connection_list() response = Mock() response.status_code = 200 response.content = flight_departures_dict_list response.json = Mock(return_value=flight_departures_dict_list) request_handler = Mock() request_handler.get = Mock(return_value=response) client = OpenskyNetworkClient(request_handler=request_handler) params = { 'airport': 'EDDF', 'begin': 1517227200, 'end': 1517230800, 'json': True } flight_departures = client.get_flight_departures(**params) assert flight_departures_dict_list == flight_departures call_args = request_handler.get.call_args[1] assert call_args['params']['airport'] == params['airport'] assert call_args['params']['begin'] == params['begin'] assert call_args['params']['end'] == params['end']
def test_get_states__http_error_code__raises_api_error(error_code): response = Mock() response.status_code = error_code request_handler = Mock() request_handler.get = Mock(return_value=response) client = OpenskyNetworkClient(request_handler=request_handler) with pytest.raises(APIError): client.get_states()
def test_get_flight_departures__http_error_code__raises_api_error(error_code): response = Mock() response.status_code = error_code request_handler = Mock() request_handler.get = Mock(return_value=response) client = OpenskyNetworkClient(request_handler=request_handler) with pytest.raises(APIError): client.get_flight_departures(airport='EDDF', begin=1517227200, end=1517230800)
def __init__(self, traffic_time_span_in_days): """ Using the OpenSky Network API it tracks the flights from and to specific airports. :param traffic_time_span_in_days: """ self.traffic_time_span_in_days = traffic_time_span_in_days self.client = OpenskyNetworkClient.create('opensky-network.org', timeout=30)
def test_get_airport__json_true__airport_dict_is_returned(): airport_dict, _ = make_airport() response = Mock() response.status_code = 200 response.content = airport_dict response.json = Mock(return_value=airport_dict) request_handler = Mock() request_handler.get = Mock(return_value=response) client = OpenskyNetworkClient(request_handler=request_handler) params = {'icao': 'EDDF', 'json': True} airport = client.get_airport(**params) assert airport_dict == airport call_args = request_handler.get.call_args[1] assert call_args['params']['icao'] == params['icao']
def __init__(self): self.client = OpenskyNetworkClient.create('opensky-network.org')