Techdebt: Replace sure with regular assertions in Personalize (#6676)
Co-authored-by: Karri Balk <kbalk@users.noreply.github.com>
This commit is contained in:
parent
0fa43c85b4
commit
35fc33c81c
@ -1,9 +1,11 @@
|
|||||||
"""Unit tests for personalize-supported APIs."""
|
"""Unit tests for personalize-supported APIs."""
|
||||||
import boto3
|
|
||||||
import json
|
import json
|
||||||
import sure # noqa # pylint: disable=unused-import
|
import re
|
||||||
import pytest
|
|
||||||
|
import boto3
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
|
import pytest
|
||||||
|
|
||||||
from moto import mock_personalize
|
from moto import mock_personalize
|
||||||
from moto.core import DEFAULT_ACCOUNT_ID
|
from moto.core import DEFAULT_ACCOUNT_ID
|
||||||
|
|
||||||
@ -29,8 +31,9 @@ def test_create_schema():
|
|||||||
create_schema_response = client.create_schema(
|
create_schema_response = client.create_schema(
|
||||||
name="personalize-demo-schema", schema=json.dumps(schema)
|
name="personalize-demo-schema", schema=json.dumps(schema)
|
||||||
)
|
)
|
||||||
create_schema_response.should.have.key("schemaArn").equals(
|
assert create_schema_response["schemaArn"] == (
|
||||||
f"arn:aws:personalize:ap-southeast-1:{DEFAULT_ACCOUNT_ID}:schema/personalize-demo-schema"
|
f"arn:aws:personalize:ap-southeast-1:{DEFAULT_ACCOUNT_ID}"
|
||||||
|
":schema/personalize-demo-schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ def test_delete_schema():
|
|||||||
]
|
]
|
||||||
client.delete_schema(schemaArn=schema_arn)
|
client.delete_schema(schemaArn=schema_arn)
|
||||||
|
|
||||||
client.list_schemas().should.have.key("schemas").equals([])
|
assert client.list_schemas()["schemas"] == []
|
||||||
|
|
||||||
|
|
||||||
@mock_personalize
|
@mock_personalize
|
||||||
@ -52,8 +55,8 @@ def test_delete_schema__unknown():
|
|||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.delete_schema(schemaArn=arn)
|
client.delete_schema(schemaArn=arn)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("ResourceNotFoundException")
|
assert err["Code"] == "ResourceNotFoundException"
|
||||||
err["Message"].should.equal(f"Resource Arn {arn} does not exist.")
|
assert err["Message"] == f"Resource Arn {arn} does not exist."
|
||||||
|
|
||||||
|
|
||||||
@mock_personalize
|
@mock_personalize
|
||||||
@ -61,14 +64,14 @@ def test_describe_schema():
|
|||||||
client = boto3.client("personalize", region_name="us-east-2")
|
client = boto3.client("personalize", region_name="us-east-2")
|
||||||
schema_arn = client.create_schema(name="myname", schema="sth")["schemaArn"]
|
schema_arn = client.create_schema(name="myname", schema="sth")["schemaArn"]
|
||||||
resp = client.describe_schema(schemaArn=schema_arn)
|
resp = client.describe_schema(schemaArn=schema_arn)
|
||||||
resp.should.have.key("schema")
|
assert "schema" in resp
|
||||||
schema = resp["schema"]
|
schema = resp["schema"]
|
||||||
|
|
||||||
schema.should.have.key("name").equals("myname")
|
assert schema["name"] == "myname"
|
||||||
schema.should.have.key("schemaArn").match("schema/myname")
|
assert re.search("schema/myname", schema["schemaArn"])
|
||||||
schema.should.have.key("schema").equals("sth")
|
assert schema["schema"] == "sth"
|
||||||
schema.should.have.key("creationDateTime")
|
assert "creationDateTime" in schema
|
||||||
schema.should.have.key("lastUpdatedDateTime")
|
assert "lastUpdatedDateTime" in schema
|
||||||
|
|
||||||
|
|
||||||
@mock_personalize
|
@mock_personalize
|
||||||
@ -78,10 +81,10 @@ def test_describe_schema__with_domain():
|
|||||||
"schemaArn"
|
"schemaArn"
|
||||||
]
|
]
|
||||||
resp = client.describe_schema(schemaArn=schema_arn)
|
resp = client.describe_schema(schemaArn=schema_arn)
|
||||||
resp.should.have.key("schema")
|
assert "schema" in resp
|
||||||
schema = resp["schema"]
|
schema = resp["schema"]
|
||||||
|
|
||||||
schema.should.have.key("domain").equals("ECOMMERCE")
|
assert schema["domain"] == "ECOMMERCE"
|
||||||
|
|
||||||
|
|
||||||
@mock_personalize
|
@mock_personalize
|
||||||
@ -93,8 +96,8 @@ def test_describe_schema__unknown():
|
|||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.describe_schema(schemaArn=arn)
|
client.describe_schema(schemaArn=arn)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("ResourceNotFoundException")
|
assert err["Code"] == "ResourceNotFoundException"
|
||||||
err["Message"].should.equal(f"Resource Arn {arn} does not exist.")
|
assert err["Message"] == f"Resource Arn {arn} does not exist."
|
||||||
|
|
||||||
|
|
||||||
@mock_personalize
|
@mock_personalize
|
||||||
@ -102,7 +105,7 @@ def test_list_schemas__initial():
|
|||||||
client = boto3.client("personalize", region_name="us-east-2")
|
client = boto3.client("personalize", region_name="us-east-2")
|
||||||
resp = client.list_schemas()
|
resp = client.list_schemas()
|
||||||
|
|
||||||
resp.should.have.key("schemas").equals([])
|
assert resp["schemas"] == []
|
||||||
|
|
||||||
|
|
||||||
@mock_personalize
|
@mock_personalize
|
||||||
@ -111,11 +114,11 @@ def test_list_schema():
|
|||||||
schema_arn = client.create_schema(name="myname", schema="sth")["schemaArn"]
|
schema_arn = client.create_schema(name="myname", schema="sth")["schemaArn"]
|
||||||
|
|
||||||
resp = client.list_schemas()
|
resp = client.list_schemas()
|
||||||
resp.should.have.key("schemas").length_of(1)
|
assert len(resp["schemas"]) == 1
|
||||||
schema = resp["schemas"][0]
|
schema = resp["schemas"][0]
|
||||||
|
|
||||||
schema.should.have.key("name").equals("myname")
|
assert schema["name"] == "myname"
|
||||||
schema.should.have.key("schemaArn").equals(schema_arn)
|
assert schema["schemaArn"] == schema_arn
|
||||||
schema.shouldnt.have.key("schema")
|
assert "schema" not in schema
|
||||||
schema.should.have.key("creationDateTime")
|
assert "creationDateTime" in schema
|
||||||
schema.should.have.key("lastUpdatedDateTime")
|
assert "lastUpdatedDateTime" in schema
|
||||||
|
Loading…
Reference in New Issue
Block a user