Techdebt: Replace sure with regular assertions in Textract (#6500)

This commit is contained in:
Bert Blommers 2023-07-09 17:01:29 +00:00 committed by GitHub
parent cd906cea56
commit c851bdc147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 24 deletions

View File

@ -1,6 +1,4 @@
"""Test different server responses."""
import sure # noqa # pylint: disable=unused-import
import json
import moto.server as server
from moto import mock_textract
@ -20,8 +18,8 @@ def test_textract_start_text_detection():
resp = test_client.post("/", headers=headers, json=request_body)
data = json.loads(resp.data.decode("utf-8"))
resp.status_code.should.equal(200)
data["JobId"].should.be.an(str)
assert resp.status_code == 200
assert isinstance(data["JobId"], str)
@mock_textract
@ -32,10 +30,11 @@ def test_textract_start_text_detection_without_document_location():
headers = {"X-Amz-Target": "X-Amz-Target=Textract.StartDocumentTextDetection"}
resp = test_client.post("/", headers=headers, json={})
data = json.loads(resp.data.decode("utf-8"))
resp.status_code.should.equal(400)
data["__type"].should.equal("InvalidParameterException")
data["message"].should.equal(
"An input parameter violated a constraint. For example, in synchronous operations, an InvalidParameterException exception occurs when neither of the S3Object or Bytes values are supplied in the Document request parameter. Validate your parameter before calling the API operation again."
assert resp.status_code == 400
assert data["__type"] == "InvalidParameterException"
assert (
data["message"]
== "An input parameter violated a constraint. For example, in synchronous operations, an InvalidParameterException exception occurs when neither of the S3Object or Bytes values are supplied in the Document request parameter. Validate your parameter before calling the API operation again."
)
@ -59,9 +58,9 @@ def test_textract_get_text_detection():
"JobId": start_job_data["JobId"],
}
resp = test_client.post("/", headers=headers, json=request_body)
resp.status_code.should.equal(200)
assert resp.status_code == 200
data = json.loads(resp.data.decode("utf-8"))
data["JobStatus"].should.equal("SUCCEEDED")
assert data["JobStatus"] == "SUCCEEDED"
@mock_textract
@ -74,7 +73,7 @@ def test_textract_get_text_detection_without_job_id():
"JobId": "invalid_job_id",
}
resp = test_client.post("/", headers=headers, json=request_body)
resp.status_code.should.equal(400)
assert resp.status_code == 400
data = json.loads(resp.data.decode("utf-8"))
data["__type"].should.equal("InvalidJobIdException")
data["message"].should.equal("An invalid job identifier was passed.")
assert data["__type"] == "InvalidJobIdException"
assert data["message"] == "An invalid job identifier was passed."

View File

@ -42,15 +42,15 @@ def test_get_document_text_detection():
resp = client.get_document_text_detection(JobId=job["JobId"])
resp["Blocks"][0]["Text"].should.equal("This is a test")
resp["Blocks"][0]["Id"].should.equal("0")
resp["Blocks"][0]["Confidence"].should.equal("100")
resp["Blocks"][0]["Geometry"]["BoundingBox"]["Width"].should.equal("0.5")
resp["Blocks"][0]["Geometry"]["BoundingBox"]["Height"].should.equal("0.5")
resp["Blocks"][0]["Geometry"]["BoundingBox"]["Left"].should.equal("0.5")
resp["Blocks"][0]["Geometry"]["BoundingBox"]["Top"].should.equal("0.5")
resp["JobStatus"].should.equal("SUCCEEDED")
resp["DocumentMetadata"]["Pages"].should.equal(TextractBackend.PAGES)
assert resp["Blocks"][0]["Text"] == "This is a test"
assert resp["Blocks"][0]["Id"] == "0"
assert resp["Blocks"][0]["Confidence"] == "100"
assert resp["Blocks"][0]["Geometry"]["BoundingBox"]["Width"] == "0.5"
assert resp["Blocks"][0]["Geometry"]["BoundingBox"]["Height"] == "0.5"
assert resp["Blocks"][0]["Geometry"]["BoundingBox"]["Left"] == "0.5"
assert resp["Blocks"][0]["Geometry"]["BoundingBox"]["Top"] == "0.5"
assert resp["JobStatus"] == "SUCCEEDED"
assert resp["DocumentMetadata"]["Pages"] == TextractBackend.PAGES
@mock_textract
@ -60,7 +60,7 @@ def test_start_document_text_detection():
DocumentLocation={"S3Object": {"Bucket": "bucket", "Name": "name"}}
)
resp.should.have.key("JobId")
assert "JobId" in resp
@mock_textract
@ -69,7 +69,7 @@ def test_get_document_text_detection_without_job_id():
with pytest.raises(ClientError) as e:
client.get_document_text_detection(JobId="Invalid Job Id")
e.value.response["Error"]["Code"].should.equal("InvalidJobIdException")
assert e.value.response["Error"]["Code"] == "InvalidJobIdException"
@mock_textract