Techdebt: MyPy Rekognition (#6219)
This commit is contained in:
parent
bdcc6f3335
commit
94db0c6fa4
@ -1 +0,0 @@
|
|||||||
"""Exceptions raised by the rekognition service."""
|
|
@ -1,6 +1,7 @@
|
|||||||
"""RekognitionBackend class with methods for supported APIs."""
|
"""RekognitionBackend class with methods for supported APIs."""
|
||||||
|
|
||||||
import string
|
import string
|
||||||
|
from typing import Any, Dict, List, Tuple
|
||||||
|
|
||||||
from moto.core import BaseBackend, BackendDict
|
from moto.core import BaseBackend, BackendDict
|
||||||
from moto.moto_api._internal import mock_random as random
|
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):
|
class RekognitionBackend(BaseBackend):
|
||||||
"""Implementation of Rekognition APIs."""
|
"""Implementation of Rekognition APIs."""
|
||||||
|
|
||||||
def start_face_search(self):
|
def start_face_search(self) -> str:
|
||||||
return self._job_id()
|
return self._job_id()
|
||||||
|
|
||||||
def start_text_detection(self):
|
def start_text_detection(self) -> str:
|
||||||
return self._job_id()
|
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.
|
This returns hardcoded values and none of the parameters are taken into account.
|
||||||
"""
|
"""
|
||||||
@ -28,7 +31,9 @@ class RekognitionBackend(BaseBackend):
|
|||||||
self._text_model_version(),
|
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.
|
This returns hardcoded values and none of the parameters are taken into account.
|
||||||
"""
|
"""
|
||||||
@ -43,24 +48,24 @@ class RekognitionBackend(BaseBackend):
|
|||||||
|
|
||||||
# private
|
# private
|
||||||
|
|
||||||
def _job_id(self):
|
def _job_id(self) -> str:
|
||||||
return "".join(
|
return "".join(
|
||||||
random.choice(string.ascii_uppercase + string.digits) for _ in range(64)
|
random.choice(string.ascii_uppercase + string.digits) for _ in range(64)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _job_status(self):
|
def _job_status(self) -> str:
|
||||||
return "SUCCEEDED"
|
return "SUCCEEDED"
|
||||||
|
|
||||||
def _next_token(self):
|
def _next_token(self) -> str:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _status_message(self):
|
def _status_message(self) -> str:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _text_model_version(self):
|
def _text_model_version(self) -> str:
|
||||||
return "3.1"
|
return "3.1"
|
||||||
|
|
||||||
def _video_metadata(self):
|
def _video_metadata(self) -> Dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
"Codec": "h264",
|
"Codec": "h264",
|
||||||
"DurationMillis": 15020,
|
"DurationMillis": 15020,
|
||||||
@ -71,7 +76,7 @@ class RekognitionBackend(BaseBackend):
|
|||||||
"ColorRange": "LIMITED",
|
"ColorRange": "LIMITED",
|
||||||
}
|
}
|
||||||
|
|
||||||
def _persons(self):
|
def _persons(self) -> List[Dict[str, Any]]:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"Timestamp": 0,
|
"Timestamp": 0,
|
||||||
@ -188,7 +193,7 @@ class RekognitionBackend(BaseBackend):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
def _text_detections(self):
|
def _text_detections(self) -> List[Dict[str, Any]]:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"Timestamp": 0,
|
"Timestamp": 0,
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
"""Handles incoming rekognition requests, invokes methods, returns responses."""
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from moto.core.common_types import TYPE_RESPONSE
|
||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
from .models import rekognition_backends
|
from .models import rekognition_backends, RekognitionBackend
|
||||||
|
|
||||||
|
|
||||||
class RekognitionResponse(BaseResponse):
|
class RekognitionResponse(BaseResponse):
|
||||||
"""Handler for Rekognition requests and responses."""
|
"""Handler for Rekognition requests and responses."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
super().__init__(service_name="rekognition")
|
super().__init__(service_name="rekognition")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rekognition_backend(self):
|
def rekognition_backend(self) -> RekognitionBackend:
|
||||||
"""Return backend instance specific for this region."""
|
|
||||||
return rekognition_backends[self.current_account][self.region]
|
return rekognition_backends[self.current_account][self.region]
|
||||||
|
|
||||||
def get_face_search(self):
|
def get_face_search(self) -> str:
|
||||||
(
|
(
|
||||||
job_status,
|
job_status,
|
||||||
status_message,
|
status_message,
|
||||||
@ -37,7 +36,7 @@ class RekognitionResponse(BaseResponse):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_text_detection(self):
|
def get_text_detection(self) -> str:
|
||||||
(
|
(
|
||||||
job_status,
|
job_status,
|
||||||
status_message,
|
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"}
|
headers = {"Content-Type": "application/x-amz-json-1.1"}
|
||||||
job_id = self.rekognition_backend.start_face_search()
|
job_id = self.rekognition_backend.start_face_search()
|
||||||
response = ('{"JobId":"' + job_id + '"}').encode()
|
response = ('{"JobId":"' + job_id + '"}').encode()
|
||||||
|
|
||||||
return 200, headers, response
|
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"}
|
headers = {"Content-Type": "application/x-amz-json-1.1"}
|
||||||
job_id = self.rekognition_backend.start_text_detection()
|
job_id = self.rekognition_backend.start_text_detection()
|
||||||
response = ('{"JobId":"' + job_id + '"}').encode()
|
response = ('{"JobId":"' + job_id + '"}').encode()
|
||||||
|
|
||||||
return 200, headers, response
|
return 200, headers, response
|
||||||
|
|
||||||
|
|
||||||
# add templates from here
|
|
||||||
|
@ -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
|
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]
|
[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_column_numbers=True
|
||||||
show_error_codes = True
|
show_error_codes = True
|
||||||
disable_error_code=abstract
|
disable_error_code=abstract
|
||||||
|
Loading…
Reference in New Issue
Block a user