def test_jsonfmt(): account = orgs.OrgAccount( orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE), name='account01', id='112233445566', email='*****@*****.**', ) output = orgquery.jsonfmt(account) assert isinstance(output, str)
def test_org_objects(): org = orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE) client = org._get_org_client() client.create_organization(FeatureSet='ALL') org._load_client() org._load_org() org_object = orgs.OrgObject(org, name='generic') assert isinstance(org_object, orgs.OrgObject) assert org_object.organization_id == org.id assert org_object.master_account_id == org.master_account_id assert org_object.name == 'generic' policy = orgs.OrgPolicy( org, name='policy01', id='p-fue927ci', ) assert isinstance(policy, orgs.OrgPolicy) assert policy.organization_id == org.id assert policy.master_account_id == org.master_account_id assert policy.name == 'policy01' assert policy.id == 'p-fue927ci' assert isinstance(policy.targets, list) account = orgs.OrgAccount( org, name='account01', id='112233445566', parent_id=org.root_id, email='*****@*****.**', ) assert isinstance(account, orgs.OrgAccount) assert account.organization_id == org.id assert account.master_account_id == org.master_account_id assert account.name == 'account01' assert account.id == '112233445566' assert account.parent_id == org.root_id assert account.email == '*****@*****.**' ou = orgs.OrganizationalUnit( org, name='production', id='o-jfk0', parent_id=org.root_id, ) assert isinstance(ou, orgs.OrganizationalUnit) assert ou.organization_id == org.id assert ou.master_account_id == org.master_account_id assert ou.name == 'production' assert ou.id == 'o-jfk0' assert ou.parent_id == org.root_id
def test_yamlfmt(): output = utils.yamlfmt(SIMPLE_ORG_SPEC) assert isinstance(output, str) dt = datetime.datetime.utcnow() output = utils.yamlfmt(dt) assert isinstance(output, str) account = orgs.OrgAccount( orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE), name='account01', id='112233445566', email='*****@*****.**', ) output = utils.yamlfmt(account) assert isinstance(output, str)
def test_crawler_init(): MockOrganization().complex() org = orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE) org.load() crawler = crawlers.Crawler(org) assert isinstance(crawler, crawlers.Crawler) assert isinstance(crawler.org, orgs.Org) assert crawler.access_role == org.access_role assert crawler.accounts == org.accounts assert crawler.regions == ALL_REGIONS crawler = crawlers.Crawler(org, accounts='', regions='') assert crawler.accounts == org.accounts assert crawler.regions == ALL_REGIONS crawler = crawlers.Crawler(org, accounts=[], regions=[]) assert crawler.accounts == org.accounts assert crawler.regions == ALL_REGIONS crawler = crawlers.Crawler(org, accounts=None, regions=None) assert crawler.accounts == org.accounts assert crawler.regions == ALL_REGIONS crawler = crawlers.Crawler(org, accounts='account01', regions='us-west-2') assert len(crawler.accounts) == 1 assert isinstance(crawler.accounts[0], orgs.OrgAccount) assert crawler.accounts[0].name == 'account01' assert len(crawler.regions) == 1 assert crawler.regions == ['us-west-2'] crawler = crawlers.Crawler( org, accounts=org.get_account('account02'), regions='GLOBAL', ) assert len(crawler.accounts) == 1 assert isinstance(crawler.accounts[0], orgs.OrgAccount) assert crawler.accounts[0].name == 'account02' assert crawler.regions == [crawlers.DEFAULT_REGION] crawler = crawlers.Crawler( org, accounts=[ 'account01', org.get_account_id_by_name('account02'), org.get_account('account03') ], regions=['us-west-2', 'us-east-1'], ) for account in crawler.accounts: assert isinstance(account, orgs.OrgAccount) assert sorted([a.name for a in crawler.accounts ]) == ['account01', 'account02', 'account03'] assert sorted(crawler.regions) == ['us-east-1', 'us-west-2'] crawler = crawlers.Crawler( org, accounts=org.list_accounts_in_ou('ou01'), regions=utils.regions_for_service('iam'), access_role='OrgCrawlerAdmin', ) assert sorted([a.name for a in crawler.accounts ]) == ['account01', 'account02', 'account03', 'master'] for account in crawler.accounts: assert isinstance(account, orgs.OrgAccount) assert crawler.regions == [crawlers.DEFAULT_REGION] assert crawler.access_role == 'OrgCrawlerAdmin' with pytest.raises(ValueError) as e: crawler = crawlers.Crawler(org, accounts=dict(key='bogus')) with pytest.raises(ValueError) as e: crawler = crawlers.Crawler(org, regions=dict(key='bogus')) with pytest.raises(ValueError) as e: crawler = crawlers.Crawler(org, regions=['us-west-1', 'bogus-1', 'bogus-2']) assert str(e.value) == 'Invalid regions: bogus-1, bogus-2' # test handling of 'SUSPENDED' account account = orgs.OrgAccount( orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE), name='inactive-account', id='992233445566', email='*****@*****.**', status='SUSPENDED', ) org.accounts.append(account) crawler = crawlers.Crawler(org) assert 'inactive-account' in [a.name for a in org.accounts] assert 'inactive-account' not in [a.name for a in crawler.accounts]