def test_fetches_using_queues(self, monkeypatch, queues: List[str]):

        mock_reply = MagicMock()
        mock_get_message = MagicMock(return_value=iter([None]))
        conn = Connection()

        monkeypatch.setattr(conn, "reply", mock_reply)
        monkeypatch.setattr(conn, "get_message", mock_get_message)

        conn.fetch(queues)

        mock_reply.assert_called_once()
        mock_get_message.assert_called_once()

        reply_args = mock_reply.call_args[0][0]
        assert "FETCH" in reply_args
        for queue in queues:
            assert queue in reply_args
    def test_returns_none_if_no_job(self, monkeypatch):

        mock_reply = MagicMock()
        mock_get_message = MagicMock(return_value=iter([None]))
        conn = Connection()

        monkeypatch.setattr(conn, "reply", mock_reply)
        monkeypatch.setattr(conn, "get_message", mock_get_message)

        queues = ["default"]
        result = conn.fetch(queues)

        mock_reply.assert_called_once()
        mock_get_message.assert_called_once()
        assert result is None
    def test_returns_deserialized_job_info_if_present(self, monkeypatch):

        data = {
            "wid": "test worker",
            "pid": 500,
            "labels": ["tests"],
            "hostname": "test suite",
        }
        serialized_data = json.dumps(data)
        mock_reply = MagicMock()
        mock_get_message = MagicMock(return_value=iter([serialized_data]))
        conn = Connection()

        monkeypatch.setattr(conn, "reply", mock_reply)
        monkeypatch.setattr(conn, "get_message", mock_get_message)

        queues = ["default"]
        result = conn.fetch(queues)

        mock_reply.assert_called_once()
        mock_get_message.assert_called_once()
        assert result == data