Techdebt: Replace sure with regular assertions in Forecast (#6667)
This commit is contained in:
parent
1f189237f4
commit
b92b2f10c3
@ -1,7 +1,7 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import pytest
|
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
|
import pytest
|
||||||
|
|
||||||
from moto import mock_forecast
|
from moto import mock_forecast
|
||||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||||
|
|
||||||
@ -24,9 +24,9 @@ def test_forecast_dataset_group_create(domain):
|
|||||||
name = "example_dataset_group"
|
name = "example_dataset_group"
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
response = client.create_dataset_group(DatasetGroupName=name, Domain=domain)
|
response = client.create_dataset_group(DatasetGroupName=name, Domain=domain)
|
||||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||||
response["DatasetGroupArn"].should.equal(
|
assert response["DatasetGroupArn"] == (
|
||||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + name
|
f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -38,11 +38,12 @@ def test_forecast_dataset_group_create_invalid_domain():
|
|||||||
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.create_dataset_group(DatasetGroupName=name, Domain=invalid_domain)
|
client.create_dataset_group(DatasetGroupName=name, Domain=invalid_domain)
|
||||||
exc.value.response["Error"]["Code"].should.equal("ValidationException")
|
assert exc.value.response["Error"]["Code"] == "ValidationException"
|
||||||
exc.value.response["Error"]["Message"].should.equal(
|
assert exc.value.response["Error"]["Message"] == (
|
||||||
"1 validation error detected: Value '"
|
f"1 validation error detected: Value '{invalid_domain}' at 'domain' "
|
||||||
+ invalid_domain
|
"failed to satisfy constraint: Member must satisfy enum value set "
|
||||||
+ "' at 'domain' failed to satisfy constraint: Member must satisfy enum value set ['INVENTORY_PLANNING', 'METRICS', 'RETAIL', 'EC2_CAPACITY', 'CUSTOM', 'WEB_TRAFFIC', 'WORK_FORCE']"
|
"['INVENTORY_PLANNING', 'METRICS', 'RETAIL', 'EC2_CAPACITY', "
|
||||||
|
"'CUSTOM', 'WEB_TRAFFIC', 'WORK_FORCE']"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -53,12 +54,11 @@ def test_forecast_dataset_group_create_invalid_name(name):
|
|||||||
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
||||||
exc.value.response["Error"]["Code"].should.equal("ValidationException")
|
assert exc.value.response["Error"]["Code"] == "ValidationException"
|
||||||
exc.value.response["Error"]["Message"].should.contain(
|
assert (
|
||||||
"1 validation error detected: Value '"
|
f"1 validation error detected: Value '{name}' at 'datasetGroupName' "
|
||||||
+ name
|
"failed to satisfy constraint: Member must"
|
||||||
+ "' at 'datasetGroupName' failed to satisfy constraint: Member must"
|
) in exc.value.response["Error"]["Message"]
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_forecast
|
@mock_forecast
|
||||||
@ -69,7 +69,7 @@ def test_forecast_dataset_group_create_duplicate_fails():
|
|||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.create_dataset_group(DatasetGroupName="name", Domain="RETAIL")
|
client.create_dataset_group(DatasetGroupName="name", Domain="RETAIL")
|
||||||
|
|
||||||
exc.value.response["Error"]["Code"].should.equal("ResourceAlreadyExistsException")
|
assert exc.value.response["Error"]["Code"] == "ResourceAlreadyExistsException"
|
||||||
|
|
||||||
|
|
||||||
@mock_forecast
|
@mock_forecast
|
||||||
@ -77,7 +77,7 @@ def test_forecast_dataset_group_list_default_empty():
|
|||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
|
|
||||||
resp = client.list_dataset_groups()
|
resp = client.list_dataset_groups()
|
||||||
resp["DatasetGroups"].should.equal([])
|
assert resp["DatasetGroups"] == []
|
||||||
|
|
||||||
|
|
||||||
@mock_forecast
|
@mock_forecast
|
||||||
@ -88,8 +88,8 @@ def test_forecast_dataset_group_list_some():
|
|||||||
result = client.list_dataset_groups()
|
result = client.list_dataset_groups()
|
||||||
|
|
||||||
assert len(result["DatasetGroups"]) == 1
|
assert len(result["DatasetGroups"]) == 1
|
||||||
result["DatasetGroups"][0]["DatasetGroupArn"].should.equal(
|
assert result["DatasetGroups"][0]["DatasetGroupArn"] == (
|
||||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/hello"
|
f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/hello"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -97,12 +97,7 @@ def test_forecast_dataset_group_list_some():
|
|||||||
def test_forecast_delete_dataset_group():
|
def test_forecast_delete_dataset_group():
|
||||||
dataset_group_name = "name"
|
dataset_group_name = "name"
|
||||||
dataset_group_arn = (
|
dataset_group_arn = (
|
||||||
"arn:aws:forecast:"
|
f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{dataset_group_name}"
|
||||||
+ region
|
|
||||||
+ ":"
|
|
||||||
+ ACCOUNT_ID
|
|
||||||
+ ":dataset-group/"
|
|
||||||
+ dataset_group_name
|
|
||||||
)
|
)
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
client.create_dataset_group(DatasetGroupName=dataset_group_name, Domain="CUSTOM")
|
client.create_dataset_group(DatasetGroupName=dataset_group_name, Domain="CUSTOM")
|
||||||
@ -112,15 +107,13 @@ def test_forecast_delete_dataset_group():
|
|||||||
@mock_forecast
|
@mock_forecast
|
||||||
def test_forecast_delete_dataset_group_missing():
|
def test_forecast_delete_dataset_group_missing():
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
missing_dsg_arn = (
|
missing_dsg_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/missing"
|
||||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/missing"
|
|
||||||
)
|
|
||||||
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.delete_dataset_group(DatasetGroupArn=missing_dsg_arn)
|
client.delete_dataset_group(DatasetGroupArn=missing_dsg_arn)
|
||||||
exc.value.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||||
exc.value.response["Error"]["Message"].should.equal(
|
assert (
|
||||||
"No resource found " + missing_dsg_arn
|
exc.value.response["Error"]["Message"] == f"No resource found {missing_dsg_arn}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -128,12 +121,7 @@ def test_forecast_delete_dataset_group_missing():
|
|||||||
def test_forecast_update_dataset_arns_empty():
|
def test_forecast_update_dataset_arns_empty():
|
||||||
dataset_group_name = "name"
|
dataset_group_name = "name"
|
||||||
dataset_group_arn = (
|
dataset_group_arn = (
|
||||||
"arn:aws:forecast:"
|
f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{dataset_group_name}"
|
||||||
+ region
|
|
||||||
+ ":"
|
|
||||||
+ ACCOUNT_ID
|
|
||||||
+ ":dataset-group/"
|
|
||||||
+ dataset_group_name
|
|
||||||
)
|
)
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
client.create_dataset_group(DatasetGroupName=dataset_group_name, Domain="CUSTOM")
|
client.create_dataset_group(DatasetGroupName=dataset_group_name, Domain="CUSTOM")
|
||||||
@ -143,14 +131,13 @@ def test_forecast_update_dataset_arns_empty():
|
|||||||
@mock_forecast
|
@mock_forecast
|
||||||
def test_forecast_update_dataset_group_not_found():
|
def test_forecast_update_dataset_group_not_found():
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
dataset_group_arn = (
|
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/test"
|
||||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + "test"
|
|
||||||
)
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.update_dataset_group(DatasetGroupArn=dataset_group_arn, DatasetArns=[])
|
client.update_dataset_group(DatasetGroupArn=dataset_group_arn, DatasetArns=[])
|
||||||
exc.value.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||||
exc.value.response["Error"]["Message"].should.equal(
|
assert (
|
||||||
"No resource found " + dataset_group_arn
|
exc.value.response["Error"]["Message"]
|
||||||
|
== f"No resource found {dataset_group_arn}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -158,9 +145,7 @@ def test_forecast_update_dataset_group_not_found():
|
|||||||
def test_describe_dataset_group():
|
def test_describe_dataset_group():
|
||||||
name = "test"
|
name = "test"
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
dataset_group_arn = (
|
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{name}"
|
||||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + name
|
|
||||||
)
|
|
||||||
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
||||||
result = client.describe_dataset_group(DatasetGroupArn=dataset_group_arn)
|
result = client.describe_dataset_group(DatasetGroupArn=dataset_group_arn)
|
||||||
assert result.get("DatasetGroupArn") == dataset_group_arn
|
assert result.get("DatasetGroupArn") == dataset_group_arn
|
||||||
@ -171,28 +156,27 @@ def test_describe_dataset_group():
|
|||||||
@mock_forecast
|
@mock_forecast
|
||||||
def test_describe_dataset_group_missing():
|
def test_describe_dataset_group_missing():
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
dataset_group_arn = (
|
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/name"
|
||||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/name"
|
|
||||||
)
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.describe_dataset_group(DatasetGroupArn=dataset_group_arn)
|
client.describe_dataset_group(DatasetGroupArn=dataset_group_arn)
|
||||||
exc.value.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||||
exc.value.response["Error"]["Message"].should.equal(
|
assert (
|
||||||
"No resource found " + dataset_group_arn
|
exc.value.response["Error"]["Message"]
|
||||||
|
== f"No resource found {dataset_group_arn}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_forecast
|
@mock_forecast
|
||||||
def test_create_dataset_group_missing_datasets():
|
def test_create_dataset_group_missing_datasets():
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
dataset_arn = "arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset/name"
|
dataset_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/name"
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.create_dataset_group(
|
client.create_dataset_group(
|
||||||
DatasetGroupName="name", Domain="CUSTOM", DatasetArns=[dataset_arn]
|
DatasetGroupName="name", Domain="CUSTOM", DatasetArns=[dataset_arn]
|
||||||
)
|
)
|
||||||
exc.value.response["Error"]["Code"].should.equal("InvalidInputException")
|
assert exc.value.response["Error"]["Code"] == "InvalidInputException"
|
||||||
exc.value.response["Error"]["Message"].should.equal(
|
assert exc.value.response["Error"]["Message"] == (
|
||||||
"Dataset arns: [" + dataset_arn + "] are not found"
|
f"Dataset arns: [{dataset_arn}] are not found"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -200,17 +184,15 @@ def test_create_dataset_group_missing_datasets():
|
|||||||
def test_update_dataset_group_missing_datasets():
|
def test_update_dataset_group_missing_datasets():
|
||||||
name = "test"
|
name = "test"
|
||||||
client = boto3.client("forecast", region_name=region)
|
client = boto3.client("forecast", region_name=region)
|
||||||
dataset_group_arn = (
|
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{name}"
|
||||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + name
|
|
||||||
)
|
|
||||||
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
||||||
dataset_arn = "arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset/name"
|
dataset_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset/name"
|
||||||
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.update_dataset_group(
|
client.update_dataset_group(
|
||||||
DatasetGroupArn=dataset_group_arn, DatasetArns=[dataset_arn]
|
DatasetGroupArn=dataset_group_arn, DatasetArns=[dataset_arn]
|
||||||
)
|
)
|
||||||
exc.value.response["Error"]["Code"].should.equal("InvalidInputException")
|
assert exc.value.response["Error"]["Code"] == "InvalidInputException"
|
||||||
exc.value.response["Error"]["Message"].should.equal(
|
assert exc.value.response["Error"]["Message"] == (
|
||||||
"Dataset arns: [" + dataset_arn + "] are not found"
|
f"Dataset arns: [{dataset_arn}] are not found"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user