Skip to content

Commit 4c67311

Browse files
committed
Make database summary report return a dataclass rather than a dict
1 parent b5cd123 commit 4c67311

File tree

5 files changed

+71
-22
lines changed

5 files changed

+71
-22
lines changed

docs/source/api-reference.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ API Reference
55
:undoc-members:
66
:members:
77

8+
.. automodule:: vws.reports
9+
:undoc-members:
10+
:members:
11+
812
.. automodule:: vws.include_target_data
913
:undoc-members:
1014
:members:

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@
112112
rst_prolog = f"""
113113
.. |project| replace:: {project}
114114
"""
115+
116+
always_document_param_types = True

src/vws/reports.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Classes for representing Vuforia reports.
3+
"""
4+
5+
from dataclasses import dataclass
6+
7+
8+
@dataclass
9+
class DatabaseSummaryReport:
10+
"""
11+
A database summary report.
12+
13+
See
14+
https://library.vuforia.com/articles/Solution/How-To-Use-the-Vuforia-Web-Services-API#How-To-Get-a-Database-Summary-Report.
15+
"""
16+
17+
active_images: int
18+
current_month_recos: int
19+
failed_images: int
20+
inactive_images: int
21+
name: str
22+
previous_month_recos: int
23+
processing_images: int
24+
reco_threshold: int
25+
request_quota: int
26+
request_usage: int
27+
target_quota: int
28+
total_recos: int

src/vws/vws.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from vws._result_codes import raise_for_result_code
1818
from vws.exceptions import TargetProcessingTimeout
19+
from vws.reports import DatabaseSummaryReport
1920

2021

2122
def _target_api_request(
@@ -379,7 +380,7 @@ def get_target_summary_report(
379380

380381
return dict(response.json())
381382

382-
def get_database_summary_report(self) -> Dict[str, Union[str, int]]:
383+
def get_database_summary_report(self) -> DatabaseSummaryReport:
383384
"""
384385
Get a summary report for the database.
385386
@@ -404,7 +405,22 @@ def get_database_summary_report(self) -> Dict[str, Union[str, int]]:
404405
expected_result_code='Success',
405406
)
406407

407-
return dict(response.json())
408+
response_data = dict(response.json())
409+
database_summary_report = DatabaseSummaryReport(
410+
active_images=response_data['active_images'],
411+
current_month_recos=response_data['current_month_recos'],
412+
failed_images=response_data['failed_images'],
413+
inactive_images=response_data['inactive_images'],
414+
name=response_data['name'],
415+
previous_month_recos=response_data['previous_month_recos'],
416+
processing_images=response_data['processing_images'],
417+
reco_threshold=response_data['reco_threshold'],
418+
request_quota=response_data['request_quota'],
419+
request_usage=response_data['request_usage'],
420+
target_quota=response_data['target_quota'],
421+
total_recos=response_data['total_recos'],
422+
)
423+
return database_summary_report
408424

409425
def delete_target(self, target_id: str) -> None:
410426
"""

tests/test_vws.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from mock_vws import MockVWS
1313
from mock_vws.database import VuforiaDatabase
1414

15-
from vws import VWS, CloudRecoService
15+
from vws import VWS, CloudRecoService, DatabaseSummaryReport
1616
from vws.exceptions import TargetProcessingTimeout
1717

1818

@@ -218,23 +218,22 @@ def test_get_target(self, vws_client: VWS) -> None:
218218
Details of a database are returned by ``get_database_summary_report``.
219219
"""
220220
report = vws_client.get_database_summary_report()
221-
expected_keys = {
222-
'active_images',
223-
'current_month_recos',
224-
'failed_images',
225-
'inactive_images',
226-
'name',
227-
'previous_month_recos',
228-
'processing_images',
229-
'reco_threshold',
230-
'request_quota',
231-
'request_usage',
232-
'result_code',
233-
'target_quota',
234-
'total_recos',
235-
'transaction_id',
236-
}
237-
assert set(report.keys()) == expected_keys
221+
222+
expected_report = DatabaseSummaryReport(
223+
active_images=0,
224+
current_month_recos=0,
225+
failed_images=0,
226+
inactive_images=0,
227+
name=report.name,
228+
previous_month_recos=0,
229+
processing_images=0,
230+
reco_threshold=1000,
231+
request_quota=100000,
232+
request_usage=0,
233+
target_quota=1000,
234+
total_recos=0,
235+
)
236+
assert report == expected_report
238237

239238

240239
class TestGetTargetRecord:
@@ -342,7 +341,7 @@ def test_default_seconds_between_requests(
342341
# At the time of writing there is a bug which prevents request
343342
# usage from being tracked so we cannot track this.
344343
expected_requests = 0
345-
assert report['request_usage'] == expected_requests
344+
assert report.request_usage == expected_requests
346345

347346
def test_custom_seconds_between_requests(
348347
self,
@@ -390,7 +389,7 @@ def test_custom_seconds_between_requests(
390389
# At the time of writing there is a bug which prevents request
391390
# usage from being tracked so we cannot track this.
392391
expected_requests = 0
393-
assert report['request_usage'] == expected_requests
392+
assert report.request_usage == expected_requests
394393

395394
def test_custom_timeout(
396395
self,

0 commit comments

Comments
 (0)