def test_get_delay_for_trip_live_case3(self): delay_data_for_trip = ProcessBusDelays() mocked_result = [{ "id": "1.1a", "trip_update": { "trip": { "trip_id": "1.1a", "start_time": "09:15:00", "route_id": "11-4e", "schedule_relationship": "SCHEDULED" }, "stop_time_update": [{ "stop_sequence": "1", "arrival": { "delay": "20" }, "stop_id": "24B", "schedule_relationship": "SCHEDULED" }] } }] delay_data_for_trip.get_data_from_bus_api = MagicMock( return_value=mocked_result) response_result = delay_data_for_trip.get_delay_for_trip_live() assert response_result['1.1a']['DELAY'] == '20'
def test_get_data_from_bus_api(self, mock_get): get_bus_trips_data = ProcessBusDelays() bus_trip = get_bus_trips_data.get_data_from_bus_api() headers = { get_bus_trips_data.config_vals["api_key_name"]: get_bus_trips_data.config_vals["api_key_value"] } requests.get.assert_called_once_with( get_bus_trips_data.config_vals['api_url'], headers=headers) assert bus_trip == json.loads(mocked_result)["entity"]
def test_show_live_bus_delays(self): show_bus_delays = BusTripDelays() request = HttpRequest() request.method = 'GET' request.GET['type'] = 'live' request_wrapper = Request(request) fetch_bus_delays = ProcessBusDelays() expected_result = {"test": "test_value"} fetch_bus_delays.get_delay_for_trip_live = MagicMock( return_value=expected_result) response = show_bus_delays.get(request_wrapper, fetch_bus_delays) assert response.status_code == 200 content = json.loads(response.content) assert 'DATA' in content data = content['DATA'] assert 'RESULT' in data assert data['RESULT'] == expected_result