def test_non_deserializable_body(): f = StringIO.StringIO(IN_SCROLL) t = ReplayTransport([{}], recfile=f, connection_class=DummyConnection) status, data = t.perform_request( 'POST', '/_search/scroll', {'scroll': '5m'}, 'c2NhbjswOzE7dG90YWxfaGl0czoxMDA7' ) assert status == 200 assert '_scroll_id' in data
def test_non_deserializable_elements_in_body(): import datetime body = { 'filter': { 'range': { 'date': { 'gte': datetime.datetime(2014, 7, 1, 0, 0), 'lte': datetime.datetime(2014, 7, 15, 23, 59, 59) } } } } f = StringIO.StringIO(IN_DATETIME) t = ReplayTransport([{}], recfile=f, connection_class=DummyConnection) status, data = t.perform_request('GET', '/_search', body=body) assert status == 200
def setUp(self): f = StringIO.StringIO(IN_CONTENTS) self.t = ReplayTransport([{}], recfile=f, connection_class=DummyConnection) self.args = ('GET', '/myindex')
class ReplayTransportFullTestCase(unittest.TestCase): def setUp(self): f = StringIO.StringIO(IN_CONTENTS) self.t = ReplayTransport([{}], recfile=f, connection_class=DummyConnection) self.args = ('GET', '/myindex') def test_simple_fetch(self): status, data = self.t.perform_request(*self.args) calls = self.t.get_connection().calls assert not calls, "Call to connection made" assert status == 200 assert {"key": "value"} == data def test_more_requests(self): status1, data1 = self.t.perform_request(*self.args) status2, data2 = self.t.perform_request( 'GET', '/myindex2', body='{"req": "body"}' ) assert status1 == 200 assert {"key": "value"} == data1 assert status2 == 200 assert {"key": "value2"} == data2 with self.assertRaises(ReplayLogExceededError): self.t.perform_request(*self.args) def test_diffrent_body_same_after_deserialization(self): self.t.perform_request(*self.args) status, data = self.t.perform_request( 'GET', '/myindex2', body='{"req": \n "body"}' ) assert status == 200 assert {"key": "value2"} == data def test_body_as_dict(self): self.t.perform_request(*self.args) status, data = self.t.perform_request( 'GET', '/myindex2', body={"req": "body"} ) assert status == 200 assert {"key": "value2"} == data