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
2 changes: 1 addition & 1 deletion docs/source/mock-api-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ API Reference
:members:
:undoc-members:

.. autoclass:: mock_vws.target.Target
.. autoclass:: mock_vws.target.ImageTarget

Image matchers
--------------
Expand Down
4 changes: 2 additions & 2 deletions src/mock_vws/_flask_server/target_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from mock_vws.database import VuforiaDatabase
from mock_vws.states import States
from mock_vws.target import Target
from mock_vws.target import ImageTarget
from mock_vws.target_manager import TargetManager
from mock_vws.target_raters import (
BrisqueTargetTrackingRater,
Expand Down Expand Up @@ -202,7 +202,7 @@ def create_target(database_name: str) -> Response:
settings = TargetManagerSettings.model_validate(obj={})
target_tracking_rater = settings.target_rater.to_target_rater()

target = Target(
target = ImageTarget(
name=request_json["name"],
width=request_json["width"],
image_value=image_bytes,
Expand Down
4 changes: 2 additions & 2 deletions src/mock_vws/_flask_server/vws.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
ImageMatcher,
StructuralSimilarityMatcher,
)
from mock_vws.target import Target
from mock_vws.target import ImageTarget
from mock_vws.target_raters import (
HardcodedTargetTrackingRater,
)
Expand Down Expand Up @@ -192,7 +192,7 @@ def add_target() -> Response:
# This rater is not used.
target_tracking_rater = HardcodedTargetTrackingRater(rating=1)

new_target = Target(
new_target = ImageTarget(
name=name,
width=request_json["width"],
image_value=base64.b64decode(s=request_json["image"]),
Expand Down
4 changes: 2 additions & 2 deletions src/mock_vws/_requests_mock_server/mock_web_services_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
ValidatorError,
)
from mock_vws.image_matchers import ImageMatcher
from mock_vws.target import Target
from mock_vws.target import ImageTarget
from mock_vws.target_manager import TargetManager
from mock_vws.target_raters import TargetTrackingRater

Expand Down Expand Up @@ -187,7 +187,7 @@ def add_target(self, request: PreparedRequest) -> _ResponseType:

application_metadata = request_json.get("application_metadata")

new_target = Target(
new_target = ImageTarget(
name=request_json["name"],
width=request_json["width"],
image_value=base64.b64decode(s=request_json["image"]),
Expand Down
23 changes: 13 additions & 10 deletions src/mock_vws/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from mock_vws._constants import TargetStatuses
from mock_vws.states import States
from mock_vws.target import Target, TargetDict
from mock_vws.target import ImageTarget, ImageTargetDict


@beartype
Expand All @@ -22,7 +22,7 @@ class DatabaseDict(TypedDict):
client_access_key: str
client_secret_key: str
state_name: str
targets: Iterable[TargetDict]
targets: Iterable[ImageTargetDict]


@beartype
Expand Down Expand Up @@ -61,7 +61,10 @@ class VuforiaDatabase:
# ``frozen=True`` while still being able to keep the interface we want.
# In particular, we might want to inspect the ``database`` object's targets
# as they change via API requests.
targets: set[Target] = field(default_factory=set[Target], hash=False)
targets: set[ImageTarget] = field(
default_factory=set[ImageTarget],
hash=False,
)
state: States = States.WORKING

request_quota: int = 100000
Expand All @@ -84,7 +87,7 @@ def to_dict(self) -> DatabaseDict:
"targets": targets,
}

def get_target(self, target_id: str) -> Target:
def get_target(self, target_id: str) -> ImageTarget:
"""Return a target from the database with the given ID."""
(target,) = (
target for target in self.targets if target.target_id == target_id
Expand All @@ -102,18 +105,18 @@ def from_dict(cls, database_dict: DatabaseDict) -> Self:
client_secret_key=database_dict["client_secret_key"],
state=States[database_dict["state_name"]],
targets={
Target.from_dict(target_dict=target_dict)
ImageTarget.from_dict(target_dict=target_dict)
for target_dict in database_dict["targets"]
},
)

@property
def not_deleted_targets(self) -> set[Target]:
def not_deleted_targets(self) -> set[ImageTarget]:
"""All targets which have not been deleted."""
return {target for target in self.targets if not target.delete_date}

@property
def active_targets(self) -> set[Target]:
def active_targets(self) -> set[ImageTarget]:
"""All active targets."""
return {
target
Expand All @@ -123,7 +126,7 @@ def active_targets(self) -> set[Target]:
}

@property
def inactive_targets(self) -> set[Target]:
def inactive_targets(self) -> set[ImageTarget]:
"""All inactive targets."""
return {
target
Expand All @@ -133,7 +136,7 @@ def inactive_targets(self) -> set[Target]:
}

@property
def failed_targets(self) -> set[Target]:
def failed_targets(self) -> set[ImageTarget]:
"""All failed targets."""
return {
target
Expand All @@ -142,7 +145,7 @@ def failed_targets(self) -> set[Target]:
}

@property
def processing_targets(self) -> set[Target]:
def processing_targets(self) -> set[ImageTarget]:
"""All processing targets."""
return {
target
Expand Down
8 changes: 4 additions & 4 deletions src/mock_vws/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)


class TargetDict(TypedDict):
class ImageTargetDict(TypedDict):
"""A dictionary type which represents a target."""

name: str
Expand Down Expand Up @@ -50,7 +50,7 @@ def _time_now() -> datetime.datetime:

@beartype(conf=BeartypeConf(is_pep484_tower=True))
@dataclass(frozen=True, eq=True)
class Target:
class ImageTarget:
"""
A Vuforia Target as managed in
https://developer.vuforia.com/target-manager.
Expand Down Expand Up @@ -145,7 +145,7 @@ def tracking_rating(self) -> int:
return self._post_processing_target_rating

@classmethod
def from_dict(cls, target_dict: TargetDict) -> Self:
def from_dict(cls, target_dict: ImageTargetDict) -> Self:
"""Load a target from a dictionary."""
timezone = ZoneInfo(key="GMT")
name = target_dict["name"]
Expand Down Expand Up @@ -187,7 +187,7 @@ def from_dict(cls, target_dict: TargetDict) -> Self:
target_tracking_rater=target_tracking_rater,
)

def to_dict(self) -> TargetDict:
def to_dict(self) -> ImageTargetDict:
"""Dump a target to a dictionary which can be loaded as JSON."""
delete_date: str | None = None
if self.delete_date:
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_vws/fixtures/vuforia_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from mock_vws._flask_server.vws import VWS_FLASK_APP
from mock_vws.database import VuforiaDatabase
from mock_vws.states import States
from mock_vws.target import Target
from mock_vws.target import ImageTarget
from mock_vws.target_raters import HardcodedTargetTrackingRater
from tests.mock_vws.fixtures.credentials import VuMarkVuforiaDatabase
from tests.mock_vws.utils import make_image_file
Expand Down Expand Up @@ -67,7 +67,7 @@ def _vumark_database(
vumark_vuforia_database: VuMarkVuforiaDatabase,
) -> VuforiaDatabase:
"""Return a database with a target for VuMark instance generation."""
vumark_target = Target(
vumark_target = ImageTarget(
active_flag=True,
application_metadata=None,
image_value=make_image_file(
Expand Down
6 changes: 3 additions & 3 deletions tests/mock_vws/test_requests_mock_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mock_vws import MissingSchemeError, MockVWS
from mock_vws.database import VuforiaDatabase
from mock_vws.image_matchers import ExactMatcher, StructuralSimilarityMatcher
from mock_vws.target import Target
from mock_vws.target import ImageTarget
from tests.mock_vws.utils import Endpoint
from tests.mock_vws.utils.usage_test_helpers import (
processing_time_seconds,
Expand Down Expand Up @@ -400,7 +400,7 @@ def test_to_dict(high_quality_image: io.BytesIO) -> None:
# The dictionary is JSON dump-able
assert json.dumps(obj=target_dict)

new_target = Target.from_dict(target_dict=target_dict)
new_target = ImageTarget.from_dict(target_dict=target_dict)
assert new_target == target

@staticmethod
Expand Down Expand Up @@ -436,7 +436,7 @@ def test_to_dict_deleted(high_quality_image: io.BytesIO) -> None:
# The dictionary is JSON dump-able
assert json.dumps(obj=target_dict)

new_target = Target.from_dict(target_dict=target_dict)
new_target = ImageTarget.from_dict(target_dict=target_dict)
assert new_target.delete_date == target.delete_date


Expand Down
4 changes: 2 additions & 2 deletions tests/mock_vws/test_target_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
validate_target_id_exists,
)
from mock_vws.database import VuforiaDatabase
from mock_vws.target import Target
from mock_vws.target import ImageTarget
from mock_vws.target_raters import HardcodedTargetTrackingRater
from tests.mock_vws.utils import make_image_file


def _database_with_target(*, target_id: str) -> VuforiaDatabase:
"""Create a database containing one target with the given ID."""
target = Target(
target = ImageTarget(
active_flag=True,
application_metadata=None,
image_value=make_image_file(
Expand Down
Loading