Created
June 1, 2015 21:05
-
-
Save iaintshine/23c6e176f3731843b879 to your computer and use it in GitHub Desktop.
python mock consecutive calls example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
try: | |
from unittest import mock | |
except ImportError: | |
import mock | |
class SyncTests(unittest.TestCase): | |
@property | |
def device_uuid(self): | |
return '6dadcec8-6e61-4691-b318-1aab27b8fecf' | |
@property | |
def session_id(self): | |
return '29f2aeeb-8d68-4ea7-95c3-a2c8e151f5a3' | |
def test_synchronization_flow(self): | |
session = { | |
'id': self.session_id | |
} | |
queue_items = [{ | |
'data': { | |
'id': 1, | |
}, | |
'meta': { | |
'type': 'user', | |
'sync': { | |
'event_type': 'created', | |
'ack_key': 'User-1234-1', | |
'revision': 1 | |
} | |
} | |
}] | |
client = mock.create_autospec(basecrm.Client) | |
sync_service = mock.create_autospec(basecrm.SyncService) | |
sync_service.start.return_value = session | |
sync_service.fetch.side_effect = [queue_items, []] | |
sync_service.ack.return_value = True | |
client.sync = sync_service | |
sync = basecrm.Sync(client, self.device_uuid) | |
sync.fetch(lambda meta, data: basecrm.Sync.ACK) | |
sync_service.start.assert_called_once_with(self.device_uuid) | |
sync_service.fetch.assert_has_calls([mock.call(self.device_uuid, self.session_id), | |
mock.call(self.device_uuid, self.session_id)]) | |
sync_service.ack.assert_called_once_with(self.device_uuid, ['User-1234-1']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment