def test_delete_policy_exception(): client = boto3.client("organizations", region_name="us-east-1") org = client.create_organization(FeatureSet="ALL")["Organization"] non_existent_policy_id = utils.make_random_service_control_policy_id() with assert_raises(ClientError) as e: response = client.delete_policy(PolicyId=non_existent_policy_id) ex = e.exception ex.operation_name.should.equal("DeletePolicy") ex.response["Error"]["Code"].should.equal("400") ex.response["Error"]["Message"].should.contain("PolicyNotFoundException") # Attempt to delete an attached policy policy_id = client.create_policy( Content=json.dumps(policy_doc01), Description="A dummy service control policy", Name="MockServiceControlPolicy", Type="SERVICE_CONTROL_POLICY", )["Policy"]["PolicySummary"]["Id"] root_id = client.list_roots()["Roots"][0]["Id"] client.attach_policy(PolicyId=policy_id, TargetId=root_id) with assert_raises(ClientError) as e: response = client.delete_policy(PolicyId=policy_id) ex = e.exception ex.operation_name.should.equal("DeletePolicy") ex.response["Error"]["Code"].should.equal("400") ex.response["Error"]["Message"].should.contain("PolicyInUseException")
def test_update_policy_exception(): client = boto3.client("organizations", region_name="us-east-1") org = client.create_organization(FeatureSet="ALL")["Organization"] non_existent_policy_id = utils.make_random_service_control_policy_id() with assert_raises(ClientError) as e: response = client.update_policy(PolicyId=non_existent_policy_id) ex = e.exception ex.operation_name.should.equal("UpdatePolicy") ex.response["Error"]["Code"].should.equal("400") ex.response["Error"]["Message"].should.contain("PolicyNotFoundException")
def __init__(self, organization, **kwargs): self.content = kwargs.get('Content') self.description = kwargs.get('Description') self.name = kwargs.get('Name') self.type = kwargs.get('Type') self.id = utils.make_random_service_control_policy_id() self.aws_managed = False self.organization_id = organization.id self.master_account_id = organization.master_account_id self._arn_format = utils.SCP_ARN_FORMAT self.attachments = []
def __init__(self, organization, **kwargs): self.type = 'POLICY' self.content = kwargs.get('Content') self.description = kwargs.get('Description') self.name = kwargs.get('Name') self.type = kwargs.get('Type') self.id = utils.make_random_service_control_policy_id() self.aws_managed = False self.organization_id = organization.id self.master_account_id = organization.master_account_id self._arn_format = utils.SCP_ARN_FORMAT self.attachments = []
def test_make_random_service_control_policy_id(): service_control_policy_id = utils.make_random_service_control_policy_id() service_control_policy_id.should.match(utils.SCP_ID_REGEX)