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_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']