Skip to content
Open
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
28 changes: 28 additions & 0 deletions src/mock_vws/_mock_common.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Common utilities for creating mock routes."""

import email.utils
import json
import uuid
from collections.abc import Iterable, Mapping
from dataclasses import dataclass
from typing import Any

from beartype import beartype

from mock_vws._constants import ResultCodes
from mock_vws.target import ImageTarget

# A database ID as it appears in the path of a reco counts report request.
Expand Down Expand Up @@ -97,6 +100,31 @@ def sorted_targets(*, targets: Iterable[ImageTarget]) -> list[ImageTarget]:
)


@beartype
def result_code_response_text(*, result_code: ResultCodes) -> str:
"""
Args:
result_code: The result code to give in the response body.

Returns:
The body of a Vuforia error response, with a new transaction ID.
"""
body = {
"transaction_id": uuid.uuid4().hex,
"result_code": result_code.value,
}
return json_dump(body=body)


@beartype
def http_date() -> str:
"""
Returns:
The current time, formatted for an HTTP ``Date`` header.
"""
return email.utils.formatdate(timeval=None, localtime=False, usegmt=True)


@beartype
def json_dump(*, body: dict[str, Any]) -> str:
"""
Expand Down
Loading
Loading