Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_router_no_workers(zmq_context, master_config):
seraph = Seraph(master_config)
seraph.start()
try:
client = zmq_context.socket(transport.REQ)
client.connect(master_config.db_queue)
client.send(cbor2.dumps(['FOO']))
with pytest.raises(transport.Error):
client.recv(flags=transport.NOBLOCK)
worker = zmq_context.socket(transport.REQ)
worker.connect(const.ORACLE_QUEUE)
worker.send(b'READY')
client_addr, empty, msg = worker.recv_multipart()
assert cbor2.loads(msg) == ['FOO']
worker.send_multipart([client_addr, empty, cbor2.dumps(['BAR'])])
assert cbor2.loads(client.recv()) == ['BAR']
finally:
seraph.quit()
seraph.join()
def test_router(zmq_context, master_config):
seraph = Seraph(master_config)
seraph.start()
try:
client = zmq_context.socket(transport.REQ)
client.connect(master_config.db_queue)
worker = zmq_context.socket(transport.REQ)
worker.connect(const.ORACLE_QUEUE)
worker.send(b'READY')
client.send(cbor2.dumps(['FOO']))
client_addr, empty, msg = worker.recv_multipart()
assert cbor2.loads(msg) == ['FOO']
worker.send_multipart([client_addr, empty, cbor2.dumps(['BAR'])])
assert cbor2.loads(client.recv()) == ['BAR']
finally:
seraph.quit()
seraph.join()
user = User()
user.oid = 23
user.name = 'Homer Simpson'
user.authid = 'homer'
user.email = 'homer.simpson@example.com'
user.birthday = {
'year': 1950,
'month': 12,
'day': 24
}
user.is_friendly = True
user.tags = [Tag.GEEK, Tag.VIP]
#data = json.dumps(user.marshal(), ensure_ascii=False)
data = cbor2.dumps(user.marshal())
RESULT['objects'] += 1
RESULT['bytes'] += len(data)
def _deserialize_value(self, data):
return cbor2.loads(data)
def test_oracle_badly_formed_request(mock_seraph, task):
assert mock_seraph.recv() == b'READY'
mock_seraph.send_multipart([b'foo', b'', b'', b'', b''])
address, empty, resp = mock_seraph.recv_multipart()
assert cbor2.loads(resp) == ['ERROR', repr('')]
def test_tag_repr():
assert repr(CBORTag(600, 'blah')) == "CBORTag(600, 'blah')"
('c11a514b67b0', datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc)),
('c11a514b67b0', datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))))
], ids=['datetime/utc', 'datetime+micro/utc', 'datetime/eet', 'timestamp/utc', 'timestamp/eet'])
def test_datetime(impl, payload, expected):
decoded = impl.loads(unhexlify(payload))
assert decoded == expected
(datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))), False,
'c07819323031332d30332d32315432323a30343a30302b30323a3030'),
(datetime(2013, 3, 21, 20, 4, 0), False, 'c074323031332d30332d32315432303a30343a30305a'),
(datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc), True, 'c11a514b67b0'),
(datetime(2013, 3, 21, 20, 4, 0, 123456, tzinfo=timezone.utc), True, 'c1fb41d452d9ec07e6b4'),
(datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))), True, 'c11a514b67b0')
], ids=[
'datetime/utc',
'datetime+micro/utc',
'datetime/eet',
'naive',
'timestamp/utc',
'timestamp+micro/utc',
'timestamp/eet'
])
def test_datetime(impl, value, as_timestamp, expected):
expected = unhexlify(expected)
datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc)),
('c0781b323031332d30332d32315432303a30343a30302e3338303834315a',
datetime(2013, 3, 21, 20, 4, 0, 380841, tzinfo=timezone.utc)),
('c07819323031332d30332d32315432323a30343a30302b30323a3030',
datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2)))),
('c11a514b67b0', datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc)),
('c11a514b67b0', datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))))
], ids=['datetime/utc', 'datetime+micro/utc', 'datetime/eet', 'timestamp/utc', 'timestamp/eet'])
def test_datetime(impl, payload, expected):
decoded = impl.loads(unhexlify(payload))
assert decoded == expected
datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2)))),
('c11a514b67b0', datetime(2013, 3, 21, 20, 4, 0, tzinfo=timezone.utc)),
('c11a514b67b0', datetime(2013, 3, 21, 22, 4, 0, tzinfo=timezone(timedelta(hours=2))))
], ids=['datetime/utc', 'datetime+micro/utc', 'datetime/eet', 'timestamp/utc', 'timestamp/eet'])
def test_datetime(impl, payload, expected):
decoded = impl.loads(unhexlify(payload))
assert decoded == expected