Skip to content

Commit

Permalink
Better test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespfennell committed Oct 31, 2019
1 parent c21ca3b commit c312bac
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions tests/unit/services/update/test_sync.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
from ... import testutil
from transiter.services.update import sync
from transiter import models
from unittest import mock

# TODO: test the order of syncing


class TestSync(testutil.TestCase(sync)):
ROUTE_1_ID = "1"
ROUTE_2_ID = "2"
STOP_1_ID = "3"

def setUp(self):

self.feed_update = models.FeedUpdate(models.Feed())

self._sync_routes = self.mockModuleAttribute("_sync_routes")
self._sync_stops = self.mockModuleAttribute("_sync_stops")
self._sync_scheduled_services = self.mockModuleAttribute(
"_sync_scheduled_services"
)
self._sync_trips = self.mockModuleAttribute("_sync_trips")
self._sync_alerts = self.mockModuleAttribute("_sync_alerts")
# Attaching the class methods to a master mock allows us to verify the call
# order: https://stackoverflow.com/questions/22677280/checking-call-order-across-multiple-mocks/22677452#22677452
self._master_mock = mock.Mock()
for method in [
"_sync_routes",
"_sync_stops",
"_sync_scheduled_services",
"_sync_trips",
"_sync_alerts",
]:
self._master_mock.attach_mock(self.mockModuleAttribute(method), method)

def test_invalid_entity(self):
"""
Expand Down Expand Up @@ -59,10 +64,14 @@ def _verify_entities_synced(
expected_trips,
expected_alerts,
):
self._sync_routes.assert_called_once_with(self.feed_update, expected_routes)
self._sync_stops.assert_called_once_with(self.feed_update, expected_stops)
self._sync_scheduled_services.assert_called_once_with(
self.feed_update, expected_scheduled_services
self._master_mock.assert_has_calls(
[
mock.call._sync_routes(self.feed_update, expected_routes),
mock.call._sync_stops(self.feed_update, expected_stops),
mock.call._sync_scheduled_services(
self.feed_update, expected_scheduled_services
),
mock.call._sync_trips(self.feed_update, expected_trips),
mock.call._sync_alerts(self.feed_update, expected_alerts),
]
)
self._sync_trips.assert_called_once_with(self.feed_update, expected_trips)
self._sync_alerts.assert_called_once_with(self.feed_update, expected_alerts)

0 comments on commit c312bac

Please sign in to comment.