Techdebt: Replace sure with regular assertions in Organizations (#6675)
Co-authored-by: Karri Balk <kbalk@users.noreply.github.com>
This commit is contained in:
parent
45dfb54469
commit
0fa43c85b4
@ -1,43 +1,44 @@
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from moto.core import DEFAULT_ACCOUNT_ID
|
||||
from moto.organizations import utils
|
||||
|
||||
|
||||
def test_make_random_org_id():
|
||||
org_id = utils.make_random_org_id()
|
||||
org_id.should.match(utils.ORG_ID_REGEX)
|
||||
assert re.match(utils.ORG_ID_REGEX, org_id)
|
||||
|
||||
|
||||
def test_make_random_root_id():
|
||||
root_id = utils.make_random_root_id()
|
||||
root_id.should.match(utils.ROOT_ID_REGEX)
|
||||
assert re.match(utils.ROOT_ID_REGEX, root_id)
|
||||
|
||||
|
||||
def test_make_random_ou_id():
|
||||
root_id = utils.make_random_root_id()
|
||||
ou_id = utils.make_random_ou_id(root_id)
|
||||
ou_id.should.match(utils.OU_ID_REGEX)
|
||||
assert re.match(utils.OU_ID_REGEX, ou_id)
|
||||
|
||||
|
||||
def test_make_random_account_id():
|
||||
account_id = utils.make_random_account_id()
|
||||
account_id.should.match(utils.ACCOUNT_ID_REGEX)
|
||||
assert re.match(utils.ACCOUNT_ID_REGEX, account_id)
|
||||
|
||||
|
||||
def test_make_random_create_account_status_id():
|
||||
create_account_status_id = utils.make_random_create_account_status_id()
|
||||
create_account_status_id.should.match(utils.CREATE_ACCOUNT_STATUS_ID_REGEX)
|
||||
assert re.match(utils.CREATE_ACCOUNT_STATUS_ID_REGEX, create_account_status_id)
|
||||
|
||||
|
||||
def test_make_random_policy_id():
|
||||
policy_id = utils.make_random_policy_id()
|
||||
policy_id.should.match(utils.POLICY_ID_REGEX)
|
||||
assert re.match(utils.POLICY_ID_REGEX, policy_id)
|
||||
|
||||
|
||||
def validate_organization(response):
|
||||
org = response["Organization"]
|
||||
sorted(org.keys()).should.equal(
|
||||
[
|
||||
assert sorted(org.keys()) == [
|
||||
"Arn",
|
||||
"AvailablePolicyTypes",
|
||||
"FeatureSet",
|
||||
@ -46,64 +47,68 @@ def validate_organization(response):
|
||||
"MasterAccountEmail",
|
||||
"MasterAccountId",
|
||||
]
|
||||
)
|
||||
org["Id"].should.match(utils.ORG_ID_REGEX)
|
||||
org["MasterAccountId"].should.equal(DEFAULT_ACCOUNT_ID)
|
||||
org["MasterAccountArn"].should.equal(
|
||||
assert re.match(utils.ORG_ID_REGEX, org["Id"])
|
||||
assert org["MasterAccountId"] == DEFAULT_ACCOUNT_ID
|
||||
assert org["MasterAccountArn"] == (
|
||||
utils.MASTER_ACCOUNT_ARN_FORMAT.format(org["MasterAccountId"], org["Id"])
|
||||
)
|
||||
org["Arn"].should.equal(
|
||||
assert org["Arn"] == (
|
||||
utils.ORGANIZATION_ARN_FORMAT.format(org["MasterAccountId"], org["Id"])
|
||||
)
|
||||
org["MasterAccountEmail"].should.equal(utils.MASTER_ACCOUNT_EMAIL)
|
||||
org["FeatureSet"].should.be.within(["ALL", "CONSOLIDATED_BILLING"])
|
||||
org["AvailablePolicyTypes"].should.equal(
|
||||
[{"Type": "SERVICE_CONTROL_POLICY", "Status": "ENABLED"}]
|
||||
)
|
||||
assert org["MasterAccountEmail"] == utils.MASTER_ACCOUNT_EMAIL
|
||||
assert org["FeatureSet"] in ["ALL", "CONSOLIDATED_BILLING"]
|
||||
assert org["AvailablePolicyTypes"] == [
|
||||
{"Type": "SERVICE_CONTROL_POLICY", "Status": "ENABLED"}
|
||||
]
|
||||
|
||||
|
||||
def validate_roots(org, response):
|
||||
response.should.have.key("Roots").should.be.a(list)
|
||||
response["Roots"].shouldnt.equal([])
|
||||
assert isinstance(response["Roots"], list)
|
||||
assert response["Roots"] != []
|
||||
root = response["Roots"][0]
|
||||
root.should.have.key("Id").should.match(utils.ROOT_ID_REGEX)
|
||||
root.should.have.key("Arn").should.equal(
|
||||
assert re.match(utils.ROOT_ID_REGEX, root["Id"])
|
||||
assert root["Arn"] == (
|
||||
utils.ROOT_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], root["Id"])
|
||||
)
|
||||
root.should.have.key("Name").should.be.a(str)
|
||||
root.should.have.key("PolicyTypes").should.equal([])
|
||||
assert isinstance(root["Name"], str)
|
||||
assert root["PolicyTypes"] == []
|
||||
|
||||
|
||||
def validate_organizational_unit(org, response):
|
||||
response.should.have.key("OrganizationalUnit").should.be.a(dict)
|
||||
assert isinstance(response["OrganizationalUnit"], dict)
|
||||
ou = response["OrganizationalUnit"]
|
||||
ou.should.have.key("Id").should.match(utils.OU_ID_REGEX)
|
||||
ou.should.have.key("Arn").should.equal(
|
||||
assert re.match(utils.OU_ID_REGEX, ou["Id"])
|
||||
assert ou["Arn"] == (
|
||||
utils.OU_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], ou["Id"])
|
||||
)
|
||||
ou.should.have.key("Name").should.be.a(str)
|
||||
assert isinstance(ou["Name"], str)
|
||||
|
||||
|
||||
def validate_account(org, account):
|
||||
sorted(account.keys()).should.equal(
|
||||
["Arn", "Email", "Id", "JoinedMethod", "JoinedTimestamp", "Name", "Status"]
|
||||
)
|
||||
account["Id"].should.match(utils.ACCOUNT_ID_REGEX)
|
||||
account["Arn"].should.equal(
|
||||
assert sorted(account.keys()) == [
|
||||
"Arn",
|
||||
"Email",
|
||||
"Id",
|
||||
"JoinedMethod",
|
||||
"JoinedTimestamp",
|
||||
"Name",
|
||||
"Status",
|
||||
]
|
||||
assert re.match(utils.ACCOUNT_ID_REGEX, account["Id"])
|
||||
assert account["Arn"] == (
|
||||
utils.ACCOUNT_ARN_FORMAT.format(
|
||||
org["MasterAccountId"], org["Id"], account["Id"]
|
||||
)
|
||||
)
|
||||
account["Email"].should.match(utils.EMAIL_REGEX)
|
||||
account["JoinedMethod"].should.be.within(["INVITED", "CREATED"])
|
||||
account["Status"].should.be.within(["ACTIVE", "SUSPENDED"])
|
||||
account["Name"].should.be.a(str)
|
||||
account["JoinedTimestamp"].should.be.a(datetime.datetime)
|
||||
assert re.match(utils.EMAIL_REGEX, account["Email"])
|
||||
assert account["JoinedMethod"] in ["INVITED", "CREATED"]
|
||||
assert account["Status"] in ["ACTIVE", "SUSPENDED"]
|
||||
assert isinstance(account["Name"], str)
|
||||
assert isinstance(account["JoinedTimestamp"], datetime.datetime)
|
||||
|
||||
|
||||
def validate_create_account_status(create_status):
|
||||
sorted(create_status.keys()).should.equal(
|
||||
[
|
||||
assert sorted(create_status.keys()) == [
|
||||
"AccountId",
|
||||
"AccountName",
|
||||
"CompletedTimestamp",
|
||||
@ -111,28 +116,27 @@ def validate_create_account_status(create_status):
|
||||
"RequestedTimestamp",
|
||||
"State",
|
||||
]
|
||||
)
|
||||
create_status["Id"].should.match(utils.CREATE_ACCOUNT_STATUS_ID_REGEX)
|
||||
create_status["AccountId"].should.match(utils.ACCOUNT_ID_REGEX)
|
||||
create_status["AccountName"].should.be.a(str)
|
||||
create_status["State"].should.equal("SUCCEEDED")
|
||||
create_status["RequestedTimestamp"].should.be.a(datetime.datetime)
|
||||
create_status["CompletedTimestamp"].should.be.a(datetime.datetime)
|
||||
assert re.match(utils.CREATE_ACCOUNT_STATUS_ID_REGEX, create_status["Id"])
|
||||
assert re.match(utils.ACCOUNT_ID_REGEX, create_status["AccountId"])
|
||||
assert isinstance(create_status["AccountName"], str)
|
||||
assert create_status["State"] == "SUCCEEDED"
|
||||
assert isinstance(create_status["RequestedTimestamp"], datetime.datetime)
|
||||
assert isinstance(create_status["CompletedTimestamp"], datetime.datetime)
|
||||
|
||||
|
||||
def validate_policy_summary(org, summary):
|
||||
summary.should.be.a(dict)
|
||||
summary.should.have.key("Id").should.match(utils.POLICY_ID_REGEX)
|
||||
summary.should.have.key("Arn").should.equal(
|
||||
assert isinstance(summary, dict)
|
||||
assert re.match(utils.POLICY_ID_REGEX, summary["Id"])
|
||||
assert summary["Arn"] == (
|
||||
utils.SCP_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], summary["Id"])
|
||||
)
|
||||
summary.should.have.key("Name").should.be.a(str)
|
||||
summary.should.have.key("Description").should.be.a(str)
|
||||
summary.should.have.key("Type").should.equal("SERVICE_CONTROL_POLICY")
|
||||
summary.should.have.key("AwsManaged").should.be.a(bool)
|
||||
assert isinstance(summary["Name"], str)
|
||||
assert isinstance(summary["Description"], str)
|
||||
assert summary["Type"] == "SERVICE_CONTROL_POLICY"
|
||||
assert isinstance(summary["AwsManaged"], bool)
|
||||
|
||||
|
||||
def validate_service_control_policy(org, response):
|
||||
response.should.have.key("PolicySummary").should.be.a(dict)
|
||||
response.should.have.key("Content").should.be.a(str)
|
||||
assert isinstance(response["PolicySummary"], dict)
|
||||
assert isinstance(response["Content"], str)
|
||||
validate_policy_summary(org, response["PolicySummary"])
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user