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 pytest
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
from botocore.exceptions import ClientError
|
||||
import pytest
|
||||
|
||||
from moto import mock_forecast
|
||||
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"
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
response = client.create_dataset_group(DatasetGroupName=name, Domain=domain)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
response["DatasetGroupArn"].should.equal(
|
||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + name
|
||||
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||
assert response["DatasetGroupArn"] == (
|
||||
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:
|
||||
client.create_dataset_group(DatasetGroupName=name, Domain=invalid_domain)
|
||||
exc.value.response["Error"]["Code"].should.equal("ValidationException")
|
||||
exc.value.response["Error"]["Message"].should.equal(
|
||||
"1 validation error detected: Value '"
|
||||
+ invalid_domain
|
||||
+ "' at 'domain' failed to satisfy constraint: Member must satisfy enum value set ['INVENTORY_PLANNING', 'METRICS', 'RETAIL', 'EC2_CAPACITY', 'CUSTOM', 'WEB_TRAFFIC', 'WORK_FORCE']"
|
||||
assert exc.value.response["Error"]["Code"] == "ValidationException"
|
||||
assert exc.value.response["Error"]["Message"] == (
|
||||
f"1 validation error detected: Value '{invalid_domain}' at 'domain' "
|
||||
"failed to satisfy constraint: Member must satisfy enum value set "
|
||||
"['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:
|
||||
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
||||
exc.value.response["Error"]["Code"].should.equal("ValidationException")
|
||||
exc.value.response["Error"]["Message"].should.contain(
|
||||
"1 validation error detected: Value '"
|
||||
+ name
|
||||
+ "' at 'datasetGroupName' failed to satisfy constraint: Member must"
|
||||
)
|
||||
assert exc.value.response["Error"]["Code"] == "ValidationException"
|
||||
assert (
|
||||
f"1 validation error detected: Value '{name}' at 'datasetGroupName' "
|
||||
"failed to satisfy constraint: Member must"
|
||||
) in exc.value.response["Error"]["Message"]
|
||||
|
||||
|
||||
@mock_forecast
|
||||
@ -69,7 +69,7 @@ def test_forecast_dataset_group_create_duplicate_fails():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
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
|
||||
@ -77,7 +77,7 @@ def test_forecast_dataset_group_list_default_empty():
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
|
||||
resp = client.list_dataset_groups()
|
||||
resp["DatasetGroups"].should.equal([])
|
||||
assert resp["DatasetGroups"] == []
|
||||
|
||||
|
||||
@mock_forecast
|
||||
@ -88,8 +88,8 @@ def test_forecast_dataset_group_list_some():
|
||||
result = client.list_dataset_groups()
|
||||
|
||||
assert len(result["DatasetGroups"]) == 1
|
||||
result["DatasetGroups"][0]["DatasetGroupArn"].should.equal(
|
||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/hello"
|
||||
assert result["DatasetGroups"][0]["DatasetGroupArn"] == (
|
||||
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():
|
||||
dataset_group_name = "name"
|
||||
dataset_group_arn = (
|
||||
"arn:aws:forecast:"
|
||||
+ region
|
||||
+ ":"
|
||||
+ ACCOUNT_ID
|
||||
+ ":dataset-group/"
|
||||
+ dataset_group_name
|
||||
f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{dataset_group_name}"
|
||||
)
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
client.create_dataset_group(DatasetGroupName=dataset_group_name, Domain="CUSTOM")
|
||||
@ -112,15 +107,13 @@ def test_forecast_delete_dataset_group():
|
||||
@mock_forecast
|
||||
def test_forecast_delete_dataset_group_missing():
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
missing_dsg_arn = (
|
||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/missing"
|
||||
)
|
||||
missing_dsg_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/missing"
|
||||
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.delete_dataset_group(DatasetGroupArn=missing_dsg_arn)
|
||||
exc.value.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
exc.value.response["Error"]["Message"].should.equal(
|
||||
"No resource found " + missing_dsg_arn
|
||||
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||
assert (
|
||||
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():
|
||||
dataset_group_name = "name"
|
||||
dataset_group_arn = (
|
||||
"arn:aws:forecast:"
|
||||
+ region
|
||||
+ ":"
|
||||
+ ACCOUNT_ID
|
||||
+ ":dataset-group/"
|
||||
+ dataset_group_name
|
||||
f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{dataset_group_name}"
|
||||
)
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
client.create_dataset_group(DatasetGroupName=dataset_group_name, Domain="CUSTOM")
|
||||
@ -143,14 +131,13 @@ def test_forecast_update_dataset_arns_empty():
|
||||
@mock_forecast
|
||||
def test_forecast_update_dataset_group_not_found():
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
dataset_group_arn = (
|
||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + "test"
|
||||
)
|
||||
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/test"
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.update_dataset_group(DatasetGroupArn=dataset_group_arn, DatasetArns=[])
|
||||
exc.value.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
exc.value.response["Error"]["Message"].should.equal(
|
||||
"No resource found " + dataset_group_arn
|
||||
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||
assert (
|
||||
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():
|
||||
name = "test"
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
dataset_group_arn = (
|
||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + name
|
||||
)
|
||||
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{name}"
|
||||
client.create_dataset_group(DatasetGroupName=name, Domain="CUSTOM")
|
||||
result = client.describe_dataset_group(DatasetGroupArn=dataset_group_arn)
|
||||
assert result.get("DatasetGroupArn") == dataset_group_arn
|
||||
@ -171,28 +156,27 @@ def test_describe_dataset_group():
|
||||
@mock_forecast
|
||||
def test_describe_dataset_group_missing():
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
dataset_group_arn = (
|
||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/name"
|
||||
)
|
||||
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/name"
|
||||
with pytest.raises(ClientError) as exc:
|
||||
client.describe_dataset_group(DatasetGroupArn=dataset_group_arn)
|
||||
exc.value.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||
exc.value.response["Error"]["Message"].should.equal(
|
||||
"No resource found " + dataset_group_arn
|
||||
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||
assert (
|
||||
exc.value.response["Error"]["Message"]
|
||||
== f"No resource found {dataset_group_arn}"
|
||||
)
|
||||
|
||||
|
||||
@mock_forecast
|
||||
def test_create_dataset_group_missing_datasets():
|
||||
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:
|
||||
client.create_dataset_group(
|
||||
DatasetGroupName="name", Domain="CUSTOM", DatasetArns=[dataset_arn]
|
||||
)
|
||||
exc.value.response["Error"]["Code"].should.equal("InvalidInputException")
|
||||
exc.value.response["Error"]["Message"].should.equal(
|
||||
"Dataset arns: [" + dataset_arn + "] are not found"
|
||||
assert exc.value.response["Error"]["Code"] == "InvalidInputException"
|
||||
assert exc.value.response["Error"]["Message"] == (
|
||||
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():
|
||||
name = "test"
|
||||
client = boto3.client("forecast", region_name=region)
|
||||
dataset_group_arn = (
|
||||
"arn:aws:forecast:" + region + ":" + ACCOUNT_ID + ":dataset-group/" + name
|
||||
)
|
||||
dataset_group_arn = f"arn:aws:forecast:{region}:{ACCOUNT_ID}:dataset-group/{name}"
|
||||
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:
|
||||
client.update_dataset_group(
|
||||
DatasetGroupArn=dataset_group_arn, DatasetArns=[dataset_arn]
|
||||
)
|
||||
exc.value.response["Error"]["Code"].should.equal("InvalidInputException")
|
||||
exc.value.response["Error"]["Message"].should.equal(
|
||||
"Dataset arns: [" + dataset_arn + "] are not found"
|
||||
assert exc.value.response["Error"]["Code"] == "InvalidInputException"
|
||||
assert exc.value.response["Error"]["Message"] == (
|
||||
f"Dataset arns: [{dataset_arn}] are not found"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user