Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@
a URL for its storage.
"""

import datetime
import io
import uuid
from http import HTTPStatus
from urllib.parse import urlsplit, urlunsplit

import pytest
import requests
from beartype import BeartypeConf, beartype
from freezegun import freeze_time

from mock_vws import MockVWS
from mock_vws.database import CloudDatabase
from tests.mock_vws.reco_counts_report.helpers import (
CSV_HEADER,
Expand Down Expand Up @@ -183,43 +178,3 @@ def test_counts_set_after_first_request(
# new file, and nothing is claimed about that.
same_file = urlsplit(url=first_url).path == urlsplit(url=second_url).path
assert not same_file or ready_response.text == CSV_HEADER


@pytest.mark.parametrize(
argnames="processing_time_seconds",
argvalues=[
pytest.param(60, id="integer"),
pytest.param(60.0, id="float"),
pytest.param(0.5, id="fractional"),
],
)
@beartype(conf=BeartypeConf(is_pep484_tower=True))
def test_report_processing_time(
*, base_vws_url: str, processing_time_seconds: float
) -> None:
"""Integer and float delays make reports ready at their completion
time.
"""
database = CloudDatabase()
with (
freeze_time(time_to_freeze="2026-10-13 12:00:00") as frozen_time,
MockVWS(
base_vws_url=base_vws_url,
processing_time_seconds=processing_time_seconds,
) as mock,
):
mock.add_cloud_database(cloud_database=database)
presigned_url = get_presigned_url(
base_vws_url=base_vws_url,
vuforia_database=database,
month=month_offset_from_now(months=0),
)
response = requests.get(url=presigned_url, timeout=30)
assert_not_ready(response=response, key=report_key(url=presigned_url))

_ = frozen_time.tick(
delta=datetime.timedelta(seconds=processing_time_seconds),
)
response = requests.get(url=presigned_url, timeout=30)
assert response.status_code == HTTPStatus.OK
assert response.text == CSV_HEADER
59 changes: 59 additions & 0 deletions tests/mock_vws/requests_mock/test_reco_counts_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Tests for report timing in the in-memory mock."""

import datetime
from http import HTTPStatus

import pytest
import requests
from beartype import BeartypeConf, beartype
from freezegun import freeze_time

from mock_vws import MockVWS
from mock_vws.database import CloudDatabase
from tests.mock_vws.reco_counts_report.helpers import (
CSV_HEADER,
assert_not_ready,
get_presigned_url,
month_offset_from_now,
report_key,
)


@pytest.mark.parametrize(
argnames="processing_time_seconds",
argvalues=[
pytest.param(60, id="integer"),
pytest.param(60.0, id="float"),
pytest.param(0.5, id="fractional"),
],
)
@beartype(conf=BeartypeConf(is_pep484_tower=True))
def test_report_processing_time(
*, base_vws_url: str, processing_time_seconds: float
) -> None:
"""Integer and float delays make reports ready at their completion
time.
"""
database = CloudDatabase()
with (
freeze_time(time_to_freeze="2026-10-13 12:00:00") as frozen_time,
MockVWS(
base_vws_url=base_vws_url,
processing_time_seconds=processing_time_seconds,
) as mock,
):
mock.add_cloud_database(cloud_database=database)
presigned_url = get_presigned_url(
base_vws_url=base_vws_url,
vuforia_database=database,
month=month_offset_from_now(months=0),
)
response = requests.get(url=presigned_url, timeout=30)
assert_not_ready(response=response, key=report_key(url=presigned_url))

_ = frozen_time.tick(
delta=datetime.timedelta(seconds=processing_time_seconds),
)
response = requests.get(url=presigned_url, timeout=30)
assert response.status_code == HTTPStatus.OK
assert response.text == CSV_HEADER
Loading