Techdebt: Replace sure with regular asserts in Budgets (#6457)
This commit is contained in:
parent
f1c72814d8
commit
7cdf456e37
@ -2,8 +2,6 @@ import boto3
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
from datetime import datetime
|
|
||||||
from moto import mock_budgets
|
from moto import mock_budgets
|
||||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ def test_create_and_describe_budget_minimal_params():
|
|||||||
"BudgetType": "COST",
|
"BudgetType": "COST",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
assert resp["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||||
|
|
||||||
try:
|
try:
|
||||||
budget = client.describe_budget(AccountId=ACCOUNT_ID, BudgetName="testbudget")[
|
budget = client.describe_budget(AccountId=ACCOUNT_ID, BudgetName="testbudget")[
|
||||||
@ -28,42 +26,41 @@ def test_create_and_describe_budget_minimal_params():
|
|||||||
]
|
]
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
pytest.skip("This test requires 64-bit time_t")
|
pytest.skip("This test requires 64-bit time_t")
|
||||||
budget.should.have.key("BudgetLimit")
|
assert "BudgetLimit" in budget
|
||||||
budget["BudgetLimit"].should.have.key("Amount")
|
assert "Amount" in budget["BudgetLimit"]
|
||||||
budget["BudgetLimit"]["Amount"].should.equal("10")
|
assert budget["BudgetLimit"]["Amount"] == "10"
|
||||||
budget["BudgetLimit"].should.have.key("Unit")
|
assert "Unit" in budget["BudgetLimit"]
|
||||||
budget["BudgetLimit"]["Unit"].should.equal("USD")
|
assert budget["BudgetLimit"]["Unit"] == "USD"
|
||||||
budget.should.have.key("BudgetName").equals("testbudget")
|
assert budget["BudgetName"] == "testbudget"
|
||||||
budget.should.have.key("TimeUnit").equals("DAILY")
|
assert budget["TimeUnit"] == "DAILY"
|
||||||
budget.should.have.key("BudgetType").equals("COST")
|
assert budget["BudgetType"] == "COST"
|
||||||
budget.should.have.key("CalculatedSpend")
|
assert "CalculatedSpend" in budget
|
||||||
budget["CalculatedSpend"].should.have.key("ActualSpend")
|
assert "ActualSpend" in budget["CalculatedSpend"]
|
||||||
budget["CalculatedSpend"]["ActualSpend"].should.equal(
|
assert budget["CalculatedSpend"]["ActualSpend"] == {"Amount": "0", "Unit": "USD"}
|
||||||
{"Amount": "0", "Unit": "USD"}
|
assert "ForecastedSpend" in budget["CalculatedSpend"]
|
||||||
)
|
assert budget["CalculatedSpend"]["ForecastedSpend"] == {
|
||||||
budget["CalculatedSpend"].should.have.key("ForecastedSpend")
|
"Amount": "0",
|
||||||
budget["CalculatedSpend"]["ForecastedSpend"].should.equal(
|
"Unit": "USD",
|
||||||
{"Amount": "0", "Unit": "USD"}
|
}
|
||||||
)
|
assert "CostTypes" in budget
|
||||||
budget.should.have.key("CostTypes")
|
assert budget["CostTypes"]["IncludeCredit"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeCredit").equals(True)
|
assert budget["CostTypes"]["IncludeDiscount"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeDiscount").equals(True)
|
assert budget["CostTypes"]["IncludeOtherSubscription"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeOtherSubscription").equals(True)
|
assert budget["CostTypes"]["IncludeRecurring"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeRecurring").equals(True)
|
assert budget["CostTypes"]["IncludeRefund"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeRefund").equals(True)
|
assert budget["CostTypes"]["IncludeSubscription"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeSubscription").equals(True)
|
assert budget["CostTypes"]["IncludeSupport"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeSupport").equals(True)
|
assert budget["CostTypes"]["IncludeTax"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeTax").equals(True)
|
assert budget["CostTypes"]["IncludeUpfront"] is True
|
||||||
budget["CostTypes"].should.have.key("IncludeUpfront").equals(True)
|
assert budget["CostTypes"]["UseAmortized"] is False
|
||||||
budget["CostTypes"].should.have.key("UseAmortized").equals(False)
|
assert budget["CostTypes"]["UseBlended"] is False
|
||||||
budget["CostTypes"].should.have.key("UseBlended").equals(False)
|
assert "LastUpdatedTime" in budget
|
||||||
budget.should.have.key("LastUpdatedTime").should.be.a(datetime)
|
assert "TimePeriod" in budget
|
||||||
budget.should.have.key("TimePeriod")
|
assert "Start" in budget["TimePeriod"]
|
||||||
budget["TimePeriod"].should.have.key("Start")
|
assert budget["TimePeriod"]["Start"]
|
||||||
budget["TimePeriod"]["Start"].should.be.a(datetime)
|
assert "End" in budget["TimePeriod"]
|
||||||
budget["TimePeriod"].should.have.key("End")
|
assert budget["TimePeriod"]["End"]
|
||||||
budget["TimePeriod"]["End"].should.be.a(datetime)
|
assert budget["TimeUnit"] == "DAILY"
|
||||||
budget.should.have.key("TimeUnit").equals("DAILY")
|
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -90,10 +87,8 @@ def test_create_existing_budget():
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("DuplicateRecordException")
|
assert err["Code"] == "DuplicateRecordException"
|
||||||
err["Message"].should.equal(
|
assert err["Message"] == "Error creating budget: testb - the budget already exists."
|
||||||
"Error creating budget: testb - the budget already exists."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -105,9 +100,10 @@ def test_create_budget_without_limit_param():
|
|||||||
Budget={"BudgetName": "testb", "TimeUnit": "DAILY", "BudgetType": "COST"},
|
Budget={"BudgetName": "testb", "TimeUnit": "DAILY", "BudgetType": "COST"},
|
||||||
)
|
)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("InvalidParameterException")
|
assert err["Code"] == "InvalidParameterException"
|
||||||
err["Message"].should.equal(
|
assert (
|
||||||
"Unable to create/update budget - please provide one of the followings: Budget Limit/ Planned Budget Limit/ Auto Adjust Data"
|
err["Message"]
|
||||||
|
== "Unable to create/update budget - please provide one of the followings: Budget Limit/ Planned Budget Limit/ Auto Adjust Data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -117,17 +113,15 @@ def test_describe_unknown_budget():
|
|||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.describe_budget(AccountId=ACCOUNT_ID, BudgetName="unknown")
|
client.describe_budget(AccountId=ACCOUNT_ID, BudgetName="unknown")
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("NotFoundException")
|
assert err["Code"] == "NotFoundException"
|
||||||
err["Message"].should.equal(
|
assert err["Message"] == "Unable to get budget: unknown - the budget doesn't exist."
|
||||||
"Unable to get budget: unknown - the budget doesn't exist."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
def test_describe_no_budgets():
|
def test_describe_no_budgets():
|
||||||
client = boto3.client("budgets", region_name="us-east-1")
|
client = boto3.client("budgets", region_name="us-east-1")
|
||||||
resp = client.describe_budgets(AccountId=ACCOUNT_ID)
|
resp = client.describe_budgets(AccountId=ACCOUNT_ID)
|
||||||
resp.should.have.key("Budgets").equals([])
|
assert resp["Budgets"] == []
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -147,7 +141,7 @@ def test_create_and_describe_all_budgets():
|
|||||||
res = client.describe_budgets(AccountId=ACCOUNT_ID)
|
res = client.describe_budgets(AccountId=ACCOUNT_ID)
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
pytest.skip("This test requires 64-bit time_t")
|
pytest.skip("This test requires 64-bit time_t")
|
||||||
res["Budgets"].should.have.length_of(1)
|
assert len(res["Budgets"]) == 1
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -164,10 +158,10 @@ def test_delete_budget():
|
|||||||
)
|
)
|
||||||
|
|
||||||
resp = client.delete_budget(AccountId=ACCOUNT_ID, BudgetName="b1")
|
resp = client.delete_budget(AccountId=ACCOUNT_ID, BudgetName="b1")
|
||||||
resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
assert resp["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||||
|
|
||||||
res = client.describe_budgets(AccountId=ACCOUNT_ID)
|
res = client.describe_budgets(AccountId=ACCOUNT_ID)
|
||||||
res["Budgets"].should.have.length_of(0)
|
assert len(res["Budgets"]) == 0
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -176,7 +170,8 @@ def test_delete_unknown_budget():
|
|||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.delete_budget(AccountId=ACCOUNT_ID, BudgetName="unknown")
|
client.delete_budget(AccountId=ACCOUNT_ID, BudgetName="unknown")
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("NotFoundException")
|
assert err["Code"] == "NotFoundException"
|
||||||
err["Message"].should.equal(
|
assert (
|
||||||
"Unable to delete budget: unknown - the budget doesn't exist. Try creating it first. "
|
err["Message"]
|
||||||
|
== "Unable to delete budget: unknown - the budget doesn't exist. Try creating it first. "
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,6 @@ import boto3
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
from moto import mock_budgets
|
from moto import mock_budgets
|
||||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||||
|
|
||||||
@ -37,13 +36,13 @@ def test_create_and_describe_notification():
|
|||||||
res = client.describe_notifications_for_budget(
|
res = client.describe_notifications_for_budget(
|
||||||
AccountId=ACCOUNT_ID, BudgetName="testbudget"
|
AccountId=ACCOUNT_ID, BudgetName="testbudget"
|
||||||
)
|
)
|
||||||
res.should.have.key("Notifications").length_of(1)
|
assert len(res["Notifications"]) == 1
|
||||||
notification = res["Notifications"][0]
|
notification = res["Notifications"][0]
|
||||||
notification.should.have.key("NotificationType").should.equal("ACTUAL")
|
assert notification["NotificationType"] == "ACTUAL"
|
||||||
notification.should.have.key("ComparisonOperator").should.equal("EQUAL_TO")
|
assert notification["ComparisonOperator"] == "EQUAL_TO"
|
||||||
notification.should.have.key("Threshold").should.equal(123)
|
assert notification["Threshold"] == 123
|
||||||
notification.should.have.key("ThresholdType").should.equal("ABSOLUTE_VALUE")
|
assert notification["ThresholdType"] == "ABSOLUTE_VALUE"
|
||||||
notification.should.have.key("NotificationState").should.equal("ALARM")
|
assert notification["NotificationState"] == "ALARM"
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -85,24 +84,24 @@ def test_create_notification():
|
|||||||
},
|
},
|
||||||
Subscribers=[{"SubscriptionType": "SNS", "Address": "arn:sns:topic:mytopic"}],
|
Subscribers=[{"SubscriptionType": "SNS", "Address": "arn:sns:topic:mytopic"}],
|
||||||
)
|
)
|
||||||
res["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
assert res["ResponseMetadata"]["HTTPStatusCode"] == 200
|
||||||
|
|
||||||
res = client.describe_notifications_for_budget(
|
res = client.describe_notifications_for_budget(
|
||||||
AccountId=ACCOUNT_ID, BudgetName="testbudget"
|
AccountId=ACCOUNT_ID, BudgetName="testbudget"
|
||||||
)
|
)
|
||||||
res.should.have.key("Notifications").length_of(2)
|
assert len(res["Notifications"]) == 2
|
||||||
n_1 = res["Notifications"][0]
|
n_1 = res["Notifications"][0]
|
||||||
n_1.should.have.key("NotificationType").should.equal("ACTUAL")
|
assert n_1["NotificationType"] == "ACTUAL"
|
||||||
n_1.should.have.key("ComparisonOperator").should.equal("EQUAL_TO")
|
assert n_1["ComparisonOperator"] == "EQUAL_TO"
|
||||||
n_1.should.have.key("Threshold").should.equal(123)
|
assert n_1["Threshold"] == 123
|
||||||
n_1.should.have.key("ThresholdType").should.equal("ABSOLUTE_VALUE")
|
assert n_1["ThresholdType"] == "ABSOLUTE_VALUE"
|
||||||
n_1.should.have.key("NotificationState").should.equal("ALARM")
|
assert n_1["NotificationState"] == "ALARM"
|
||||||
n_2 = res["Notifications"][1]
|
n_2 = res["Notifications"][1]
|
||||||
n_2.should.have.key("NotificationType").should.equal("ACTUAL")
|
assert n_2["NotificationType"] == "ACTUAL"
|
||||||
n_2.should.have.key("ComparisonOperator").should.equal("GREATER_THAN")
|
assert n_2["ComparisonOperator"] == "GREATER_THAN"
|
||||||
n_2.should.have.key("Threshold").should.equal(0)
|
assert n_2["Threshold"] == 0
|
||||||
n_2.should.have.key("ThresholdType").should.equal("ABSOLUTE_VALUE")
|
assert n_2["ThresholdType"] == "ABSOLUTE_VALUE"
|
||||||
n_2.should.have.key("NotificationState").should.equal("OK")
|
assert n_2["NotificationState"] == "OK"
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -123,10 +122,8 @@ def test_create_notification_unknown_budget():
|
|||||||
Subscribers=[{"SubscriptionType": "EMAIL", "Address": "admin@moto.com"}],
|
Subscribers=[{"SubscriptionType": "EMAIL", "Address": "admin@moto.com"}],
|
||||||
)
|
)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("NotFoundException")
|
assert err["Code"] == "NotFoundException"
|
||||||
err["Message"].should.equal(
|
assert err["Message"] == "Unable to create notification - the budget doesn't exist."
|
||||||
"Unable to create notification - the budget doesn't exist."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -171,7 +168,7 @@ def test_delete_notification():
|
|||||||
res = client.describe_notifications_for_budget(
|
res = client.describe_notifications_for_budget(
|
||||||
AccountId=ACCOUNT_ID, BudgetName="testbudget"
|
AccountId=ACCOUNT_ID, BudgetName="testbudget"
|
||||||
)
|
)
|
||||||
res.should.have.key("Notifications").length_of(0)
|
assert len(res["Notifications"]) == 0
|
||||||
|
|
||||||
|
|
||||||
@mock_budgets
|
@mock_budgets
|
||||||
@ -191,7 +188,5 @@ def test_delete_notification_unknown_budget():
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("NotFoundException")
|
assert err["Code"] == "NotFoundException"
|
||||||
err["Message"].should.equal(
|
assert err["Message"] == "Unable to delete notification - the budget doesn't exist."
|
||||||
"Unable to delete notification - the budget doesn't exist."
|
|
||||||
)
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import json
|
import json
|
||||||
import sure # noqa # pylint: disable=unused-import
|
|
||||||
|
|
||||||
import moto.server as server
|
import moto.server as server
|
||||||
from moto import mock_budgets
|
from moto import mock_budgets
|
||||||
@ -12,5 +11,5 @@ def test_budgets_describe_budgets():
|
|||||||
|
|
||||||
headers = {"X-Amz-Target": "AWSBudgetServiceGateway.DescribeBudgets"}
|
headers = {"X-Amz-Target": "AWSBudgetServiceGateway.DescribeBudgets"}
|
||||||
resp = test_client.post("/", headers=headers, json={})
|
resp = test_client.post("/", headers=headers, json={})
|
||||||
resp.status_code.should.equal(200)
|
assert resp.status_code == 200
|
||||||
json.loads(resp.data).should.equal({"Budgets": [], "nextToken": None})
|
assert json.loads(resp.data) == {"Budgets": [], "nextToken": None}
|
||||||
|
Loading…
Reference in New Issue
Block a user