diff --git a/tests/test_organizations/organizations_test_utils.py b/tests/test_organizations/organizations_test_utils.py index 26bc27e15..3c92fb1a3 100644 --- a/tests/test_organizations/organizations_test_utils.py +++ b/tests/test_organizations/organizations_test_utils.py @@ -1,138 +1,142 @@ 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( - [ - "Arn", - "AvailablePolicyTypes", - "FeatureSet", - "Id", - "MasterAccountArn", - "MasterAccountEmail", - "MasterAccountId", - ] - ) - org["Id"].should.match(utils.ORG_ID_REGEX) - org["MasterAccountId"].should.equal(DEFAULT_ACCOUNT_ID) - org["MasterAccountArn"].should.equal( + assert sorted(org.keys()) == [ + "Arn", + "AvailablePolicyTypes", + "FeatureSet", + "Id", + "MasterAccountArn", + "MasterAccountEmail", + "MasterAccountId", + ] + 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( - [ - "AccountId", - "AccountName", - "CompletedTimestamp", - "Id", - "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 sorted(create_status.keys()) == [ + "AccountId", + "AccountName", + "CompletedTimestamp", + "Id", + "RequestedTimestamp", + "State", + ] + 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"]) diff --git a/tests/test_organizations/test_organizations_boto3.py b/tests/test_organizations/test_organizations_boto3.py index 7f83dbc2d..c10dafc39 100644 --- a/tests/test_organizations/test_organizations_boto3.py +++ b/tests/test_organizations/test_organizations_boto3.py @@ -1,5 +1,13 @@ from datetime import datetime +import json +import re +import boto3 +from botocore.exceptions import ClientError +import pytest + +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +from moto import mock_organizations from moto.organizations.exceptions import InvalidInputException, TargetNotFoundException from moto.organizations.models import ( FakeAccount, @@ -9,15 +17,6 @@ from moto.organizations.models import ( FakeRoot, OrganizationsBackend, ) - -import boto3 -import json -import sure # noqa # pylint: disable=unused-import -from botocore.exceptions import ClientError -import pytest - -from moto import mock_organizations -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.organizations import utils from .organizations_test_utils import ( validate_organization, @@ -35,26 +34,26 @@ def test_create_organization(): client = boto3.client("organizations", region_name="us-east-1") response = client.create_organization(FeatureSet="ALL") validate_organization(response) - response["Organization"]["FeatureSet"].should.equal("ALL") + assert response["Organization"]["FeatureSet"] == "ALL" response = client.list_accounts() - len(response["Accounts"]).should.equal(1) - response["Accounts"][0]["Name"].should.equal("master") - response["Accounts"][0]["Id"].should.equal(ACCOUNT_ID) - response["Accounts"][0]["Email"].should.equal(utils.MASTER_ACCOUNT_EMAIL) + assert len(response["Accounts"]) == 1 + assert response["Accounts"][0]["Name"] == "master" + assert response["Accounts"][0]["Id"] == ACCOUNT_ID + assert response["Accounts"][0]["Email"] == utils.MASTER_ACCOUNT_EMAIL response = client.list_policies(Filter="SERVICE_CONTROL_POLICY") - len(response["Policies"]).should.equal(1) - response["Policies"][0]["Name"].should.equal("FullAWSAccess") - response["Policies"][0]["Id"].should.equal(utils.DEFAULT_POLICY_ID) - response["Policies"][0]["AwsManaged"].should.equal(True) + assert len(response["Policies"]) == 1 + assert response["Policies"][0]["Name"] == "FullAWSAccess" + assert response["Policies"][0]["Id"] == utils.DEFAULT_POLICY_ID + assert response["Policies"][0]["AwsManaged"] is True response = client.list_targets_for_policy(PolicyId=utils.DEFAULT_POLICY_ID) - len(response["Targets"]).should.equal(2) + assert len(response["Targets"]) == 2 root_ou = [t for t in response["Targets"] if t["Type"] == "ROOT"][0] - root_ou["Name"].should.equal("Root") + assert root_ou["Name"] == "Root" master_account = [t for t in response["Targets"] if t["Type"] == "ACCOUNT"][0] - master_account["Name"].should.equal("master") + assert master_account["Name"] == "master" @mock_organizations @@ -63,7 +62,7 @@ def test_create_organization_without_feature_set(): client.create_organization() response = client.describe_organization() validate_organization(response) - response["Organization"]["FeatureSet"].should.equal("ALL") + assert response["Organization"]["FeatureSet"] == "ALL" @mock_organizations @@ -80,10 +79,10 @@ def test_describe_organization_exception(): with pytest.raises(ClientError) as e: client.describe_organization() ex = e.value - ex.operation_name.should.equal("DescribeOrganization") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AWSOrganizationsNotInUseException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DescribeOrganization" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AWSOrganizationsNotInUseException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "Your account is not a member of an organization." ) @@ -107,7 +106,7 @@ def test_create_organizational_unit(): ou_name = "ou01" response = client.create_organizational_unit(ParentId=root_id, Name=ou_name) validate_organizational_unit(org, response) - response["OrganizationalUnit"]["Name"].should.equal(ou_name) + assert response["OrganizationalUnit"]["Name"] == ou_name @mock_organizations @@ -122,17 +121,15 @@ def test_delete_organizational_unit(): # delete organizational unit ou_id = response["OrganizationalUnit"]["Id"] response = client.delete_organizational_unit(OrganizationalUnitId=ou_id) - response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 # verify the deletion with pytest.raises(ClientError) as e: client.describe_organizational_unit(OrganizationalUnitId=ou_id) ex = e.value - ex.operation_name.should.equal("DescribeOrganizationalUnit") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain( - "OrganizationalUnitNotFoundException" - ) + assert ex.operation_name == "DescribeOrganizationalUnit" + assert ex.response["Error"]["Code"] == "400" + assert "OrganizationalUnitNotFoundException" in ex.response["Error"]["Message"] @mock_organizations @@ -150,17 +147,15 @@ def test_describe_organizational_unit(): @mock_organizations def test_describe_organizational_unit_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] with pytest.raises(ClientError) as e: client.describe_organizational_unit( OrganizationalUnitId=utils.make_random_root_id() ) ex = e.value - ex.operation_name.should.equal("DescribeOrganizationalUnit") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain( - "OrganizationalUnitNotFoundException" - ) + assert ex.operation_name == "DescribeOrganizationalUnit" + assert ex.response["Error"]["Code"] == "400" + assert "OrganizationalUnitNotFoundException" in ex.response["Error"]["Message"] @mock_organizations @@ -172,9 +167,9 @@ def test_list_organizational_units_for_parent(): client.create_organizational_unit(ParentId=root_id, Name="ou02") client.create_organizational_unit(ParentId=root_id, Name="ou03") response = client.list_organizational_units_for_parent(ParentId=root_id) - response.should.have.key("OrganizationalUnits").should.be.a(list) + assert isinstance(response["OrganizationalUnits"], list) for ou in response["OrganizationalUnits"]: - validate_organizational_unit(org, dict(OrganizationalUnit=ou)) + validate_organizational_unit(org, {"OrganizationalUnit": ou}) @mock_organizations @@ -186,14 +181,15 @@ def test_list_organizational_units_pagination(): name = "ou" + str(i) client.create_organizational_unit(ParentId=root_id, Name=name) response = client.list_organizational_units_for_parent(ParentId=root_id) - response.should_not.have.key("NextToken") - len(response["OrganizationalUnits"]).should.be.greater_than_or_equal_to(i) + assert "NextToken" not in response + assert len(response["OrganizationalUnits"]) >= i paginator = client.get_paginator("list_organizational_units_for_parent") page_iterator = paginator.paginate(MaxResults=5, ParentId=root_id) - for page in page_iterator: - len(page["OrganizationalUnits"]).should.be.lower_than_or_equal_to(5) - page["OrganizationalUnits"][-1]["Name"].should.contain("19") + page_list = list(page_iterator) + for page in page_list: + assert len(page["OrganizationalUnits"]) <= 5 + assert "19" in page_list[-1]["OrganizationalUnits"][-1]["Name"] @mock_organizations @@ -204,9 +200,9 @@ def test_list_organizational_units_for_parent_exception(): ParentId=utils.make_random_root_id() ) ex = e.value - ex.operation_name.should.equal("ListOrganizationalUnitsForParent") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain("ParentNotFoundException") + assert ex.operation_name == "ListOrganizationalUnitsForParent" + assert ex.response["Error"]["Code"] == "400" + assert "ParentNotFoundException" in ex.response["Error"]["Message"] # Accounts @@ -223,7 +219,7 @@ def test_create_account(): "CreateAccountStatus" ] validate_create_account_status(create_status) - create_status["AccountName"].should.equal(mockname) + assert create_status["AccountName"] == mockname @mock_organizations @@ -254,7 +250,7 @@ def test_close_account_puts_account_in_suspended_status(): client.close_account(AccountId=created_account_id) account = client.describe_account(AccountId=created_account_id)["Account"] - account["Status"].should.equal("SUSPENDED") + assert account["Status"] == "SUSPENDED" @mock_organizations @@ -266,10 +262,10 @@ def test_close_account_id_not_in_org_raises_exception(): with pytest.raises(ClientError) as e: client.close_account(AccountId=uncreated_fake_account_id) ex = e.value - ex.operation_name.should.equal("CloseAccount") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "CloseAccount" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an account that doesn't exist." ) @@ -277,7 +273,7 @@ def test_close_account_id_not_in_org_raises_exception(): @mock_organizations def test_describe_create_account_status(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] request_id = client.create_account(AccountName=mockname, Email=mockemail)[ "CreateAccountStatus" ]["Id"] @@ -294,8 +290,8 @@ def test_describe_account(): ]["AccountId"] response = client.describe_account(AccountId=account_id) validate_account(org, response["Account"]) - response["Account"]["Name"].should.equal(mockname) - response["Account"]["Email"].should.equal(mockemail) + assert response["Account"]["Name"] == mockname + assert response["Account"]["Email"] == mockemail @mock_organizations @@ -304,10 +300,10 @@ def test_describe_account_exception(): with pytest.raises(ClientError) as e: client.describe_account(AccountId=utils.make_random_account_id()) ex = e.value - ex.operation_name.should.equal("DescribeAccount") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DescribeAccount" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an account that doesn't exist." ) @@ -321,13 +317,13 @@ def test_list_accounts(): email = name + "@" + mockdomain client.create_account(AccountName=name, Email=email) response = client.list_accounts() - response.should.have.key("Accounts") + assert "Accounts" in response accounts = response["Accounts"] - len(accounts).should.equal(6) + assert len(accounts) == 6 for account in accounts: validate_account(org, account) - accounts[4]["Name"].should.equal(mockname + "3") - accounts[3]["Email"].should.equal(mockname + "2" + "@" + mockdomain) + assert accounts[4]["Name"] == mockname + "3" + assert accounts[3]["Email"] == mockname + "2" + "@" + mockdomain @mock_organizations @@ -339,26 +335,27 @@ def test_list_accounts_pagination(): email = name + "@" + mockdomain client.create_account(AccountName=name, Email=email) response = client.list_accounts() - response.should_not.have.key("NextToken") - len(response["Accounts"]).should.be.greater_than_or_equal_to(i) + assert "NextToken" not in response + assert len(response["Accounts"]) >= i paginator = client.get_paginator("list_accounts") page_iterator = paginator.paginate(MaxResults=5) - for page in page_iterator: - len(page["Accounts"]).should.be.lower_than_or_equal_to(5) - page["Accounts"][-1]["Name"].should.contain("24") + page_list = list(page_iterator) + for page in page_list: + assert len(page["Accounts"]) <= 5 + assert "24" in page_list[-1]["Accounts"][-1]["Name"] @mock_organizations def test_list_accounts_for_parent(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] account_id = client.create_account(AccountName=mockname, Email=mockemail)[ "CreateAccountStatus" ]["AccountId"] response = client.list_accounts_for_parent(ParentId=root_id) - account_id.should.be.within([account["Id"] for account in response["Accounts"]]) + assert account_id in [account["Id"] for account in response["Accounts"]] @mock_organizations @@ -367,26 +364,27 @@ def test_list_accounts_for_parent_pagination(): client.create_organization(FeatureSet="ALL") root_id = client.list_roots()["Roots"][0]["Id"] response = client.list_accounts_for_parent(ParentId=root_id) - response.should_not.have.key("NextToken") + assert "NextToken" not in response num_existing_accounts = len(response["Accounts"]) for i in range(num_existing_accounts, 21): name = mockname + str(i) email = name + "@" + mockdomain client.create_account(AccountName=name, Email=email) response = client.list_accounts_for_parent(ParentId=root_id) - len(response["Accounts"]).should.be.greater_than_or_equal_to(i) + assert len(response["Accounts"]) >= i paginator = client.get_paginator("list_accounts_for_parent") page_iterator = paginator.paginate(MaxResults=5, ParentId=root_id) - for page in page_iterator: - len(page["Accounts"]).should.be.lower_than_or_equal_to(5) - page["Accounts"][-1]["Name"].should.contain("20") + page_list = list(page_iterator) + for page in page_list: + assert len(page["Accounts"]) <= 5 + assert "20" in page_list[-1]["Accounts"][-1]["Name"] @mock_organizations def test_move_account(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] account_id = client.create_account(AccountName=mockname, Email=mockemail)[ "CreateAccountStatus" @@ -397,32 +395,32 @@ def test_move_account(): AccountId=account_id, SourceParentId=root_id, DestinationParentId=ou01_id ) response = client.list_accounts_for_parent(ParentId=ou01_id) - account_id.should.be.within([account["Id"] for account in response["Accounts"]]) + assert account_id in [account["Id"] for account in response["Accounts"]] @mock_organizations def test_list_parents_for_ou(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou01 = client.create_organizational_unit(ParentId=root_id, Name="ou01") ou01_id = ou01["OrganizationalUnit"]["Id"] response01 = client.list_parents(ChildId=ou01_id) - response01.should.have.key("Parents").should.be.a(list) - response01["Parents"][0].should.have.key("Id").should.equal(root_id) - response01["Parents"][0].should.have.key("Type").should.equal("ROOT") + assert isinstance(response01["Parents"], list) + assert response01["Parents"][0]["Id"] == root_id + assert response01["Parents"][0]["Type"] == "ROOT" ou02 = client.create_organizational_unit(ParentId=ou01_id, Name="ou02") ou02_id = ou02["OrganizationalUnit"]["Id"] response02 = client.list_parents(ChildId=ou02_id) - response02.should.have.key("Parents").should.be.a(list) - response02["Parents"][0].should.have.key("Id").should.equal(ou01_id) - response02["Parents"][0].should.have.key("Type").should.equal("ORGANIZATIONAL_UNIT") + assert isinstance(response02["Parents"], list) + assert response02["Parents"][0]["Id"] == ou01_id + assert response02["Parents"][0]["Type"] == "ORGANIZATIONAL_UNIT" @mock_organizations def test_list_parents_for_accounts(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou01 = client.create_organizational_unit(ParentId=root_id, Name="ou01") ou01_id = ou01["OrganizationalUnit"]["Id"] @@ -436,19 +434,19 @@ def test_list_parents_for_accounts(): AccountId=account02_id, SourceParentId=root_id, DestinationParentId=ou01_id ) response01 = client.list_parents(ChildId=account01_id) - response01.should.have.key("Parents").should.be.a(list) - response01["Parents"][0].should.have.key("Id").should.equal(root_id) - response01["Parents"][0].should.have.key("Type").should.equal("ROOT") + assert isinstance(response01["Parents"], list) + assert response01["Parents"][0]["Id"] == root_id + assert response01["Parents"][0]["Type"] == "ROOT" response02 = client.list_parents(ChildId=account02_id) - response02.should.have.key("Parents").should.be.a(list) - response02["Parents"][0].should.have.key("Id").should.equal(ou01_id) - response02["Parents"][0].should.have.key("Type").should.equal("ORGANIZATIONAL_UNIT") + assert isinstance(response02["Parents"], list) + assert response02["Parents"][0]["Id"] == ou01_id + assert response02["Parents"][0]["Type"] == "ORGANIZATIONAL_UNIT" @mock_organizations def test_list_children(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou01 = client.create_organizational_unit(ParentId=root_id, Name="ou01") ou01_id = ou01["OrganizationalUnit"]["Id"] @@ -467,53 +465,53 @@ def test_list_children(): response02 = client.list_children(ParentId=root_id, ChildType="ORGANIZATIONAL_UNIT") response03 = client.list_children(ParentId=ou01_id, ChildType="ACCOUNT") response04 = client.list_children(ParentId=ou01_id, ChildType="ORGANIZATIONAL_UNIT") - response01["Children"][0]["Id"].should.equal(ACCOUNT_ID) - response01["Children"][0]["Type"].should.equal("ACCOUNT") - response01["Children"][1]["Id"].should.equal(account01_id) - response01["Children"][1]["Type"].should.equal("ACCOUNT") - response02["Children"][0]["Id"].should.equal(ou01_id) - response02["Children"][0]["Type"].should.equal("ORGANIZATIONAL_UNIT") - response03["Children"][0]["Id"].should.equal(account02_id) - response03["Children"][0]["Type"].should.equal("ACCOUNT") - response04["Children"][0]["Id"].should.equal(ou02_id) - response04["Children"][0]["Type"].should.equal("ORGANIZATIONAL_UNIT") + assert response01["Children"][0]["Id"] == ACCOUNT_ID + assert response01["Children"][0]["Type"] == "ACCOUNT" + assert response01["Children"][1]["Id"] == account01_id + assert response01["Children"][1]["Type"] == "ACCOUNT" + assert response02["Children"][0]["Id"] == ou01_id + assert response02["Children"][0]["Type"] == "ORGANIZATIONAL_UNIT" + assert response03["Children"][0]["Id"] == account02_id + assert response03["Children"][0]["Type"] == "ACCOUNT" + assert response04["Children"][0]["Id"] == ou02_id + assert response04["Children"][0]["Type"] == "ORGANIZATIONAL_UNIT" @mock_organizations def test_list_children_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] with pytest.raises(ClientError) as e: client.list_children(ParentId=utils.make_random_root_id(), ChildType="ACCOUNT") ex = e.value - ex.operation_name.should.equal("ListChildren") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain("ParentNotFoundException") + assert ex.operation_name == "ListChildren" + assert ex.response["Error"]["Code"] == "400" + assert "ParentNotFoundException" in ex.response["Error"]["Message"] with pytest.raises(ClientError) as e: client.list_children(ParentId=root_id, ChildType="BLEE") ex = e.value - ex.operation_name.should.equal("ListChildren") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "ListChildren" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations def test_list_create_account_status(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] response = client.list_create_account_status() createAccountStatuses = response["CreateAccountStatuses"] - createAccountStatuses.should.have.length_of(1) + assert len(createAccountStatuses) == 1 validate_create_account_status(createAccountStatuses[0]) - client.create_account(AccountName=mockname, Email=mockemail)["CreateAccountStatus"][ - "Id" - ] + _ = client.create_account(AccountName=mockname, Email=mockemail)[ + "CreateAccountStatus" + ]["Id"] response = client.list_create_account_status() createAccountStatuses = response["CreateAccountStatuses"] - createAccountStatuses.should.have.length_of(2) + assert len(createAccountStatuses) == 2 for createAccountStatus in createAccountStatuses: validate_create_account_status(createAccountStatus) @@ -521,42 +519,42 @@ def test_list_create_account_status(): @mock_organizations def test_list_create_account_status_succeeded(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] requiredStates = ["SUCCEEDED"] response = client.list_create_account_status(States=requiredStates) createAccountStatuses = response["CreateAccountStatuses"] - createAccountStatuses.should.have.length_of(1) + assert len(createAccountStatuses) == 1 validate_create_account_status(createAccountStatuses[0]) @mock_organizations def test_list_create_account_status_in_progress(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] requiredStates = ["IN_PROGRESS"] response = client.list_create_account_status(States=requiredStates) createAccountStatuses = response["CreateAccountStatuses"] - createAccountStatuses.should.have.length_of(0) + assert len(createAccountStatuses) == 0 @mock_organizations def test_get_paginated_list_create_account_status(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] for _ in range(5): - client.create_account(AccountName=mockname, Email=mockemail)[ + _ = client.create_account(AccountName=mockname, Email=mockemail)[ "CreateAccountStatus" ]["Id"] response = client.list_create_account_status(MaxResults=2) createAccountStatuses = response["CreateAccountStatuses"] - createAccountStatuses.should.have.length_of(2) + assert len(createAccountStatuses) == 2 for createAccountStatus in createAccountStatuses: validate_create_account_status(createAccountStatus) next_token = response["NextToken"] - next_token.should_not.equal(None) + assert next_token is not None response2 = client.list_create_account_status(NextToken=next_token) createAccountStatuses.extend(response2["CreateAccountStatuses"]) - createAccountStatuses.should.have.length_of(6) + assert len(createAccountStatuses) == 6 assert "NextToken" not in response2.keys() for createAccountStatus in createAccountStatuses: validate_create_account_status(createAccountStatus) @@ -565,7 +563,7 @@ def test_get_paginated_list_create_account_status(): @mock_organizations def test_remove_account_from_organization(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] create_account_status = client.create_account( AccountName=mockname, Email=mockemail )["CreateAccountStatus"] @@ -606,12 +604,17 @@ def test_delete_organization_with_existing_account(): # Service Control Policies -policy_doc01 = dict( - Version="2012-10-17", - Statement=[ - dict(Sid="MockPolicyStatement", Effect="Allow", Action="s3:*", Resource="*") +policy_doc01 = { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "MockPolicyStatement", + "Effect": "Allow", + "Action": "s3:*", + "Resource": "*", + } ], -) +} @mock_organizations @@ -625,11 +628,9 @@ def test_create_policy(): Type="SERVICE_CONTROL_POLICY", )["Policy"] validate_service_control_policy(org, policy) - policy["PolicySummary"]["Name"].should.equal("MockServiceControlPolicy") - policy["PolicySummary"]["Description"].should.equal( - "A dummy service control policy" - ) - policy["Content"].should.equal(json.dumps(policy_doc01)) + assert policy["PolicySummary"]["Name"] == "MockServiceControlPolicy" + assert policy["PolicySummary"]["Description"] == "A dummy service control policy" + assert policy["Content"] == json.dumps(policy_doc01) @mock_organizations @@ -650,10 +651,10 @@ def test_create_policy_errors(): # then ex = e.value - ex.operation_name.should.equal("CreatePolicy") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "CreatePolicy" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations @@ -668,37 +669,35 @@ def test_describe_policy(): )["Policy"]["PolicySummary"]["Id"] policy = client.describe_policy(PolicyId=policy_id)["Policy"] validate_service_control_policy(org, policy) - policy["PolicySummary"]["Name"].should.equal("MockServiceControlPolicy") - policy["PolicySummary"]["Description"].should.equal( - "A dummy service control policy" - ) - policy["Content"].should.equal(json.dumps(policy_doc01)) + assert policy["PolicySummary"]["Name"] == "MockServiceControlPolicy" + assert policy["PolicySummary"]["Description"] == "A dummy service control policy" + assert policy["Content"] == json.dumps(policy_doc01) @mock_organizations def test_describe_policy_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] policy_id = "p-47fhe9s3" with pytest.raises(ClientError) as e: client.describe_policy(PolicyId=policy_id) ex = e.value - ex.operation_name.should.equal("DescribePolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain("PolicyNotFoundException") + assert ex.operation_name == "DescribePolicy" + assert ex.response["Error"]["Code"] == "400" + assert "PolicyNotFoundException" in ex.response["Error"]["Message"] with pytest.raises(ClientError) as e: client.describe_policy(PolicyId="meaninglessstring") ex = e.value - ex.operation_name.should.equal("DescribePolicy") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "DescribePolicy" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations def test_attach_policy(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou_id = client.create_organizational_unit(ParentId=root_id, Name="ou01")[ "OrganizationalUnit" @@ -713,17 +712,17 @@ def test_attach_policy(): Type="SERVICE_CONTROL_POLICY", )["Policy"]["PolicySummary"]["Id"] response = client.attach_policy(PolicyId=policy_id, TargetId=root_id) - response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 response = client.attach_policy(PolicyId=policy_id, TargetId=ou_id) - response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 response = client.attach_policy(PolicyId=policy_id, TargetId=account_id) - response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 @mock_organizations def test_detach_policy(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou_id = client.create_organizational_unit(ParentId=root_id, Name="ou01")[ "OrganizationalUnit" @@ -740,17 +739,22 @@ def test_detach_policy(): # Attach/List/Detach policy for name, target in [("OU", ou_id), ("Root", root_id), ("Account", account_id)]: # - with sure.ensure("We should start with 0 policies"): - get_nonaws_policies(target, client).should.have.length_of(0) + assert ( + len(get_nonaws_policies(target, client)) == 0 + ), "We should start with 0 policies" + # client.attach_policy(PolicyId=policy_id, TargetId=target) - with sure.ensure("Expecting 1 policy after creation of target={0}", name): - get_nonaws_policies(target, client).should.have.length_of(1) + assert ( + len(get_nonaws_policies(target, client)) == 1 + ), f"Expecting 1 policy after creation of target={name}" + # response = client.detach_policy(PolicyId=policy_id, TargetId=target) - response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) - with sure.ensure("Expecting 0 policies after deletion of target={0}", name): - get_nonaws_policies(target, client).should.have.length_of(0) + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 + assert ( + len(get_nonaws_policies(target, client)) == 0 + ), f"Expecting 0 policies after deletion of target={name}" def get_nonaws_policies(account_id, client): @@ -766,9 +770,9 @@ def get_nonaws_policies(account_id, client): @mock_organizations def test_detach_policy_root_ou_not_found_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] - client.create_organizational_unit(ParentId=root_id, Name="ou01")[ + _ = client.create_organizational_unit(ParentId=root_id, Name="ou01")[ "OrganizationalUnit" ]["Id"] account_id = client.create_account(AccountName=mockname, Email=mockemail)[ @@ -785,17 +789,15 @@ def test_detach_policy_root_ou_not_found_exception(): with pytest.raises(ClientError) as e: client.detach_policy(PolicyId=policy_id, TargetId="r-xy85") ex = e.value - ex.operation_name.should.equal("DetachPolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain( - "OrganizationalUnitNotFoundException" - ) + assert ex.operation_name == "DetachPolicy" + assert ex.response["Error"]["Code"] == "400" + assert "OrganizationalUnitNotFoundException" in ex.response["Error"]["Message"] @mock_organizations def test_detach_policy_ou_not_found_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou_id = client.create_organizational_unit(ParentId=root_id, Name="ou01")[ "OrganizationalUnit" @@ -810,17 +812,15 @@ def test_detach_policy_ou_not_found_exception(): with pytest.raises(ClientError) as e: client.detach_policy(PolicyId=policy_id, TargetId="ou-zx86-z3x4yr2t7") ex = e.value - ex.operation_name.should.equal("DetachPolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain( - "OrganizationalUnitNotFoundException" - ) + assert ex.operation_name == "DetachPolicy" + assert ex.response["Error"]["Code"] == "400" + assert "OrganizationalUnitNotFoundException" in ex.response["Error"]["Message"] @mock_organizations def test_detach_policy_account_id_not_found_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] account_id = client.create_account(AccountName=mockname, Email=mockemail)[ "CreateAccountStatus" ]["AccountId"] @@ -834,10 +834,10 @@ def test_detach_policy_account_id_not_found_exception(): with pytest.raises(ClientError) as e: client.detach_policy(PolicyId=policy_id, TargetId="111619863336") ex = e.value - ex.operation_name.should.equal("DetachPolicy") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DetachPolicy" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an account that doesn't exist." ) @@ -845,7 +845,7 @@ def test_detach_policy_account_id_not_found_exception(): @mock_organizations def test_detach_policy_invalid_target_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou_id = client.create_organizational_unit(ParentId=root_id, Name="ou01")[ "OrganizationalUnit" @@ -860,18 +860,18 @@ def test_detach_policy_invalid_target_exception(): with pytest.raises(ClientError) as e: client.detach_policy(PolicyId=policy_id, TargetId="invalidtargetid") ex = e.value - ex.operation_name.should.equal("DetachPolicy") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "DetachPolicy" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations def test_delete_policy(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] base_policies = client.list_policies(Filter="SERVICE_CONTROL_POLICY")["Policies"] - base_policies.should.have.length_of(1) + assert len(base_policies) == 1 policy_id = client.create_policy( Content=json.dumps(policy_doc01), Description="A dummy service control policy", @@ -879,25 +879,25 @@ def test_delete_policy(): Type="SERVICE_CONTROL_POLICY", )["Policy"]["PolicySummary"]["Id"] new_policies = client.list_policies(Filter="SERVICE_CONTROL_POLICY")["Policies"] - new_policies.should.have.length_of(2) + assert len(new_policies) == 2 response = client.delete_policy(PolicyId=policy_id) - response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 new_policies = client.list_policies(Filter="SERVICE_CONTROL_POLICY")["Policies"] - new_policies.should.equal(base_policies) - new_policies.should.have.length_of(1) + assert new_policies == base_policies + assert len(new_policies) == 1 @mock_organizations def test_delete_policy_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] non_existent_policy_id = utils.make_random_policy_id() with pytest.raises(ClientError) as e: client.delete_policy(PolicyId=non_existent_policy_id) ex = e.value - ex.operation_name.should.equal("DeletePolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain("PolicyNotFoundException") + assert ex.operation_name == "DeletePolicy" + assert ex.response["Error"]["Code"] == "400" + assert "PolicyNotFoundException" in ex.response["Error"]["Message"] # Attempt to delete an attached policy policy_id = client.create_policy( @@ -911,15 +911,15 @@ def test_delete_policy_exception(): with pytest.raises(ClientError) as e: client.delete_policy(PolicyId=policy_id) ex = e.value - ex.operation_name.should.equal("DeletePolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain("PolicyInUseException") + assert ex.operation_name == "DeletePolicy" + assert ex.response["Error"]["Code"] == "400" + assert "PolicyInUseException" in ex.response["Error"]["Message"] @mock_organizations def test_attach_policy_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = "r-dj873" ou_id = "ou-gi99-i7r8eh2i2" account_id = "126644886543" @@ -932,35 +932,31 @@ def test_attach_policy_exception(): with pytest.raises(ClientError) as e: client.attach_policy(PolicyId=policy_id, TargetId=root_id) ex = e.value - ex.operation_name.should.equal("AttachPolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain( - "OrganizationalUnitNotFoundException" - ) + assert ex.operation_name == "AttachPolicy" + assert ex.response["Error"]["Code"] == "400" + assert "OrganizationalUnitNotFoundException" in ex.response["Error"]["Message"] with pytest.raises(ClientError) as e: client.attach_policy(PolicyId=policy_id, TargetId=ou_id) ex = e.value - ex.operation_name.should.equal("AttachPolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain( - "OrganizationalUnitNotFoundException" - ) + assert ex.operation_name == "AttachPolicy" + assert ex.response["Error"]["Code"] == "400" + assert "OrganizationalUnitNotFoundException" in ex.response["Error"]["Message"] with pytest.raises(ClientError) as e: client.attach_policy(PolicyId=policy_id, TargetId=account_id) ex = e.value - ex.operation_name.should.equal("AttachPolicy") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "AttachPolicy" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an account that doesn't exist." ) with pytest.raises(ClientError) as e: client.attach_policy(PolicyId=policy_id, TargetId="meaninglessstring") ex = e.value - ex.operation_name.should.equal("AttachPolicy") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "AttachPolicy" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations @@ -968,37 +964,37 @@ def test_update_policy(): client = boto3.client("organizations", region_name="us-east-1") org = client.create_organization(FeatureSet="ALL")["Organization"] - policy_dict = dict( - Content=json.dumps(policy_doc01), - Description="A dummy service control policy", - Name="MockServiceControlPolicy", - Type="SERVICE_CONTROL_POLICY", - ) + policy_dict = { + "Content": json.dumps(policy_doc01), + "Description": "A dummy service control policy", + "Name": "MockServiceControlPolicy", + "Type": "SERVICE_CONTROL_POLICY", + } policy_id = client.create_policy(**policy_dict)["Policy"]["PolicySummary"]["Id"] for key in ("Description", "Name"): response = client.update_policy(**{"PolicyId": policy_id, key: "foobar"}) policy = client.describe_policy(PolicyId=policy_id) - policy["Policy"]["PolicySummary"][key].should.equal("foobar") + assert policy["Policy"]["PolicySummary"][key] == "foobar" validate_service_control_policy(org, response["Policy"]) response = client.update_policy(PolicyId=policy_id, Content="foobar") policy = client.describe_policy(PolicyId=policy_id) - policy["Policy"]["Content"].should.equal("foobar") + assert policy["Policy"]["Content"] == "foobar" validate_service_control_policy(org, response["Policy"]) @mock_organizations def test_update_policy_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] non_existent_policy_id = utils.make_random_policy_id() with pytest.raises(ClientError) as e: client.update_policy(PolicyId=non_existent_policy_id) ex = e.value - ex.operation_name.should.equal("UpdatePolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain("PolicyNotFoundException") + assert ex.operation_name == "UpdatePolicy" + assert ex.response["Error"]["Code"] == "400" + assert "PolicyNotFoundException" in ex.response["Error"]["Message"] @mock_organizations @@ -1051,27 +1047,25 @@ def test_list_policies_for_target(): @mock_organizations def test_list_policies_for_target_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou_id = "ou-gi99-i7r8eh2i2" account_id = "126644886543" with pytest.raises(ClientError) as e: client.list_policies_for_target(TargetId=ou_id, Filter="SERVICE_CONTROL_POLICY") ex = e.value - ex.operation_name.should.equal("ListPoliciesForTarget") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain( - "OrganizationalUnitNotFoundException" - ) + assert ex.operation_name == "ListPoliciesForTarget" + assert ex.response["Error"]["Code"] == "400" + assert "OrganizationalUnitNotFoundException" in ex.response["Error"]["Message"] with pytest.raises(ClientError) as e: client.list_policies_for_target( TargetId=account_id, Filter="SERVICE_CONTROL_POLICY" ) ex = e.value - ex.operation_name.should.equal("ListPoliciesForTarget") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "ListPoliciesForTarget" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an account that doesn't exist." ) with pytest.raises(ClientError) as e: @@ -1079,10 +1073,10 @@ def test_list_policies_for_target_exception(): TargetId="meaninglessstring", Filter="SERVICE_CONTROL_POLICY" ) ex = e.value - ex.operation_name.should.equal("ListPoliciesForTarget") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "ListPoliciesForTarget" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." # not existing root # when @@ -1093,10 +1087,10 @@ def test_list_policies_for_target_exception(): # then ex = e.value - ex.operation_name.should.equal("ListPoliciesForTarget") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("TargetNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "ListPoliciesForTarget" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "TargetNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified a target that doesn't exist." ) @@ -1107,16 +1101,16 @@ def test_list_policies_for_target_exception(): # then ex = e.value - ex.operation_name.should.equal("ListPoliciesForTarget") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "ListPoliciesForTarget" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations def test_list_targets_for_policy(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] root_id = client.list_roots()["Roots"][0]["Id"] ou_id = client.create_organizational_unit(ParentId=root_id, Name="ou01")[ "OrganizationalUnit" @@ -1135,33 +1129,31 @@ def test_list_targets_for_policy(): client.attach_policy(PolicyId=policy_id, TargetId=account_id) response = client.list_targets_for_policy(PolicyId=policy_id) for target in response["Targets"]: - target.should.be.a(dict) - target.should.have.key("Name").should.be.a(str) - target.should.have.key("Arn").should.be.a(str) - target.should.have.key("TargetId").should.be.a(str) - target.should.have.key("Type").should.be.within( - ["ROOT", "ORGANIZATIONAL_UNIT", "ACCOUNT"] - ) + assert isinstance(target, dict) + assert isinstance(target["Name"], str) + assert isinstance(target["Arn"], str) + assert isinstance(target["TargetId"], str) + assert target["Type"] in ["ROOT", "ORGANIZATIONAL_UNIT", "ACCOUNT"] @mock_organizations def test_list_targets_for_policy_exception(): client = boto3.client("organizations", region_name="us-east-1") - client.create_organization(FeatureSet="ALL")["Organization"] + _ = client.create_organization(FeatureSet="ALL")["Organization"] policy_id = "p-47fhe9s3" with pytest.raises(ClientError) as e: client.list_targets_for_policy(PolicyId=policy_id) ex = e.value - ex.operation_name.should.equal("ListTargetsForPolicy") - ex.response["Error"]["Code"].should.equal("400") - ex.response["Error"]["Message"].should.contain("PolicyNotFoundException") + assert ex.operation_name == "ListTargetsForPolicy" + assert ex.response["Error"]["Code"] == "400" + assert "PolicyNotFoundException" in ex.response["Error"]["Message"] with pytest.raises(ClientError) as e: client.list_targets_for_policy(PolicyId="meaninglessstring") ex = e.value - ex.operation_name.should.equal("ListTargetsForPolicy") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "ListTargetsForPolicy" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations @@ -1175,7 +1167,7 @@ def test_tag_resource_account(): client.tag_resource(ResourceId=resource_id, Tags=[{"Key": "key", "Value": "value"}]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "value"}] # adding a tag with an existing key, will update the value client.tag_resource( @@ -1183,12 +1175,12 @@ def test_tag_resource_account(): ) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "new-value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "new-value"}] client.untag_resource(ResourceId=resource_id, TagKeys=["key"]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([]) + assert response["Tags"] == [] @mock_organizations @@ -1200,7 +1192,7 @@ def test_tag_resource_organization_organization_root(): client.tag_resource(ResourceId=resource_id, Tags=[{"Key": "key", "Value": "value"}]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "value"}] # adding a tag with an existing key, will update the value client.tag_resource( @@ -1208,12 +1200,12 @@ def test_tag_resource_organization_organization_root(): ) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "new-value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "new-value"}] client.untag_resource(ResourceId=resource_id, TagKeys=["key"]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([]) + assert response["Tags"] == [] @mock_organizations @@ -1228,7 +1220,7 @@ def test_tag_resource_organization_organizational_unit(): client.tag_resource(ResourceId=resource_id, Tags=[{"Key": "key", "Value": "value"}]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "value"}] # adding a tag with an existing key, will update the value client.tag_resource( @@ -1236,12 +1228,12 @@ def test_tag_resource_organization_organizational_unit(): ) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "new-value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "new-value"}] client.untag_resource(ResourceId=resource_id, TagKeys=["key"]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([]) + assert response["Tags"] == [] @mock_organizations @@ -1260,7 +1252,7 @@ def test_tag_resource_policy(): client.tag_resource(ResourceId=resource_id, Tags=[{"Key": "key", "Value": "value"}]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "value"}] # adding a tag with an existing key, will update the value client.tag_resource( @@ -1268,12 +1260,12 @@ def test_tag_resource_policy(): ) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([{"Key": "key", "Value": "new-value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "new-value"}] client.untag_resource(ResourceId=resource_id, TagKeys=["key"]) response = client.list_tags_for_resource(ResourceId=resource_id) - response["Tags"].should.equal([]) + assert response["Tags"] == [] @mock_organizations @@ -1286,10 +1278,10 @@ def test_tag_resource_errors(): ResourceId="0A000000X000", Tags=[{"Key": "key", "Value": "value"}] ) ex = e.value - ex.operation_name.should.equal("TagResource") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "TagResource" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You provided a value that does not match the required pattern." ) with pytest.raises(ClientError) as e: @@ -1297,11 +1289,11 @@ def test_tag_resource_errors(): ResourceId="000000000000", Tags=[{"Key": "key", "Value": "value"}] ) ex = e.value - ex.operation_name.should.equal("TagResource") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("TargetNotFoundException") - ex.response["Error"]["Message"].should.equal( - "You specified a target that doesn't exist." + assert ex.operation_name == "TagResource" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "TargetNotFoundException" in ex.response["Error"]["Code"] + assert ( + ex.response["Error"]["Message"] == "You specified a target that doesn't exist." ) @@ -1312,7 +1304,7 @@ def test__get_resource_for_tagging_existing_root(): org_backend = OrganizationsBackend(region_name="N/A", account_id="N/A") org_backend.ou.append(root) response = org_backend._get_resource_for_tagging(root.id) - response.id.should.equal(root.id) + assert response.id == root.id def test__get_resource_for_tagging_existing_non_root(): @@ -1320,9 +1312,9 @@ def test__get_resource_for_tagging_existing_non_root(): with pytest.raises(TargetNotFoundException) as e: org_backend._get_resource_for_tagging("r-abcd") ex = e.value - ex.code.should.equal(400) - ex.description.should.contain("TargetNotFoundException") - ex.message.should.equal("You specified a target that doesn't exist.") + assert ex.code == 400 + assert "TargetNotFoundException" in ex.description + assert ex.message == "You specified a target that doesn't exist." def test__get_resource_for_tagging_existing_ou(): @@ -1332,7 +1324,7 @@ def test__get_resource_for_tagging_existing_ou(): org_backend.ou.append(ou) response = org_backend._get_resource_for_tagging(ou.id) - response.id.should.equal(ou.id) + assert response.id == ou.id def test__get_resource_for_tagging_non_existing_ou(): @@ -1340,9 +1332,9 @@ def test__get_resource_for_tagging_non_existing_ou(): with pytest.raises(TargetNotFoundException) as e: org_backend._get_resource_for_tagging("ou-9oyc-lv2q36ln") ex = e.value - ex.code.should.equal(400) - ex.description.should.contain("TargetNotFoundException") - ex.message.should.equal("You specified a target that doesn't exist.") + assert ex.code == 400 + assert "TargetNotFoundException" in ex.description + assert ex.message == "You specified a target that doesn't exist." def test__get_resource_for_tagging_existing_account(): @@ -1352,7 +1344,7 @@ def test__get_resource_for_tagging_existing_account(): org_backend.accounts.append(account) response = org_backend._get_resource_for_tagging(account.id) - response.id.should.equal(account.id) + assert response.id == account.id def test__get_resource_for_tagging_non_existing_account(): @@ -1360,9 +1352,9 @@ def test__get_resource_for_tagging_non_existing_account(): with pytest.raises(TargetNotFoundException) as e: org_backend._get_resource_for_tagging("100326223992") ex = e.value - ex.code.should.equal(400) - ex.description.should.contain("TargetNotFoundException") - ex.message.should.equal("You specified a target that doesn't exist.") + assert ex.code == 400 + assert "TargetNotFoundException" in ex.description + assert ex.message == "You specified a target that doesn't exist." def test__get_resource_for_tagging_existing_policy(): @@ -1372,7 +1364,7 @@ def test__get_resource_for_tagging_existing_policy(): org_backend.policies.append(policy) response = org_backend._get_resource_for_tagging(policy.id) - response.id.should.equal(policy.id) + assert response.id == policy.id def test__get_resource_for_tagging_non_existing_policy(): @@ -1380,9 +1372,9 @@ def test__get_resource_for_tagging_non_existing_policy(): with pytest.raises(TargetNotFoundException) as e: org_backend._get_resource_for_tagging("p-y1vas4da") ex = e.value - ex.code.should.equal(400) - ex.description.should.contain("TargetNotFoundException") - ex.message.should.equal("You specified a target that doesn't exist.") + assert ex.code == 400 + assert "TargetNotFoundException" in ex.description + assert ex.message == "You specified a target that doesn't exist." def test__get_resource_to_tag_incorrect_resource(): @@ -1390,9 +1382,9 @@ def test__get_resource_to_tag_incorrect_resource(): with pytest.raises(InvalidInputException) as e: org_backend._get_resource_for_tagging("10032622399200") ex = e.value - ex.code.should.equal(400) - ex.description.should.contain("InvalidInputException") - ex.message.should.equal( + assert ex.code == 400 + assert "InvalidInputException" in ex.description + assert ex.message == ( "You provided a value that does not match the required pattern." ) @@ -1408,7 +1400,7 @@ def test_list_tags_for_resource(): response = client.list_tags_for_resource(ResourceId=account_id) - response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "value"}] @mock_organizations @@ -1419,19 +1411,19 @@ def test_list_tags_for_resource_errors(): with pytest.raises(ClientError) as e: client.list_tags_for_resource(ResourceId="000x00000A00") ex = e.value - ex.operation_name.should.equal("ListTagsForResource") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "ListTagsForResource" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You provided a value that does not match the required pattern." ) with pytest.raises(ClientError) as e: client.list_tags_for_resource(ResourceId="000000000000") ex = e.value - ex.operation_name.should.equal("ListTagsForResource") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("TargetNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "ListTagsForResource" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "TargetNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified a target that doesn't exist." ) @@ -1445,16 +1437,16 @@ def test_untag_resource(): ]["AccountId"] client.tag_resource(ResourceId=account_id, Tags=[{"Key": "key", "Value": "value"}]) response = client.list_tags_for_resource(ResourceId=account_id) - response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "value"}] # removing a non existing tag should not raise any error client.untag_resource(ResourceId=account_id, TagKeys=["not-existing"]) response = client.list_tags_for_resource(ResourceId=account_id) - response["Tags"].should.equal([{"Key": "key", "Value": "value"}]) + assert response["Tags"] == [{"Key": "key", "Value": "value"}] client.untag_resource(ResourceId=account_id, TagKeys=["key"]) response = client.list_tags_for_resource(ResourceId=account_id) - response["Tags"].should.have.length_of(0) + assert len(response["Tags"]) == 0 @mock_organizations @@ -1465,20 +1457,20 @@ def test_untag_resource_errors(): with pytest.raises(ClientError) as e: client.untag_resource(ResourceId="0X00000000A0", TagKeys=["key"]) ex = e.value - ex.operation_name.should.equal("UntagResource") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "UntagResource" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You provided a value that does not match the required pattern." ) with pytest.raises(ClientError) as e: client.untag_resource(ResourceId="000000000000", TagKeys=["key"]) ex = e.value - ex.operation_name.should.equal("UntagResource") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("TargetNotFoundException") - ex.response["Error"]["Message"].should.equal( - "You specified a target that doesn't exist." + assert ex.operation_name == "UntagResource" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "TargetNotFoundException" in ex.response["Error"]["Code"] + assert ( + ex.response["Error"]["Message"] == "You specified a target that doesn't exist." ) @@ -1490,13 +1482,13 @@ def test_update_organizational_unit(): ou_name = "ou01" response = client.create_organizational_unit(ParentId=root_id, Name=ou_name) validate_organizational_unit(org, response) - response["OrganizationalUnit"]["Name"].should.equal(ou_name) + assert response["OrganizationalUnit"]["Name"] == ou_name new_ou_name = "ou02" response = client.update_organizational_unit( OrganizationalUnitId=response["OrganizationalUnit"]["Id"], Name=new_ou_name ) validate_organizational_unit(org, response) - response["OrganizationalUnit"]["Name"].should.equal(new_ou_name) + assert response["OrganizationalUnit"]["Name"] == new_ou_name @mock_organizations @@ -1507,16 +1499,16 @@ def test_update_organizational_unit_duplicate_error(): ou_name = "ou01" response = client.create_organizational_unit(ParentId=root_id, Name=ou_name) validate_organizational_unit(org, response) - response["OrganizationalUnit"]["Name"].should.equal(ou_name) + assert response["OrganizationalUnit"]["Name"] == ou_name with pytest.raises(ClientError) as e: client.update_organizational_unit( OrganizationalUnitId=response["OrganizationalUnit"]["Id"], Name=ou_name ) exc = e.value - exc.operation_name.should.equal("UpdateOrganizationalUnit") - exc.response["Error"]["Code"].should.contain("DuplicateOrganizationalUnitException") - exc.response["Error"]["Message"].should.equal( - "An OU with the same name already exists." + assert exc.operation_name == "UpdateOrganizationalUnit" + assert "DuplicateOrganizationalUnitException" in exc.response["Error"]["Code"] + assert ( + exc.response["Error"]["Message"] == "An OU with the same name already exists." ) @@ -1531,11 +1523,11 @@ def test_enable_aws_service_access(): # then response = client.list_aws_service_access_for_organization() - response["EnabledServicePrincipals"].should.have.length_of(1) + assert len(response["EnabledServicePrincipals"]) == 1 service = response["EnabledServicePrincipals"][0] - service["ServicePrincipal"].should.equal("config.amazonaws.com") + assert service["ServicePrincipal"] == "config.amazonaws.com" date_enabled = service["DateEnabled"] - date_enabled.should.be.a(datetime) + assert isinstance(date_enabled, datetime) # enabling the same service again should not result in any error or change # when @@ -1543,10 +1535,10 @@ def test_enable_aws_service_access(): # then response = client.list_aws_service_access_for_organization() - response["EnabledServicePrincipals"].should.have.length_of(1) + assert len(response["EnabledServicePrincipals"]) == 1 service = response["EnabledServicePrincipals"][0] - service["ServicePrincipal"].should.equal("config.amazonaws.com") - service["DateEnabled"].should.equal(date_enabled) + assert service["ServicePrincipal"] == "config.amazonaws.com" + assert service["DateEnabled"] == date_enabled @mock_organizations @@ -1557,10 +1549,10 @@ def test_enable_aws_service_access_error(): with pytest.raises(ClientError) as e: client.enable_aws_service_access(ServicePrincipal="moto.amazonaws.com") ex = e.value - ex.operation_name.should.equal("EnableAWSServiceAccess") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "EnableAWSServiceAccess" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an unrecognized service principal." ) @@ -1577,14 +1569,14 @@ def test_enable_multiple_aws_service_access(): response = client.list_aws_service_access_for_organization() # then - response["EnabledServicePrincipals"].should.have.length_of(2) + assert len(response["EnabledServicePrincipals"]) == 2 services = sorted( response["EnabledServicePrincipals"], key=lambda i: i["ServicePrincipal"] ) - services[0]["ServicePrincipal"].should.equal("config.amazonaws.com") - services[0]["DateEnabled"].should.be.a(datetime) - services[1]["ServicePrincipal"].should.equal("ram.amazonaws.com") - services[1]["DateEnabled"].should.be.a(datetime) + assert services[0]["ServicePrincipal"] == "config.amazonaws.com" + assert isinstance(services[0]["DateEnabled"], datetime) + assert services[1]["ServicePrincipal"] == "ram.amazonaws.com" + assert isinstance(services[1]["DateEnabled"], datetime) @mock_organizations @@ -1599,7 +1591,7 @@ def test_disable_aws_service_access(): # then response = client.list_aws_service_access_for_organization() - response["EnabledServicePrincipals"].should.have.length_of(0) + assert len(response["EnabledServicePrincipals"]) == 0 # disabling the same service again should not result in any error # when @@ -1607,7 +1599,7 @@ def test_disable_aws_service_access(): # then response = client.list_aws_service_access_for_organization() - response["EnabledServicePrincipals"].should.have.length_of(0) + assert len(response["EnabledServicePrincipals"]) == 0 @mock_organizations @@ -1618,10 +1610,10 @@ def test_disable_aws_service_access_errors(): with pytest.raises(ClientError) as e: client.disable_aws_service_access(ServicePrincipal="moto.amazonaws.com") ex = e.value - ex.operation_name.should.equal("DisableAWSServiceAccess") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DisableAWSServiceAccess" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an unrecognized service principal." ) @@ -1642,18 +1634,18 @@ def test_register_delegated_administrator(): # then response = client.list_delegated_administrators() - response["DelegatedAdministrators"].should.have.length_of(1) + assert len(response["DelegatedAdministrators"]) == 1 admin = response["DelegatedAdministrators"][0] - admin["Id"].should.equal(account_id) - admin["Arn"].should.equal( + assert admin["Id"] == account_id + assert admin["Arn"] == ( f"arn:aws:organizations::{ACCOUNT_ID}:account/{org_id}/{account_id}" ) - admin["Email"].should.equal(mockemail) - admin["Name"].should.equal(mockname) - admin["Status"].should.equal("ACTIVE") - admin["JoinedMethod"].should.equal("CREATED") - admin["JoinedTimestamp"].should.be.a(datetime) - admin["DelegationEnabledDate"].should.be.a(datetime) + assert admin["Email"] == mockemail + assert admin["Name"] == mockname + assert admin["Status"] == "ACTIVE" + assert admin["JoinedMethod"] == "CREATED" + assert isinstance(admin["JoinedTimestamp"], datetime) + assert isinstance(admin["DelegationEnabledDate"], datetime) @mock_organizations @@ -1677,11 +1669,12 @@ def test_register_delegated_administrator_errors(): # then ex = e.value - ex.operation_name.should.equal("RegisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("ConstraintViolationException") - ex.response["Error"]["Message"].should.equal( - "You cannot register master account/yourself as delegated administrator for your organization." + assert ex.operation_name == "RegisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "ConstraintViolationException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( + "You cannot register master account/yourself as delegated " + "administrator for your organization." ) # register not existing Account @@ -1693,11 +1686,12 @@ def test_register_delegated_administrator_errors(): # then ex = e.value - ex.operation_name.should.equal("RegisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotFoundException") - ex.response["Error"]["Message"].should.equal( - "You specified an account that doesn't exist." + assert ex.operation_name == "RegisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotFoundException" in ex.response["Error"]["Code"] + assert ( + ex.response["Error"]["Message"] + == "You specified an account that doesn't exist." ) # register not supported service @@ -1709,10 +1703,10 @@ def test_register_delegated_administrator_errors(): # then ex = e.value - ex.operation_name.should.equal("RegisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "RegisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an unrecognized service principal." ) @@ -1725,10 +1719,10 @@ def test_register_delegated_administrator_errors(): # then ex = e.value - ex.operation_name.should.equal("RegisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountAlreadyRegisteredException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "RegisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountAlreadyRegisteredException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "The provided account is already a delegated administrator for your organization." ) @@ -1755,8 +1749,8 @@ def test_list_delegated_administrators(): response = client.list_delegated_administrators() # then - response["DelegatedAdministrators"].should.have.length_of(2) - sorted([admin["Id"] for admin in response["DelegatedAdministrators"]]).should.equal( + assert len(response["DelegatedAdministrators"]) == 2 + assert sorted([admin["Id"] for admin in response["DelegatedAdministrators"]]) == ( sorted([account_id_1, account_id_2]) ) @@ -1766,18 +1760,18 @@ def test_list_delegated_administrators(): ) # then - response["DelegatedAdministrators"].should.have.length_of(1) + assert len(response["DelegatedAdministrators"]) == 1 admin = response["DelegatedAdministrators"][0] - admin["Id"].should.equal(account_id_1) - admin["Arn"].should.equal( + assert admin["Id"] == account_id_1 + assert admin["Arn"] == ( f"arn:aws:organizations::{ACCOUNT_ID}:account/{org_id}/{account_id_1}" ) - admin["Email"].should.equal(mockemail) - admin["Name"].should.equal(mockname) - admin["Status"].should.equal("ACTIVE") - admin["JoinedMethod"].should.equal("CREATED") - admin["JoinedTimestamp"].should.be.a(datetime) - admin["DelegationEnabledDate"].should.be.a(datetime) + assert admin["Email"] == mockemail + assert admin["Name"] == mockname + assert admin["Status"] == "ACTIVE" + assert admin["JoinedMethod"] == "CREATED" + assert isinstance(admin["JoinedTimestamp"], datetime) + assert isinstance(admin["DelegationEnabledDate"], datetime) @mock_organizations @@ -1793,10 +1787,10 @@ def test_list_delegated_administrators_erros(): # then ex = e.value - ex.operation_name.should.equal("ListDelegatedAdministrators") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "ListDelegatedAdministrators" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an unrecognized service principal." ) @@ -1820,10 +1814,10 @@ def test_list_delegated_services_for_account(): response = client.list_delegated_services_for_account(AccountId=account_id) # then - response["DelegatedServices"].should.have.length_of(2) - sorted( + assert len(response["DelegatedServices"]) == 2 + assert sorted( [service["ServicePrincipal"] for service in response["DelegatedServices"]] - ).should.equal(["guardduty.amazonaws.com", "ssm.amazonaws.com"]) + ) == ["guardduty.amazonaws.com", "ssm.amazonaws.com"] @mock_organizations @@ -1839,10 +1833,10 @@ def test_list_delegated_services_for_account_erros(): # then ex = e.value - ex.operation_name.should.equal("ListDelegatedServicesForAccount") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AWSOrganizationsNotInUseException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "ListDelegatedServicesForAccount" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AWSOrganizationsNotInUseException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "Your account is not a member of an organization." ) @@ -1853,10 +1847,10 @@ def test_list_delegated_services_for_account_erros(): # then ex = e.value - ex.operation_name.should.equal("ListDelegatedServicesForAccount") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotRegisteredException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "ListDelegatedServicesForAccount" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotRegisteredException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "The provided account is not a registered delegated administrator for your organization." ) @@ -1880,7 +1874,7 @@ def test_deregister_delegated_administrator(): # then response = client.list_delegated_administrators() - response["DelegatedAdministrators"].should.have.length_of(0) + assert len(response["DelegatedAdministrators"]) == 0 @mock_organizations @@ -1901,11 +1895,12 @@ def test_deregister_delegated_administrator_erros(): # then ex = e.value - ex.operation_name.should.equal("DeregisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("ConstraintViolationException") - ex.response["Error"]["Message"].should.equal( - "You cannot register master account/yourself as delegated administrator for your organization." + assert ex.operation_name == "DeregisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "ConstraintViolationException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( + "You cannot register master account/yourself as delegated " + "administrator for your organization." ) # deregister not existing Account @@ -1917,10 +1912,10 @@ def test_deregister_delegated_administrator_erros(): # then ex = e.value - ex.operation_name.should.equal("DeregisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DeregisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an account that doesn't exist." ) @@ -1933,10 +1928,10 @@ def test_deregister_delegated_administrator_erros(): # then ex = e.value - ex.operation_name.should.equal("DeregisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("AccountNotRegisteredException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DeregisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "AccountNotRegisteredException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "The provided account is not a registered delegated administrator for your organization." ) @@ -1954,10 +1949,10 @@ def test_deregister_delegated_administrator_erros(): # then ex = e.value - ex.operation_name.should.equal("DeregisterDelegatedAdministrator") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DeregisterDelegatedAdministrator" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified an unrecognized service principal." ) @@ -1976,12 +1971,12 @@ def test_enable_policy_type(): # then root = response["Root"] - root["Id"].should.equal(root_id) - root["Arn"].should.equal( + assert root["Id"] == root_id + assert root["Arn"] == ( utils.ROOT_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], root_id) ) - root["Name"].should.equal("Root") - sorted(root["PolicyTypes"], key=lambda x: x["Type"]).should.equal( + assert root["Name"] == "Root" + assert sorted(root["PolicyTypes"], key=lambda x: x["Type"]) == ( [{"Type": "AISERVICES_OPT_OUT_POLICY", "Status": "ENABLED"}] ) @@ -2002,10 +1997,10 @@ def test_enable_policy_type_errors(): # then ex = e.value - ex.operation_name.should.equal("EnablePolicyType") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("RootNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "EnablePolicyType" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "RootNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified a root that doesn't exist." ) @@ -2019,10 +2014,10 @@ def test_enable_policy_type_errors(): # then ex = e.value - ex.operation_name.should.equal("EnablePolicyType") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("PolicyTypeAlreadyEnabledException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "EnablePolicyType" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "PolicyTypeAlreadyEnabledException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "The specified policy type is already enabled." ) @@ -2033,10 +2028,10 @@ def test_enable_policy_type_errors(): # then ex = e.value - ex.operation_name.should.equal("EnablePolicyType") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "EnablePolicyType" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations @@ -2054,12 +2049,12 @@ def test_disable_policy_type(): # then root = response["Root"] - root["Id"].should.equal(root_id) - root["Arn"].should.equal( + assert root["Id"] == root_id + assert root["Arn"] == ( utils.ROOT_ARN_FORMAT.format(org["MasterAccountId"], org["Id"], root_id) ) - root["Name"].should.equal("Root") - root["PolicyTypes"].should.equal([]) + assert root["Name"] == "Root" + assert root["PolicyTypes"] == [] @mock_organizations @@ -2078,10 +2073,10 @@ def test_disable_policy_type_errors(): # then ex = e.value - ex.operation_name.should.equal("DisablePolicyType") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("RootNotFoundException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DisablePolicyType" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "RootNotFoundException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "You specified a root that doesn't exist." ) @@ -2094,10 +2089,10 @@ def test_disable_policy_type_errors(): # then ex = e.value - ex.operation_name.should.equal("DisablePolicyType") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("PolicyTypeNotEnabledException") - ex.response["Error"]["Message"].should.equal( + assert ex.operation_name == "DisablePolicyType" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "PolicyTypeNotEnabledException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == ( "This operation can be performed only for enabled policy types." ) @@ -2108,10 +2103,10 @@ def test_disable_policy_type_errors(): # then ex = e.value - ex.operation_name.should.equal("DisablePolicyType") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.response["Error"]["Code"].should.contain("InvalidInputException") - ex.response["Error"]["Message"].should.equal("You specified an invalid value.") + assert ex.operation_name == "DisablePolicyType" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert "InvalidInputException" in ex.response["Error"]["Code"] + assert ex.response["Error"]["Message"] == "You specified an invalid value." @mock_organizations @@ -2145,17 +2140,17 @@ def test_aiservices_opt_out_policy(): # then summary = response["Policy"]["PolicySummary"] policy_id = summary["Id"] - summary["Id"].should.match(utils.POLICY_ID_REGEX) - summary["Arn"].should.equal( + assert re.match(utils.POLICY_ID_REGEX, summary["Id"]) + assert summary["Arn"] == ( utils.AI_POLICY_ARN_FORMAT.format( org["MasterAccountId"], org["Id"], summary["Id"] ) ) - summary["Name"].should.equal("ai-opt-out") - summary["Description"].should.equal("Opt out of all AI services") - summary["Type"].should.equal("AISERVICES_OPT_OUT_POLICY") - summary["AwsManaged"].should.equal(False) - json.loads(response["Policy"]["Content"]).should.equal(ai_policy) + assert summary["Name"] == "ai-opt-out" + assert summary["Description"] == "Opt out of all AI services" + assert summary["Type"] == "AISERVICES_OPT_OUT_POLICY" + assert summary["AwsManaged"] is False + assert json.loads(response["Policy"]["Content"]) == ai_policy # when client.attach_policy(PolicyId=policy_id, TargetId=root_id) @@ -2164,5 +2159,5 @@ def test_aiservices_opt_out_policy(): response = client.list_policies_for_target( TargetId=root_id, Filter="AISERVICES_OPT_OUT_POLICY" ) - response["Policies"].should.have.length_of(1) - response["Policies"][0]["Id"].should.equal(policy_id) + assert len(response["Policies"]) == 1 + assert response["Policies"][0]["Id"] == policy_id