Exemple #1
0
    def test_google_maps_api_failure(self):
        traffic = Traffic("blah, blah", "ha, ha")
        traffic.gmaps.distance_matrix = MagicMock(
            side_effect=Exception("stuff's broke"))
        traffic.set_dynamo_data = MagicMock()
        traffic.get_dynamo_data = MagicMock(return_value=None)

        traffic.make_google_api_call()

        self.assertEqual(traffic.duration, "unavailable")
Exemple #2
0
    def test_google_maps_api_failure(self):
        traffic = Traffic("blah, blah", "ha, ha")
        traffic.gmaps.distance_matrix = MagicMock(
            side_effect=Exception("stuff's broke"))
        traffic.make_google_api_call()
        self.assertEqual(traffic.duration, "Unavailable")

        actual = traffic.time_in_hours_and_minutes(seconds)
        expected = {"hours": hours, "minutes": minutes}

        self.assertEqual(actual, expected)
Exemple #3
0
    def test_get_traffic_calls_gmaps_if_needed(self):
        traffic = Traffic("foo", "bar")
        traffic.get_dynamo_data = MagicMock(return_value=None)
        traffic.make_google_api_call = MagicMock()

        traffic.get_traffic_data()

        traffic.make_google_api_call.assert_called()
Exemple #4
0
    def test_google_maps_api(self):
        traffic = Traffic("blah, blah", "foo, foo")
        origin = ["foo, foo"]
        destination = ["blah, blah"]
        traffic.gmaps.distance_matrix = MagicMock(return_value={
            "rows": [{
                "elements": [{
                    "duration": {
                        "value": 55555
                    }
                }]
            }]
        })

        traffic.make_google_api_call()
        traffic.gmaps.distance_matrix.assert_called_with(origin, destination)
        self.assertEqual(traffic.duration, {"hours": "15", "minutes": "25"})
Exemple #5
0
    def test_get_traffic_data_skips_gmaps_if_not_needed(self):
        traffic = Traffic("foo", "bar")
        traffic.get_dynamo_data = MagicMock(return_value={
            "time": time.time(),
            "hours": "1",
            "minutes": "75"
        })
        traffic.make_google_api_call = MagicMock()

        traffic.get_traffic_data()

        traffic.make_google_api_call.assert_not_called()
        self.assertEqual(traffic.duration, {"hours": "1", "minutes": "75"})