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