def test_load(): mock_org = MockOrganization() mock_org.simple() org = orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE) org.clear_cache() assert not os.path.exists(org._cache_dir) assert not os.path.exists(org._cache_file) org.load() assert os.path.exists(org._cache_file) assert org.id == mock_org.org_id assert org.root_id == mock_org.root_id assert len(org.accounts) == 3 assert len(org.org_units) == 6 assert len(org.policies) == 3 for ou in org.org_units: for policy_id in ou.attached_policy_ids: assert policy_id in [p.id for p in org.policies] for account in org.accounts: for policy_id in account.attached_policy_ids: assert policy_id in [p.id for p in org.policies] for policy in org.policies: for target in policy.targets: if target['Type'] == 'ROOT': assert target['TargetId'] == mock_org.root_id elif target['Type'] == 'ORGANIZATIONAL_UNIT': assert target['TargetId'] in [ou.id for ou in org.org_units] elif target['Type'] == 'ACCOUNT': assert target['TargetId'] in [a.id for a in org.accounts] org_from_cache = orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE) org_from_cache.load() assert org.dump() == org_from_cache.dump() org.clear_cache()
def test_simple_build(): mock_org = MockOrganization() mock_org.simple() assert mock_org.spec == yaml.safe_load(SIMPLE_ORG_SPEC) assert len(mock_org.client.list_accounts()['Accounts']) == 3 assert len( mock_org.client.list_policies( Filter='SERVICE_CONTROL_POLICY')['Policies']) == 3 assert len( mock_org.client.list_organizational_units_for_parent( ParentId=mock_org.root_id)['OrganizationalUnits']) == 3
def test_list_accounts_by_name_or_id(): mock_org = MockOrganization() mock_org.simple() org = orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE) org.load() mock_accounts = mock_org.spec['root'][0]['accounts'] response = org.list_accounts_by_name() assert isinstance(response, list) assert len(response) == 3 assert sorted(response) == [a['name'] for a in mock_accounts] response = org.list_accounts_by_id() assert isinstance(response, list) assert len(response) == 3 for account_id in response: assert re.compile(r'[0-9]{12}').match(account_id) org.clear_cache()
def test_dump_accounts(): mock_org = MockOrganization() mock_org.simple() org = orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE) org.load() response = org.dump_accounts() assert isinstance(response, list) assert len(response) == 3 mock_accounts = mock_org.spec['root'][0]['accounts'] for account in response: assert account['master_account_id'] == MASTER_ACCOUNT_ID assert account['organization_id'] == org.id assert account['name'] in [a['name'] for a in mock_accounts] assert re.compile(r'[0-9]{12}').match(account['id']) assert account['parent_id'] == org.root_id assert account['email'] == account['name'] + '@example.com' assert len(account['aliases']) == 0 assert len(account['credentials']) == 0 org.clear_cache()