@@ -83,11 +83,11 @@ def _month_offset_from_now(*, months: int) -> str:
8383
8484
8585@beartype
86- def _request_reco_counts_report (
86+ def _request_reco_counts_report_json (
8787 * ,
8888 vuforia_database : CloudDatabase ,
8989 database_id : str ,
90- month : str | int ,
90+ request_json : object ,
9191) -> requests .Response :
9292 """Request a reco counts report and return the response.
9393
@@ -96,7 +96,7 @@ def _request_reco_counts_report(
9696 """
9797 request_path = f"/imagetargets/databases/{ database_id } /reports/recoCounts"
9898 content_type = "application/json"
99- content = json .dumps (obj = { "month" : month } ).encode (encoding = "utf-8" )
99+ content = json .dumps (obj = request_json ).encode (encoding = "utf-8" )
100100 date = rfc_1123_date ()
101101 authorization_string = authorization_header (
102102 access_key = vuforia_database .server_access_key ,
@@ -121,6 +121,21 @@ def _request_reco_counts_report(
121121 )
122122
123123
124+ @beartype
125+ def _request_reco_counts_report (
126+ * ,
127+ vuforia_database : CloudDatabase ,
128+ database_id : str ,
129+ month : str | int ,
130+ ) -> requests .Response :
131+ """Request a reco counts report for one month."""
132+ return _request_reco_counts_report_json (
133+ vuforia_database = vuforia_database ,
134+ database_id = database_id ,
135+ request_json = {"month" : month },
136+ )
137+
138+
124139@beartype
125140def _presigned_url (* , vuforia_database : CloudDatabase , month : str ) -> str :
126141 """Request a report for the given month and return its download
@@ -386,6 +401,22 @@ def test_malformed_month(
386401 response_json = json .loads (s = response .text )
387402 assert response_json ["result_code" ] == ResultCodes .FAIL .value
388403
404+ @staticmethod
405+ def test_body_is_not_an_object (
406+ * ,
407+ vuforia_database : CloudDatabase ,
408+ ) -> None :
409+ """The request body must be a JSON object."""
410+ response = _request_reco_counts_report_json (
411+ vuforia_database = vuforia_database ,
412+ database_id = vuforia_database .database_id ,
413+ request_json = [],
414+ )
415+
416+ assert response .status_code == HTTPStatus .BAD_REQUEST
417+ response_json = json .loads (s = response .text )
418+ assert response_json ["result_code" ] == ResultCodes .FAIL .value
419+
389420 @staticmethod
390421 def test_unknown_database_id (* , vuforia_database : CloudDatabase ) -> None :
391422 """The path must name the database which the request's server
0 commit comments