From c050a98302f07eac99cf2576750878b2417cff15 Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 20 Aug 2015 16:08:53 -0300 Subject: [tests] adapt test for end-of-sync event The soledad sync method was changed to use twisted deferreds, but the test that checks for sync signal was not changed accordingly. This commit fixes that. --- .../src/leap/soledad/common/tests/test_soledad.py | 31 ++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'common/src/leap') diff --git a/common/src/leap/soledad/common/tests/test_soledad.py b/common/src/leap/soledad/common/tests/test_soledad.py index c8bcaba1..bd356858 100644 --- a/common/src/leap/soledad/common/tests/test_soledad.py +++ b/common/src/leap/soledad/common/tests/test_soledad.py @@ -18,8 +18,11 @@ Tests for general Soledad functionality. """ import os + from mock import Mock +from twisted.internet import defer + from leap.common.events import catalog from leap.soledad.common.tests.util import ( BaseSoledadTest, @@ -348,26 +351,26 @@ class SoledadSignalingTestCase(BaseSoledadTest): self.assertEqual([], soledad.client.signal.mock_calls) sol.close() + @defer.inlineCallbacks def test_sync_signals(self): """ Test Soledad emits SOLEDAD_CREATING_KEYS signal. """ - soledad.client.signal.reset_mock() # get a fresh instance so it emits all bootstrap signals sol = self._soledad_instance() + soledad.client.signal.reset_mock() + # mock the actual db sync so soledad does not try to connect to the # server - sol._dbsyncer.sync = Mock() - - def _assert_done_data_sync_signal_emitted(results): - # assert the signal has been emitted - soledad.client.events.emit.assert_called_with( - catalog.SOLEDAD_DONE_DATA_SYNC, - ADDRESS, - ) - sol.close() + d = defer.Deferred() + d.callback(None) + sol._dbsyncer.sync = Mock(return_value=d) - # do the sync and assert signal was emitted - d = sol.sync() - d.addCallback(_assert_done_data_sync_signal_emitted) - return d + yield sol.sync() + + # assert the signal has been emitted + soledad.client.events.emit.assert_called_with( + catalog.SOLEDAD_DONE_DATA_SYNC, + ADDRESS, + ) + sol.close() -- cgit v1.2.3