Techdebt: MyPy Rekognition (#6219)

This commit is contained in:
Bert Blommers 2023-04-17 18:01:08 +00:00 committed by GitHub
parent bdcc6f3335
commit 94db0c6fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 26 deletions

View File

@ -1 +0,0 @@
"""Exceptions raised by the rekognition service."""

View File

@ -1,6 +1,7 @@
"""RekognitionBackend class with methods for supported APIs."""
import string
from typing import Any, Dict, List, Tuple
from moto.core import BaseBackend, BackendDict
from moto.moto_api._internal import mock_random as random
@ -9,13 +10,15 @@ from moto.moto_api._internal import mock_random as random
class RekognitionBackend(BaseBackend):
"""Implementation of Rekognition APIs."""
def start_face_search(self):
def start_face_search(self) -> str:
return self._job_id()
def start_text_detection(self):
def start_text_detection(self) -> str:
return self._job_id()
def get_face_search(self):
def get_face_search(
self,
) -> Tuple[str, str, Dict[str, Any], List[Dict[str, Any]], str, str]:
"""
This returns hardcoded values and none of the parameters are taken into account.
"""
@ -28,7 +31,9 @@ class RekognitionBackend(BaseBackend):
self._text_model_version(),
)
def get_text_detection(self):
def get_text_detection(
self,
) -> Tuple[str, str, Dict[str, Any], List[Dict[str, Any]], str, str]:
"""
This returns hardcoded values and none of the parameters are taken into account.
"""
@ -43,24 +48,24 @@ class RekognitionBackend(BaseBackend):
# private
def _job_id(self):
def _job_id(self) -> str:
return "".join(
random.choice(string.ascii_uppercase + string.digits) for _ in range(64)
)
def _job_status(self):
def _job_status(self) -> str:
return "SUCCEEDED"
def _next_token(self):
def _next_token(self) -> str:
return ""
def _status_message(self):
def _status_message(self) -> str:
return ""
def _text_model_version(self):
def _text_model_version(self) -> str:
return "3.1"
def _video_metadata(self):
def _video_metadata(self) -> Dict[str, Any]:
return {
"Codec": "h264",
"DurationMillis": 15020,
@ -71,7 +76,7 @@ class RekognitionBackend(BaseBackend):
"ColorRange": "LIMITED",
}
def _persons(self):
def _persons(self) -> List[Dict[str, Any]]:
return [
{
"Timestamp": 0,
@ -188,7 +193,7 @@ class RekognitionBackend(BaseBackend):
}
]
def _text_detections(self):
def _text_detections(self) -> List[Dict[str, Any]]:
return [
{
"Timestamp": 0,

View File

@ -1,22 +1,21 @@
"""Handles incoming rekognition requests, invokes methods, returns responses."""
import json
from moto.core.common_types import TYPE_RESPONSE
from moto.core.responses import BaseResponse
from .models import rekognition_backends
from .models import rekognition_backends, RekognitionBackend
class RekognitionResponse(BaseResponse):
"""Handler for Rekognition requests and responses."""
def __init__(self):
def __init__(self) -> None:
super().__init__(service_name="rekognition")
@property
def rekognition_backend(self):
"""Return backend instance specific for this region."""
def rekognition_backend(self) -> RekognitionBackend:
return rekognition_backends[self.current_account][self.region]
def get_face_search(self):
def get_face_search(self) -> str:
(
job_status,
status_message,
@ -37,7 +36,7 @@ class RekognitionResponse(BaseResponse):
)
)
def get_text_detection(self):
def get_text_detection(self) -> str:
(
job_status,
status_message,
@ -58,19 +57,16 @@ class RekognitionResponse(BaseResponse):
)
)
def start_face_search(self):
def start_face_search(self) -> TYPE_RESPONSE:
headers = {"Content-Type": "application/x-amz-json-1.1"}
job_id = self.rekognition_backend.start_face_search()
response = ('{"JobId":"' + job_id + '"}').encode()
return 200, headers, response
def start_text_detection(self):
def start_text_detection(self) -> TYPE_RESPONSE:
headers = {"Content-Type": "application/x-amz-json-1.1"}
job_id = self.rekognition_backend.start_text_detection()
response = ('{"JobId":"' + job_id + '"}').encode()
return 200, headers, response
# add templates from here

View File

@ -239,7 +239,7 @@ disable = W,C,R,E
enable = anomalous-backslash-in-string, arguments-renamed, dangerous-default-value, deprecated-module, function-redefined, import-self, redefined-builtin, redefined-outer-name, reimported, pointless-statement, super-with-arguments, unused-argument, unused-import, unused-variable, useless-else-on-loop, wildcard-import
[mypy]
files= moto/a*,moto/b*,moto/c*,moto/d*,moto/e*,moto/f*,moto/g*,moto/i*,moto/k*,moto/l*,moto/m*,moto/n*,moto/o*,moto/p*,moto/q*,moto/ram,moto/rds*,moto/redshift*,moto/scheduler
files= moto/a*,moto/b*,moto/c*,moto/d*,moto/e*,moto/f*,moto/g*,moto/i*,moto/k*,moto/l*,moto/m*,moto/n*,moto/o*,moto/p*,moto/q*,moto/ram,moto/rds*,moto/redshift*,moto/rekognition,moto/scheduler
show_column_numbers=True
show_error_codes = True
disable_error_code=abstract