def test_write_and_read(self): """Tests writing-to and reading-from TCP Host.""" frame = "%s>%s:%s" % ( self.random(6), ','.join([self.random(6), self.random(6), self.random(6)]), ' '.join([ self.random(), 'test_write_and_read', self.random()]) ) aprs_frame = aprs.Frame(frame) kiss_frame = aprs_frame.encode_kiss() ks = kiss.TCPKISS(host=self.random_host, port=self.random_port) a = (self.random_host, self.random_port) entry = MocketEntry(a, [kiss_frame]) entry_1 = MocketEntry(('localhost', 80), True) Mocket.register(entry) ks.interface = create_connection(a) ks._write_handler = ks.interface.sendall def _pass(): pass ks.stop = _pass ks.write(kiss_frame) _read_data = ks.read(len(kiss_frame), readmode=False) self._logger.info( '_read_data(%s)="%s"', len(_read_data), _read_data)
def test_write_and_read(self): """Tests writing-to and reading-from TCP Host.""" frame = "%s>%s:%s" % (self.random(6), ','.join([ self.random(6), self.random(6), self.random(6) ]), ' '.join([self.random(), 'test_write_and_read', self.random()])) aprs_frame = aprs.Frame(frame) kiss_frame = aprs_frame.encode_kiss() ks = kiss.TCPKISS(host=self.random_host, port=self.random_port) a = (self.random_host, self.random_port) entry = MocketEntry(a, [kiss_frame]) entry_1 = MocketEntry(('localhost', 80), True) Mocket.register(entry) ks.interface = create_connection(a) ks._write_handler = ks.interface.sendall def _pass(): pass ks.stop = _pass ks.write(kiss_frame) _read_data = ks.read(len(kiss_frame), readmode=False) self._logger.info('_read_data(%s)="%s"', len(_read_data), _read_data)
def test_wrong_ack_additional_answer(self): with mock.patch.object(pylogbeat, 'LOGGER', new=self._mocked_logger): # respond with wrong ACK sequence response = b'2A\\x00\x00\x00\x03\x03\x03' Mocket.register(MocketEntry((SOCKET_HOST, SOCKET_PORT), [response])) exc = None client = self._factor_client() try: with self.assertRaises(pylogbeat.ConnectionException) as exc: client.send([MESSAGE, MESSAGE]) finally: client.close() if exc is not None: message = str(exc.exception) expected_message = 'No ACK received or wrong frame type "0x00"' self.assertEqual(message, expected_message) self.assertEqual(len(Mocket._requests), 1) # logger self._mocked_logger.log.assert_any_call( logging.WARNING, 'Waited for ACK from server but received an unexpected frame: "0x00". Aborting.' ) self._mocked_logger.reset_mock()
def _test_write(self): frame = "%s>%s:%s" % ( self.random(6), ','.join([self.random(6), self.random(6), self.random(6)]), ' '.join([ self.random(), 'test_write', self.random()]) ) aprs_frame = aprs.Frame(frame) kiss_frame = aprs_frame.encode_kiss() ks = kiss.TCPKISS(host=self.random_host, port=self.random_port) a = (self.random_host, self.random_port) entry = MocketEntry(a, kiss_frame) Mocket.register(entry) self._logger.debug(a) self._logger.debug(entry.get_response()) ks.interface = create_connection(a) ks._write_handler = ks.interface.sendall def _pass(): pass ks.stop = _pass ks.write(kiss_frame)
def _test_write(self): frame = "%s>%s:%s" % (self.random(6), ','.join([ self.random(6), self.random(6), self.random(6) ]), ' '.join([self.random(), 'test_write', self.random()])) aprs_frame = aprs.Frame(frame) kiss_frame = aprs_frame.encode_kiss() ks = kiss.TCPKISS(host=self.random_host, port=self.random_port) a = (self.random_host, self.random_port) entry = MocketEntry(a, kiss_frame) Mocket.register(entry) self._logger.debug(a) self._logger.debug(entry.get_response()) ks.interface = create_connection(a) ks._write_handler = ks.interface.sendall def _pass(): pass ks.stop = _pass ks.write(kiss_frame)
def single_register(cls, method, uri, body='', status=200, headers=None, match_querystring=True): entry = cls( uri, method, Response( body=body, status=status, headers=headers ), match_querystring=match_querystring ) Mocket.register(entry) return entry
def test_register(self): entry_1 = MocketEntry(('localhost', 80), True) entry_2 = MocketEntry(('localhost', 80), True) entry_3 = MocketEntry(('localhost', 8080), True) Mocket.register(entry_1, entry_2, entry_3) self.assertEqual(Mocket._entries, { ('localhost', 80): [entry_1, entry_2], ('localhost', 8080): [entry_3], })
def setUp(self): # clean up singleton durign testing Player._instances.clear() self.hostname = 'localhost' self.cluster = 'test_cluster' self.routing_key = Constants.CONDUCTOR_ROUTING_KEY self.connection = Connection(get_broker_url()) self.exchange = Exchange(Constants.CONDUCTOR_EXCHANGE) # turn on mocket Mocket.enable()
def test_ok(self): # window size (we will send two messages below, so let's answer with two) response = b'2A\x00\x00\x00\x02' Mocket.register(MocketEntry((SOCKET_HOST, SOCKET_PORT), [response])) client = self._factor_client() try: client.send([MESSAGE, MESSAGE]) finally: client.close() self.assertEqual(len(Mocket._requests), 1)
def test_client_unsubscribes_to_event(self): ack = C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_SEPARATOR unsubscribe_ack = C.TOPIC_EVENT + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_UNSUBSCRIBE + C.MESSAGE_PART_SEPARATOR + "test1" + C.MESSAGE_SEPARATOR unsubscribe = C.TOPIC_EVENT + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_UNSUBSCRIBE + C.MESSAGE_PART_SEPARATOR + "test1" + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(ack), str.encode(unsubscribe_ack)])) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(0.1) ds.event.unsubscribe("test1", None) time.sleep(0.1) assert Mocket.last_request() == (str(str.encode(unsubscribe)))
async def main(l): async with aiohttp.ClientSession(loop=l) as session: with async_timeout.timeout(3): async with session.get(url) as get_response: assert get_response.status == 404 assert await get_response.text() == body with async_timeout.timeout(3): async with session.post(url, data=body * 6) as post_response: assert post_response.status == 201 assert await post_response.text() == body * 2 assert Mocket.last_request().method == 'POST' assert Mocket.last_request().body == body * 6
def test_client_receives_login_confirmation(self): """ Scenario: The client receives a login confirmation When the server sends the message A|A+ Then the clients connection state is "OPEN" And the last login was successful """ ack = C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(ack)])) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(0.1) assert ds.get_connection_state() == C.CONNECTION_STATE_OPEN
def single_register(cls, method, uri, body='', status=200, headers=None, match_querystring=True): entry = cls(uri, method, Response(body=body, status=status, headers=headers), match_querystring=match_querystring) Mocket.register(entry) return entry
def test_client_receives_invalid_authentication_data(self): """ Scenario: The client's authentication data is rejected Given the client is initialised When the client logs in with username "XXX" and password "ZZZ" But the server sends the message A|E|INVALID_AUTH_DATA|Sinvalid authentication data+ Then the last login failed with error "INVALID_AUTH_DATA" and message "invalid authentication data" """ invalid_auth_data = C.TOPIC_AUTH + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ERROR + C.MESSAGE_PART_SEPARATOR + "INVALID_AUTH_DATA" + C.MESSAGE_PART_SEPARATOR + "Sinvalid authentication data" + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(invalid_auth_data)])) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(0.1) assert ds.get_connection_state() == C.CONNECTION_STATE_AWAITING_AUTHENTICATION
def test_client_made_too_many_unsuccessful_authentication_attempts(self): """ Scenario: The client has made too many unsuccessful authentication attempts Given the client is initialised When the client logs in with username "XXX" and password "ZZZ" But the server sends the message A|E|TOO_MANY_AUTH_ATTEMPTS|Stoo many authentication attempts+ Then the last login failed with error "TOO_MANY_AUTH_ATTEMPTS" and message "too many authentication attempts" """ too_many_auth_attempts = C.TOPIC_AUTH + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ERROR + C.MESSAGE_PART_SEPARATOR + "TOO_MANY_AUTH_ATTEMPTS" + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(too_many_auth_attempts)])) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(0.1) assert ds.get_connection_state() == C.CONNECTION_STATE_AUTHENTICATING
def test_wrong_ack_end_of_stream(self): # respond with wrong ACK sequence response = b'2A\x00\x00\x00\x03' Mocket.register(MocketEntry((SOCKET_HOST, SOCKET_PORT), [response])) client = self._factor_client() try: # on real sockets, here we would expect a timeout or no data; # Mocket raises BlockingIOError with self.assertRaises(BlockingIOError): client.send([MESSAGE, MESSAGE]) finally: client.close() self.assertEqual(len(Mocket._requests), 1)
def test_multipart(self): url = 'http://httpbin.org/post' data = '--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="content"\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 68\r\n\r\nAction: comment\nText: Comment with attach\nAttachment: x1.txt, x2.txt\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_2"; filename="x.txt"\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nbye\n\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_1"; filename="x.txt"\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nbye\n\r\n--xXXxXXyYYzzz--\r\n' headers = { 'Content-Length': '495', 'Content-Type': 'multipart/form-data; boundary=xXXxXXyYYzzz', 'Accept': 'text/plain', 'User-Agent': 'Mocket', 'Accept-encoding': 'identity', } Entry.register(Entry.POST, url) response = requests.post(url, data=data, headers=headers) self.assertEqual(response.status_code, 200) last_request = Mocket.last_request() self.assertEqual(last_request.method, 'POST') self.assertEqual(last_request.path, '/post') self.assertEqual(last_request.body, data) sent_headers = dict(last_request.headers) self.assertEqualHeaders( sent_headers, { 'accept': 'text/plain', 'accept-encoding': 'identity', 'content-length': '495', 'content-type': 'multipart/form-data; boundary=xXXxXXyYYzzz', 'host': 'httpbin.org', 'user-agent': 'Mocket', 'connection': 'keep-alive', } )
def test_http_session(self): url = "http://httpbin.org/ip" body = "asd" * 100 Entry.single_register(Entry.GET, url, body=body, status=404) Entry.single_register(Entry.POST, url, body=body * 2, status=201) async def main(_loop): async with aiohttp.ClientSession(loop=_loop) as session: with async_timeout.timeout(3): async with session.get(url) as get_response: assert get_response.status == 404 assert await get_response.text() == body with async_timeout.timeout(3): async with session.post(url, data=body * 6) as post_response: assert post_response.status == 201 assert await post_response.text() == body * 2 assert Mocket.last_request().method == "POST" assert Mocket.last_request().body == body * 6 loop = asyncio.get_event_loop() loop.set_debug(True) loop.run_until_complete(main(loop)) self.assertEqual(len(Mocket.request_list()), 2)
def test_multipart(self): url = 'http://httpbin.org/post' data = '--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="content"\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Length: 68\r\n\r\nAction: comment\nText: Comment with attach\nAttachment: x1.txt, x2.txt\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_2"; filename="x.txt"\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nbye\n\r\n--xXXxXXyYYzzz\r\nContent-Disposition: form-data; name="attachment_1"; filename="x.txt"\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nbye\n\r\n--xXXxXXyYYzzz--\r\n' headers = { 'Content-Length': '495', 'Content-Type': 'multipart/form-data; boundary=xXXxXXyYYzzz', 'Accept': 'text/plain', 'User-Agent': 'Mocket', 'Accept-encoding': 'identity', } Entry.register(Entry.POST, url) response = requests.post(url, data=data, headers=headers) self.assertEqual(response.status_code, 200) last_request = Mocket.last_request() self.assertEqual(last_request.method, 'POST') self.assertEqual(last_request.path, '/post') self.assertEqual(last_request.body, data) sent_headers = dict(last_request.headers) self.assertEqualHeaders( sent_headers, { 'accept': 'text/plain', 'accept-encoding': 'identity', 'content-length': '495', 'content-type': 'multipart/form-data; boundary=xXXxXXyYYzzz', 'host': 'httpbin.org', 'user-agent': 'Mocket' })
def test_client_sends_login_credentials(self): """ Scenario: The client sends login credentials Given the test server is ready And the client is initialised When the client logs in with username "XXX" and password "YYY" Then the last message the server recieved is A|REQ|{"username":"******","password":"******"}+ And the clients connection state is "AUTHENTICATING" """ Mocket.register(MocketEntry(('localhost', 8989), 0)) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(0.1) auth_msg = C.TOPIC_AUTH + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_REQUEST + C.MESSAGE_PART_SEPARATOR + "{\"password\": \"YYY\", \"username\": \"XXX\"}" + C.MESSAGE_SEPARATOR assert (Mocket.last_request()) == (str(str.encode(auth_msg))) assert ds.get_connection_state() == C.CONNECTION_STATE_AUTHENTICATING
def test_client_listens_to_event_prefix(self): ''' Scenario: The client listens to eventPrefix When the client listens to events matching "eventPrefix/.*" Then the last message the server received is E|L|eventPrefix/.*+ Then the server sends the message E|A|L|eventPrefix/.*+ ''' ack = C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_SEPARATOR listen_ack = C.TOPIC_EVENT + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_LISTEN + C.MESSAGE_PART_SEPARATOR + "regex/\*" + C.MESSAGE_SEPARATOR listen = C.TOPIC_EVENT + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_LISTEN + C.MESSAGE_PART_SEPARATOR + "regex/\*" + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(ack), str.encode(listen_ack)])) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(0.1) ds.event.listen("regex/\*", None) time.sleep(0.1) assert Mocket.last_request() == (str(str.encode(listen)))
def test_client_subscribes_to_event(self): """ Scenario: The client subscribes to an event Given the client subscribes to an event named "test1" Then the last message the server received is E|S|test1+ Then the server sends the message E|A|S|test1+ """ ack = C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_SEPARATOR subscribe_ack = C.TOPIC_EVENT + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_SUBSCRIBE + C.MESSAGE_PART_SEPARATOR + "test1" + C.MESSAGE_SEPARATOR subscribe = C.TOPIC_EVENT + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_SUBSCRIBE + C.MESSAGE_PART_SEPARATOR + "test1" + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(ack), str.encode(subscribe_ack)])) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(0.1) ds.event.subscribe("test1", None) time.sleep(0.1) assert Mocket.last_request() == (str(str.encode(subscribe)))
def test_client_cant_connect_after_TOO_MANY_AUTH_ATTEMPTS(self): """ Scenario: The client can't made further authentication attempts after it received TOO_MANY_AUTH_ATTEMPTS Given the server resets its message count When the client logs in with username "XXX" and password "ZZZ" Then the server has received 0 messages And the client throws a "IS_CLOSED" error with message "this client's connection was closed" """ too_many_auth_attempts = C.TOPIC_AUTH + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ERROR + C.MESSAGE_PART_SEPARATOR + "TOO_MANY_AUTH_ATTEMPTS" + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(too_many_auth_attempts)])) ds = DeepStreamClient('localhost', 8989) credentials = {"username": "******", "password": "******"} ds.login(credentials, None) time.sleep(0.1) assert ds.get_connection_state() == C.CONNECTION_STATE_AUTHENTICATING time.sleep(0.1) with pytest.raises(Exception) as excinfo: ds.login(credentials, None) assert 'client\'s connection was closed' in str(excinfo.value)
def test_client_throws_error_when_connection_lost(self): """ Scenario: The client loses its connection to the server When the connection to the server is lost Given two seconds later Then the client throws a "connectionError" error with message "Can't connect! Deepstream server unreachable" And the clients connection state is "RECONNECTING" """ ack = C.ACTIONS_ACK + C.MESSAGE_PART_SEPARATOR + C.ACTIONS_ACK + C.MESSAGE_SEPARATOR Mocket.register(MocketEntry(('localhost', 8989), [str.encode(ack)])) ds = DeepStreamClient('localhost', 8989) ds.login({"username": "******", "password": "******"}, None) time.sleep(1) Mocket.reset() time.sleep(1) with self.assertRaises(Exception) as c: ds.event.subscribe('event1', None) time.sleep(2) self.assertTrue("Can't connect! Deepstream server unreachable" in c.exception.args[0])
async def test_http_session(self): url = "http://httpbin.org/ip" body = "asd" * 100 Entry.single_register(Entry.GET, url, body=body, status=404) Entry.single_register(Entry.POST, url, body=body * 2, status=201) async with aiohttp.ClientSession() as session: with async_timeout.timeout(3): async with session.get(url) as get_response: assert get_response.status == 404 assert await get_response.text() == body with async_timeout.timeout(3): async with session.post(url, data=body * 6) as post_response: assert post_response.status == 201 assert await post_response.text() == body * 2 assert Mocket.last_request().method == "POST" assert Mocket.last_request().body == body * 6 self.assertEqual(len(Mocket.request_list()), 2)
def _pre_setup(self): # Use Mocket to prevent any real network access from tests Mocket.enable() # Mock at the level of requests library. # Connectivity tests can use lower level mocks at socket level instead. if self.mock_requests: responses.start() # Start with empty config by default #patch('dpm.main.ConfigObj', lambda *a: {}).start() self.config = { 'username': '******', 'pasword': 'password', } patch('dpm.main.ConfigObj', lambda *a: self.config).start() #self.config.update( #server_url='https://example.com' #) self.runner = CliRunner()
def _pre_setup(self): # Use Mocket to prevent any real network access from tests Mocket.enable() # Mock at the level of requests library. # Connectivity tests can use lower level mocks at socket level instead. if self.mock_requests: responses.start() # Start with default config self._config = ConfigObj({ 'username': '******', 'password': '******', }) self.config = MagicMock(spec_set=self._config) self.config.__getitem__.side_effect = self._config.__getitem__ self.config.__setitem__.side_effect = self._config.__setitem__ self.config.get.side_effect = self._config.get patch('dpm.main.ConfigObj', lambda *a: self.config).start() self.runner = CliRunner()
def test_remove_last_empty(self): Mocket.remove_last_request() self.assertEqual(Mocket._requests, [])
def activate(self): Mocket.disable() Mocket.enable()
def disable(self): Mocket.disable()
def single_register(cls, method, uri, body='', status=200, headers=None): entry = cls(uri, method, Response(body=body, status=status, headers=headers)) Mocket.register(entry) return entry
def test_set(self): Entry.register_response('SET mocket "is awesome!"', OK) self.assertTrue(self.rclient.set('mocket', 'is awesome!')) self.assertEqual(len(Mocket._requests), 1) self.assertEqual(Mocket.last_request().data, b'*3\r\n$3\r\nSET\r\n$6\r\nmocket\r\n$11\r\nis awesome!\r\n')
def test_lrange(self): l = [b'one', b'two', b'three'] Entry.register_response('LRANGE list 0 -1', l) self.assertEqual(self.rclient.lrange('list', 0, -1), l) self.assertEqual(len(Mocket._requests), 1) self.assertEqual(Mocket.last_request().data, b'*4\r\n$6\r\nLRANGE\r\n$4\r\nlist\r\n$1\r\n0\r\n$2\r\n-1\r\n')
def test_lastrequest(self): self.assertEqual(Mocket.last_request(), None) Mocket._requests.extend([1, 2, 3]) self.assertEqual(Mocket.last_request(), 3)
def test_err(self): Entry.register_response('INCRBY counter one', ERROR('ERR value is not an integer or out of range')) self.assertRaises(redis.ResponseError, self.rclient.incr, 'counter', 'one') self.assertEqual(len(Mocket._requests), 1) self.assertEqual(Mocket.last_request().data, b'*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$3\r\none\r\n')
def test_get_unicode(self): Entry.register_response('GET snowman', '\u2603') self.assertEqual(self.rclient.get('snowman'), b'\xe2\x98\x83') self.assertEqual(len(Mocket._requests), 1) self.assertEqual(Mocket.last_request().data, b'*2\r\n$3\r\nGET\r\n$7\r\nsnowman\r\n')
def test_getentry(self): entry = MocketEntry(('localhost', 80), True) Mocket.register(entry) self.assertEqual(Mocket.get_entry('localhost', 80, True), entry)
def test_reset(self): Mocket._requests.extend([1, 2, 3]) self.assertEqual(Mocket._requests, [1, 2, 3]) Mocket.reset() self.assertEqual(Mocket._requests, [])
def setUp(self): Mocket.reset()
def test_gethostname(self): hostname = socket.gethostname() Mocket.enable() self.assertEqual(socket.gethostname(), 'localhost') Mocket.disable() self.assertEqual(socket.gethostname(), hostname)
def test_gethostbyname(self): host = socket.gethostbyname('localhost') Mocket.enable() self.assertEqual(socket.gethostbyname('localhost'), '127.0.0.1') Mocket.disable() self.assertEqual(socket.gethostbyname('localhost'), host)
def tearDown(self): # since Player is a singleton object. we need to destroy it # turn off mocket when test is over Mocket.disable()
def test_collect(self): request = 'GET /get/p/?b=2&a=1 HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: testme.org\r\nConnection: close\r\nUser-Agent: Python-urllib/2.6\r\n\r\n' Mocket.collect(request) self.assertEqual(Mocket.last_request(), request) self.assertEqual(Mocket._requests, [request])
def mocketize_setup(self): Entry.register_response('FLUSHDB', OK) self.rclient.flushdb() self.assertEqual(len(Mocket._requests), 1) Mocket.reset()
def test_remove_last(self): Mocket._requests = [1, 2] Mocket.remove_last_request() self.assertEqual(Mocket._requests, [1])
def disable(): Mocket.disable()