Repository: apify/crawlee-python
File: tests/unit/_memory_storage_client/test_request_queue_client.py (Python)

Code before:

async def test_list_head(request_queue_client: RequestQueueClient) -> None:
    await request_queue_client.add_request(Request.from_url('https://apify.com'))
    await request_queue_client.add_request(Request.from_url('https://example.com'))
    list_head = await request_queue_client.list_head()
    assert len(list_head.items) == 2

    for item in list_head.items:
        assert item.id is not None


async def test_request_state_serialization(request_queue_client: RequestQueueClient) -> None:
    request = Request.from_url('https://crawlee.dev', payload=b'test')
    request.state = RequestState.UNPROCESSED

    await request_queue_client.add_request(request)

    result = await request_queue_client.list_head()
    assert len(result.items) == 1
    assert result.items[0] == request

    got_request = await request_queue_client.get_request(request.id)

    assert request == got_request
    assert request.payload == got_request.payload
    assert got_request.payload != b"b'test'"


async def test_add_record(request_queue_client: RequestQueueClient) -> None:
    processed_request_forefront = await request_queue_client.add_request(
        Request.from_url('https://apify.com'),
        forefront=True,
    )
    processed_request_not_forefront = await request_queue_client.add_request(
        Request.from_url('https://example.com'),
        forefront=False,
    )

    assert processed_request_forefront.id is not None
    assert processed_request_not_forefront.id is not None
    assert processed_request_forefront.was_already_handled is False
    assert processed_request_not_forefront.was_already_handled is False

    rq_info = await request_queue_client.get()
    assert rq_info is not None
    assert rq_info.pending_request_count == rq_info.total_request_count == 2
    assert rq_info.handled_request_count == 0


async def test_get_record(request_queue_client: RequestQueueClient) -> None:
    request_url = 'https://apify.com'

Review comment (suggestion):
I believe this should be enough, correct?

```suggestion
    assert request.payload == got_request.payload
```

Code after:

async def test_list_head(request_queue_client: RequestQueueClient) -> None:
    await request_queue_client.add_request(Request.from_url('https://apify.com'))
    await request_queue_client.add_request(Request.from_url('https://example.com'))
    list_head = await request_queue_client.list_head()
    assert len(list_head.items) == 2

    for item in list_head.items:
        assert item.id is not None


async def test_request_state_serialization(request_queue_client: RequestQueueClient) -> None:
    request = Request.from_url('https://crawlee.dev', payload=b'test')
    request.state = RequestState.UNPROCESSED

    await request_queue_client.add_request(request)

    result = await request_queue_client.list_head()
    assert len(result.items) == 1
    assert result.items[0] == request

    got_request = await request_queue_client.get_request(request.id)

    assert request == got_request
    assert request.payload == got_request.payload


async def test_add_record(request_queue_client: RequestQueueClient) -> None:
    processed_request_forefront = await request_queue_client.add_request(
        Request.from_url('https://apify.com'),
        forefront=True,
    )
    processed_request_not_forefront = await request_queue_client.add_request(
        Request.from_url('https://example.com'),
        forefront=False,
    )

    assert processed_request_forefront.id is not None
    assert processed_request_not_forefront.id is not None
    assert processed_request_forefront.was_already_handled is False
    assert processed_request_not_forefront.was_already_handled is False

    rq_info = await request_queue_client.get()
    assert rq_info is not None
    assert rq_info.pending_request_count == rq_info.total_request_count == 2
    assert rq_info.handled_request_count == 0


async def test_get_record(request_queue_client: RequestQueueClient) -> None:
    request_url = 'https://apify.com'
    processed_request = await request_queue_client.add_request(Request.from_url(request_url))