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_declare_error(self):
"""Worker failed to start if existing queue arguments are different"""
with tasks.kuyruk.channel() as ch:
ch.queue_declare("kuyruk", durable=False)
self.assertRaises(amqp.exceptions.PreconditionFailed,
tasks.echo,
args=('hello world', ))
with run_worker(terminate=False) as worker:
worker.expect('PRECONDITION_FAILED')
def test_user_id(
self, publisher, get_message_from_queue, queue, rabbit_config
):
user_id = rabbit_config['username']
# successful case
publisher.publish("payload", user_id=user_id)
message = get_message_from_queue(queue.name)
assert message.properties['user_id'] == user_id
# when user_id does not match the current user, expect an error
with pytest.raises(PreconditionFailed):
publisher.publish("payload", user_id="invalid")
def reconnect(self):
"""Reconnect to rabbitmq server"""
parsed = urlparse.urlparse(self.amqp_url)
port = parsed.port or 5672
self.connection = amqp.Connection(host="%s:%s" % (parsed.hostname, port),
userid=parsed.username or 'guest',
password=parsed.password or 'guest',
virtual_host=unquote(
parsed.path.lstrip('/') or '%2F'))
self.channel = self.connection.channel()
try:
self.channel.queue_declare(self.name)
except amqp.exceptions.PreconditionFailed:
pass
#self.channel.queue_purge(self.name)
def reconnect(self):
"""Reconnect to rabbitmq server"""
parsed = urlparse.urlparse(self.amqp_url)
port = parsed.port or 5672
self.connection = amqp.Connection(host="%s:%s" % (parsed.hostname, port),
userid=parsed.username or 'guest',
password=parsed.password or 'guest',
virtual_host=unquote(
parsed.path.lstrip('/') or '%2F'))
self.channel = self.connection.channel()
try:
self.channel.queue_declare(self.name)
except amqp.exceptions.PreconditionFailed:
pass
#self.channel.queue_purge(self.name)