def test_disconnects_if_not_connected(self, client: Client): client.connect = MagicMock() client.disconnect = MagicMock() was_successful = client.queue("test", args=(1, 2)) client.connect.assert_called_once() client.disconnect.assert_called_once()
def test_uses_inputs_for_job_submission( self, client: Client, job_id: str, job_name: str, job_priority: int, num_retries: int, queue: str, args: Iterable, ): was_successful = client.queue(task=job_name, args=args, queue=queue, jid=job_id, priority=job_priority) assert was_successful client.faktory.reply.assert_called_once() client.faktory.get_message.assert_called_once() assert client.faktory.reply.call_args[0][0] == "PUSH" request = client.faktory.reply.call_args[0][1] assert request["jobtype"] == job_name assert request["args"] == list(args) assert request["jid"] == job_id assert request["queue"] == queue assert request["priority"] == job_priority
def test_can_queue_job(self, client: Client): was_successful = client.queue("test", args=(1, 2)) assert was_successful client.faktory.reply.assert_called_once() client.faktory.get_message.assert_called_once() assert client.faktory.reply.call_args[0][0] == "PUSH" request = client.faktory.reply.call_args[0][1] assert request["jobtype"] == "test" assert request["args"] == [1, 2] assert request["jid"] is not None assert request["queue"] == "default"
def test_can_queue_job_with_generator(self, client: Client): # Split out in another test because generator gets consumed # when being cast to list, so we can't use it in parametrize was_successful = client.queue("test", args=(val for val in [1, 2])) assert was_successful client.faktory.reply.assert_called_once() client.faktory.get_message.assert_called_once() assert client.faktory.reply.call_args[0][0] == "PUSH" request = client.faktory.reply.call_args[0][1] assert request["jobtype"] == "test" assert request["args"] == [1, 2] assert request["jid"] is not None assert request["queue"] == "default"
def test_creates_connection_from_url(): client = Client("tcp://a-server:7419") assert client.faktory.host == "a-server" assert client.faktory.port == 7419
def test_constructor_uses_existing_conn(conn): client = Client(connection=conn) assert client.faktory == conn
def client(conn) -> Client: return Client(connection=conn)
def test_requires_sequence_args(self, client: Client): with pytest.raises(ValueError): client.queue("test", args="will error because not sequence")
def test_requires_queue_name(self, client: Client): with pytest.raises(ValueError): client.queue("test", queue=None)
def test_requires_task_name(self, client: Client): with pytest.raises(ValueError): client.queue(None, args=(1, 2))