From c851bdc147f3b1da9c9b6db9cd170e14e205b13b Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Sun, 9 Jul 2023 17:01:29 +0000 Subject: [PATCH] Techdebt: Replace sure with regular assertions in Textract (#6500) --- tests/test_textract/test_server.py | 25 ++++++++++++------------- tests/test_textract/test_textract.py | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/tests/test_textract/test_server.py b/tests/test_textract/test_server.py index 70829023b..49bb37702 100644 --- a/tests/test_textract/test_server.py +++ b/tests/test_textract/test_server.py @@ -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." diff --git a/tests/test_textract/test_textract.py b/tests/test_textract/test_textract.py index 4aee9dd9c..a0254c58c 100644 --- a/tests/test_textract/test_textract.py +++ b/tests/test_textract/test_textract.py @@ -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