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,138 +1,142 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import re
|
||||||
|
|
||||||
from moto.core import DEFAULT_ACCOUNT_ID
|
from moto.core import DEFAULT_ACCOUNT_ID
|
||||||
from moto.organizations import utils
|
from moto.organizations import utils
|
||||||
|
|
||||||
|
|
||||||
def test_make_random_org_id():
|
def test_make_random_org_id():
|
||||||
org_id = utils.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():
|
def test_make_random_root_id():
|
||||||
root_id = utils.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():
|
def test_make_random_ou_id():
|
||||||
root_id = utils.make_random_root_id()
|
root_id = utils.make_random_root_id()
|
||||||
ou_id = utils.make_random_ou_id(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():
|
def test_make_random_account_id():
|
||||||
account_id = utils.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():
|
def test_make_random_create_account_status_id():
|
||||||
create_account_status_id = utils.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():
|
def test_make_random_policy_id():
|
||||||
policy_id = utils.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):
|
def validate_organization(response):
|
||||||
org = response["Organization"]
|
org = response["Organization"]
|
||||||
sorted(org.keys()).should.equal(
|
assert sorted(org.keys()) == [
|
||||||
[
|
"Arn",
|
||||||
"Arn",
|
"AvailablePolicyTypes",
|
||||||
"AvailablePolicyTypes",
|
"FeatureSet",
|
||||||
"FeatureSet",
|
"Id",
|
||||||
"Id",
|
"MasterAccountArn",
|
||||||
"MasterAccountArn",
|
"MasterAccountEmail",
|
||||||
"MasterAccountEmail",
|
"MasterAccountId",
|
||||||
"MasterAccountId",
|
]
|
||||||
]
|
assert re.match(utils.ORG_ID_REGEX, org["Id"])
|
||||||
)
|
assert org["MasterAccountId"] == DEFAULT_ACCOUNT_ID
|
||||||
org["Id"].should.match(utils.ORG_ID_REGEX)
|
assert org["MasterAccountArn"] == (
|
||||||
org["MasterAccountId"].should.equal(DEFAULT_ACCOUNT_ID)
|
|
||||||
org["MasterAccountArn"].should.equal(
|
|
||||||
utils.MASTER_ACCOUNT_ARN_FORMAT.format(org["MasterAccountId"], org["Id"])
|
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"])
|
utils.ORGANIZATION_ARN_FORMAT.format(org["MasterAccountId"], org["Id"])
|
||||||
)
|
)
|
||||||
org["MasterAccountEmail"].should.equal(utils.MASTER_ACCOUNT_EMAIL)
|
assert org["MasterAccountEmail"] == utils.MASTER_ACCOUNT_EMAIL
|
||||||
org["FeatureSet"].should.be.within(["ALL", "CONSOLIDATED_BILLING"])
|
assert org["FeatureSet"] in ["ALL", "CONSOLIDATED_BILLING"]
|
||||||
org["AvailablePolicyTypes"].should.equal(
|
assert org["AvailablePolicyTypes"] == [
|
||||||
[{"Type": "SERVICE_CONTROL_POLICY", "Status": "ENABLED"}]
|
{"Type": "SERVICE_CONTROL_POLICY", "Status": "ENABLED"}
|
||||||
)
|
]
|
||||||
|
|
||||||
|
|
||||||
def validate_roots(org, response):
|
def validate_roots(org, response):
|
||||||
response.should.have.key("Roots").should.be.a(list)
|
assert isinstance(response["Roots"], list)
|
||||||
response["Roots"].shouldnt.equal([])
|
assert response["Roots"] != []
|
||||||
root = response["Roots"][0]
|
root = response["Roots"][0]
|
||||||
root.should.have.key("Id").should.match(utils.ROOT_ID_REGEX)
|
assert re.match(utils.ROOT_ID_REGEX, root["Id"])
|
||||||
root.should.have.key("Arn").should.equal(
|
assert root["Arn"] == (
|
||||||
utils.ROOT_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], root["Id"])
|
utils.ROOT_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], root["Id"])
|
||||||
)
|
)
|
||||||
root.should.have.key("Name").should.be.a(str)
|
assert isinstance(root["Name"], str)
|
||||||
root.should.have.key("PolicyTypes").should.equal([])
|
assert root["PolicyTypes"] == []
|
||||||
|
|
||||||
|
|
||||||
def validate_organizational_unit(org, response):
|
def validate_organizational_unit(org, response):
|
||||||
response.should.have.key("OrganizationalUnit").should.be.a(dict)
|
assert isinstance(response["OrganizationalUnit"], dict)
|
||||||
ou = response["OrganizationalUnit"]
|
ou = response["OrganizationalUnit"]
|
||||||
ou.should.have.key("Id").should.match(utils.OU_ID_REGEX)
|
assert re.match(utils.OU_ID_REGEX, ou["Id"])
|
||||||
ou.should.have.key("Arn").should.equal(
|
assert ou["Arn"] == (
|
||||||
utils.OU_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], ou["Id"])
|
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):
|
def validate_account(org, account):
|
||||||
sorted(account.keys()).should.equal(
|
assert sorted(account.keys()) == [
|
||||||
["Arn", "Email", "Id", "JoinedMethod", "JoinedTimestamp", "Name", "Status"]
|
"Arn",
|
||||||
)
|
"Email",
|
||||||
account["Id"].should.match(utils.ACCOUNT_ID_REGEX)
|
"Id",
|
||||||
account["Arn"].should.equal(
|
"JoinedMethod",
|
||||||
|
"JoinedTimestamp",
|
||||||
|
"Name",
|
||||||
|
"Status",
|
||||||
|
]
|
||||||
|
assert re.match(utils.ACCOUNT_ID_REGEX, account["Id"])
|
||||||
|
assert account["Arn"] == (
|
||||||
utils.ACCOUNT_ARN_FORMAT.format(
|
utils.ACCOUNT_ARN_FORMAT.format(
|
||||||
org["MasterAccountId"], org["Id"], account["Id"]
|
org["MasterAccountId"], org["Id"], account["Id"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
account["Email"].should.match(utils.EMAIL_REGEX)
|
assert re.match(utils.EMAIL_REGEX, account["Email"])
|
||||||
account["JoinedMethod"].should.be.within(["INVITED", "CREATED"])
|
assert account["JoinedMethod"] in ["INVITED", "CREATED"]
|
||||||
account["Status"].should.be.within(["ACTIVE", "SUSPENDED"])
|
assert account["Status"] in ["ACTIVE", "SUSPENDED"]
|
||||||
account["Name"].should.be.a(str)
|
assert isinstance(account["Name"], str)
|
||||||
account["JoinedTimestamp"].should.be.a(datetime.datetime)
|
assert isinstance(account["JoinedTimestamp"], datetime.datetime)
|
||||||
|
|
||||||
|
|
||||||
def validate_create_account_status(create_status):
|
def validate_create_account_status(create_status):
|
||||||
sorted(create_status.keys()).should.equal(
|
assert sorted(create_status.keys()) == [
|
||||||
[
|
"AccountId",
|
||||||
"AccountId",
|
"AccountName",
|
||||||
"AccountName",
|
"CompletedTimestamp",
|
||||||
"CompletedTimestamp",
|
"Id",
|
||||||
"Id",
|
"RequestedTimestamp",
|
||||||
"RequestedTimestamp",
|
"State",
|
||||||
"State",
|
]
|
||||||
]
|
assert re.match(utils.CREATE_ACCOUNT_STATUS_ID_REGEX, create_status["Id"])
|
||||||
)
|
assert re.match(utils.ACCOUNT_ID_REGEX, create_status["AccountId"])
|
||||||
create_status["Id"].should.match(utils.CREATE_ACCOUNT_STATUS_ID_REGEX)
|
assert isinstance(create_status["AccountName"], str)
|
||||||
create_status["AccountId"].should.match(utils.ACCOUNT_ID_REGEX)
|
assert create_status["State"] == "SUCCEEDED"
|
||||||
create_status["AccountName"].should.be.a(str)
|
assert isinstance(create_status["RequestedTimestamp"], datetime.datetime)
|
||||||
create_status["State"].should.equal("SUCCEEDED")
|
assert isinstance(create_status["CompletedTimestamp"], datetime.datetime)
|
||||||
create_status["RequestedTimestamp"].should.be.a(datetime.datetime)
|
|
||||||
create_status["CompletedTimestamp"].should.be.a(datetime.datetime)
|
|
||||||
|
|
||||||
|
|
||||||
def validate_policy_summary(org, summary):
|
def validate_policy_summary(org, summary):
|
||||||
summary.should.be.a(dict)
|
assert isinstance(summary, dict)
|
||||||
summary.should.have.key("Id").should.match(utils.POLICY_ID_REGEX)
|
assert re.match(utils.POLICY_ID_REGEX, summary["Id"])
|
||||||
summary.should.have.key("Arn").should.equal(
|
assert summary["Arn"] == (
|
||||||
utils.SCP_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], summary["Id"])
|
utils.SCP_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], summary["Id"])
|
||||||
)
|
)
|
||||||
summary.should.have.key("Name").should.be.a(str)
|
assert isinstance(summary["Name"], str)
|
||||||
summary.should.have.key("Description").should.be.a(str)
|
assert isinstance(summary["Description"], str)
|
||||||
summary.should.have.key("Type").should.equal("SERVICE_CONTROL_POLICY")
|
assert summary["Type"] == "SERVICE_CONTROL_POLICY"
|
||||||
summary.should.have.key("AwsManaged").should.be.a(bool)
|
assert isinstance(summary["AwsManaged"], bool)
|
||||||
|
|
||||||
|
|
||||||
def validate_service_control_policy(org, response):
|
def validate_service_control_policy(org, response):
|
||||||
response.should.have.key("PolicySummary").should.be.a(dict)
|
assert isinstance(response["PolicySummary"], dict)
|
||||||
response.should.have.key("Content").should.be.a(str)
|
assert isinstance(response["Content"], str)
|
||||||
validate_policy_summary(org, response["PolicySummary"])
|
validate_policy_summary(org, response["PolicySummary"])
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user