Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mocketize_teardown(self):
self.assertEqual(len(Mocket._requests), 0)
def setUp(self):
mocket.Mocket.disable()
def test_register(self):
Entry.register(('localhost', 6379), 'SET snowman "is ☃!"', OK)
self.assertEqual(
Mocket._entries[('localhost', 6379)][0].command,
[b'*3', b'$3', b'SET', b'$7', b'snowman', b'$7', b'is \xe2\x98\x83!']
)
self.assertEqual(
Mocket._entries[('localhost', 6379)][0].responses[0].data,
b'+OK\r\n'
)
"""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 mocketize_setup(self):
Entry.register_response('FLUSHDB', OK)
self.rclient.flushdb()
self.assertEqual(len(Mocket._requests), 1)
Mocket.reset()
@mocketize
def setUp(self):
self.rclient = redis.StrictRedis()
self.rclient.flushdb()
@mocketize
def test_set(self):
self.assertTrue(self.rclient.set('mocket', 'is awesome!'))
@mocketize
def test_incr(self):
Entry.register_responses('INCRBY counter 1', (1, 2, 3))
self.assertEqual(self.rclient.incr('counter'), 1)
self.assertEqual(self.rclient.incr('counter'), 2)
self.assertEqual(self.rclient.incr('counter'), 3)
self.assertEqual(len(Mocket._requests), 3)
self.assertEqual(Mocket._requests[0].data, b'*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$1\r\n1\r\n')
self.assertEqual(Mocket._requests[1].data, b'*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$1\r\n1\r\n')
self.assertEqual(Mocket._requests[2].data, b'*3\r\n$6\r\nINCRBY\r\n$7\r\ncounter\r\n$1\r\n1\r\n')
@mocketize
def test_user_get_userid(self):
# Handler for `user2 = User.get(...)`
Entry.single_register(
Entry.POST,
self.lastuser.endpoint_url(
current_app.lastuser_config['getuser_userid_endpoint']
),
body=json.dumps(
{
"status": "ok",
"type": "user",
"buid": "1234567890123456789012",
"userid": "1234567890123456789012",
"name": "user1",
"title": "User 1",
"label": "User 1 (@user1)",
@mocketize
def test_request_bodies(self):
url = "http://bit.ly/fakeurl/{0}"
for e in range(5):
u = url.format(e)
Entry.single_register(Entry.POST, u, body=str(e))
request_body = urlencode({"key-{0}".format(e): "value={0}".format(e)})
urlopen(u, request_body.encode("utf-8"))
last_request = Mocket.last_request()
assert last_request.body == request_body