def test_resetting_batch(): request = { 'topic': 'record', 'action': 'read', 'recordName': 'some-record', } client = Client("http://url.com") client.start_batch().add_to_batch(request) assert client.start_batch().add_to_batch(request)._batch == [request] assert client.reset_batch()._batch is None
def test_adding_to_created_batch(): additional_request = { 'topic': 'record', 'action': 'delete', 'recordName': 'some-record', } client = Client("http://url.com") client.start_batch() assert client.is_batched assert client._batch == [] assert client.add_to_batch(request)._batch == [request] assert client.add_to_batch(additional_request)._batch == [ request, additional_request ]
def test_batched(mocker): client = Client(URL) client.auth_data = {"token": "some-token"} mocker.patch.object(client, '_execute') assert isinstance(client.start_batch().get_record(REQUEST['recordName']), Client) assert client._batch == [REQUEST] client._execute.assert_not_called()
def test_batched(): client = Client(URL) client.auth_data = {"token": "some-token"} client.start_batch() client.get_record("recordName") client.make_rpc("rpcName") client.emit_event("eventName") assert client._batch == [{ 'action': 'read', 'recordName': 'recordName', 'topic': 'record' }, { 'action': 'make', 'data': None, 'rpcName': 'rpcName', 'topic': 'rpc' }, { 'action': 'emit', 'data': None, 'eventName': 'eventName', 'topic': 'event' }] with requests_mock.mock() as m: res = { 'result': "SUCCESS", 'body': [{ "success": True, "data": "data" }, { "success": True }, { "success": True }] } m.post(URL, status_code=200, json=res) assert client.execute_batch() == res['body']
def test_batched(mocker): client = Client(URL) client.auth_data = {"token": "some-token"} mocker.patch.object(client, '_execute') # without data assert isinstance( client.start_batch().delete_list(REQUEST['listName']), Client ) assert client._batch == [REQUEST] client._execute.assert_not_called()
def test_batched(mocker): client = Client(URL) client.auth_data = {"token": "some-token"} mocker.patch.object(client, '_execute') # with data assert isinstance( client.start_batch().emit_event( REQUEST['eventName'], REQUEST_WITH_DATA['data'] ), Client ) assert client._batch == [REQUEST_WITH_DATA] client._execute.assert_not_called() # without data assert isinstance( client.start_batch().emit_event(REQUEST['eventName']), Client ) assert client._batch == [REQUEST] client._execute.assert_not_called()
def test_is_batched(): client = Client("http://url.com") assert client.start_batch().is_batched is True
def test_starting_batch(): client = Client("http://url.com") assert client._batch is None assert client.start_batch()._batch == []