organizations: clean up for flake8

This commit is contained in:
Ashley Gould 2018-07-14 13:23:15 -07:00
parent f20898da0e
commit c40d2be646
6 changed files with 26 additions and 55 deletions

View File

@ -1,7 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime import datetime
import time
from moto.core import BaseBackend, BaseModel from moto.core import BaseBackend, BaseModel
from moto.core.utils import unix_time from moto.core.utils import unix_time
@ -126,6 +125,3 @@ class OrganizationsBackend(BaseBackend):
organizations_backend = OrganizationsBackend() organizations_backend = OrganizationsBackend()

View File

@ -45,4 +45,3 @@ class OrganizationsResponse(BaseResponse):
return json.dumps( return json.dumps(
self.organizations_backend.list_accounts() self.organizations_backend.list_accounts()
) )

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import random import random
import string import string
CHARSET=string.ascii_lowercase + string.digits CHARSET = string.ascii_lowercase + string.digits
ORG_ID_SIZE = 10 ORG_ID_SIZE = 10
ROOT_ID_SIZE = 4 ROOT_ID_SIZE = 4
ACCOUNT_ID_SIZE = 12 ACCOUNT_ID_SIZE = 12
@ -16,17 +16,20 @@ def make_random_org_id():
# e.g. 'o-vipjnq5z86' # e.g. 'o-vipjnq5z86'
return 'o-' + ''.join(random.choice(CHARSET) for x in range(ORG_ID_SIZE)) return 'o-' + ''.join(random.choice(CHARSET) for x in range(ORG_ID_SIZE))
def make_random_root_id(): def make_random_root_id():
# The regex pattern for a root ID string requires "r-" followed by # The regex pattern for a root ID string requires "r-" followed by
# from 4 to 32 lower-case letters or digits. # from 4 to 32 lower-case letters or digits.
# e.g. 'r-3zwx' # e.g. 'r-3zwx'
return 'r-' + ''.join(random.choice(CHARSET) for x in range(ROOT_ID_SIZE)) return 'r-' + ''.join(random.choice(CHARSET) for x in range(ROOT_ID_SIZE))
def make_random_account_id(): def make_random_account_id():
# The regex pattern for an account ID string requires exactly 12 digits. # The regex pattern for an account ID string requires exactly 12 digits.
# e.g. '488633172133' # e.g. '488633172133'
return ''.join([random.choice(string.digits) for n in range(ACCOUNT_ID_SIZE)]) return ''.join([random.choice(string.digits) for n in range(ACCOUNT_ID_SIZE)])
def make_random_create_account_status_id(): def make_random_create_account_status_id():
# The regex pattern for an create account request ID string requires # The regex pattern for an create account request ID string requires
# "car-" followed by from 8 to 32 lower-case letters or digits. # "car-" followed by from 8 to 32 lower-case letters or digits.

View File

@ -4,7 +4,6 @@ models. This module will go away.
""" """
import yaml import yaml
import moto
from moto import organizations as orgs from moto import organizations as orgs
@ -15,7 +14,7 @@ print(orgs.utils.make_random_account_id())
print(orgs.utils.make_random_create_account_id()) print(orgs.utils.make_random_create_account_id())
# models # models
my_org = orgs.models.FakeOrganization(feature_set = 'ALL') my_org = orgs.models.FakeOrganization(feature_set='ALL')
print(yaml.dump(my_org._describe())) print(yaml.dump(my_org._describe()))
#assert False #assert False

View File

@ -1,13 +1,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import boto3 import boto3
import botocore.exceptions
import sure # noqa import sure # noqa
import yaml
import re
import datetime import datetime
import moto
from moto import mock_organizations from moto import mock_organizations
from moto.organizations.models import ( from moto.organizations.models import (
MASTER_ACCOUNT_ID, MASTER_ACCOUNT_ID,
@ -53,21 +49,7 @@ def validate_organization(response):
'Type': 'SERVICE_CONTROL_POLICY', 'Type': 'SERVICE_CONTROL_POLICY',
'Status': 'ENABLED' 'Status': 'ENABLED'
}]) }])
#
#'Organization': {
# 'Id': 'string',
# 'Arn': 'string',
# 'FeatureSet': 'ALL'|'CONSOLIDATED_BILLING',
# 'MasterAccountArn': 'string',
# 'MasterAccountId': 'string',
# 'MasterAccountEmail': 'string',
# 'AvailablePolicyTypes': [
# {
# 'Type': 'SERVICE_CONTROL_POLICY',
# 'Status': 'ENABLED'|'PENDING_ENABLE'|'PENDING_DISABLE'
# },
# ]
#}
def validate_account(org, account): def validate_account(org, account):
sorted(account.keys()).should.equal([ sorted(account.keys()).should.equal([
@ -90,15 +72,7 @@ def validate_account(org, account):
account['Status'].should.be.within(['ACTIVE', 'SUSPENDED']) account['Status'].should.be.within(['ACTIVE', 'SUSPENDED'])
account['Name'].should.be.a(str) account['Name'].should.be.a(str)
account['JoinedTimestamp'].should.be.a(datetime.datetime) account['JoinedTimestamp'].should.be.a(datetime.datetime)
#'Account': {
# 'Id': 'string',
# 'Arn': 'string',
# 'Email': 'string',
# 'Name': 'string',
# 'Status': 'ACTIVE'|'SUSPENDED',
# 'JoinedMethod': 'INVITED'|'CREATED',
# 'JoinedTimestamp': datetime(2015, 1, 1)
#}
def validate_create_account_status(create_status): def validate_create_account_status(create_status):
sorted(create_status.keys()).should.equal([ sorted(create_status.keys()).should.equal([
@ -115,15 +89,7 @@ def validate_create_account_status(create_status):
create_status['State'].should.equal('SUCCEEDED') create_status['State'].should.equal('SUCCEEDED')
create_status['RequestedTimestamp'].should.be.a(datetime.datetime) create_status['RequestedTimestamp'].should.be.a(datetime.datetime)
create_status['CompletedTimestamp'].should.be.a(datetime.datetime) create_status['CompletedTimestamp'].should.be.a(datetime.datetime)
#'CreateAccountStatus': {
# 'Id': 'string',
# 'AccountName': 'string',
# 'State': 'IN_PROGRESS'|'SUCCEEDED'|'FAILED',
# 'RequestedTimestamp': datetime(2015, 1, 1),
# 'CompletedTimestamp': datetime(2015, 1, 1),
# 'AccountId': 'string',
# 'FailureReason': 'ACCOUNT_LIMIT_EXCEEDED'|'EMAIL_ALREADY_EXISTS'|'INVALID_ADDRESS'|'INVALID_EMAIL'|'CONCURRENT_ACCOUNT_MODIFICATION'|'INTERNAL_FAILURE'
#}
@mock_organizations @mock_organizations
def test_create_organization(): def test_create_organization():
@ -134,6 +100,7 @@ def test_create_organization():
response['Organization']['FeatureSet'].should.equal('ALL') response['Organization']['FeatureSet'].should.equal('ALL')
#assert False #assert False
@mock_organizations @mock_organizations
def test_describe_organization(): def test_describe_organization():
client = boto3.client('organizations', region_name='us-east-1') client = boto3.client('organizations', region_name='us-east-1')
@ -148,23 +115,27 @@ mockname = 'mock-account'
mockdomain = 'moto-example.org' mockdomain = 'moto-example.org'
mockemail = '@'.join([mockname, mockdomain]) mockemail = '@'.join([mockname, mockdomain])
@mock_organizations @mock_organizations
def test_create_account(): def test_create_account():
client = boto3.client('organizations', region_name='us-east-1') client = boto3.client('organizations', region_name='us-east-1')
client.create_organization(FeatureSet='ALL') client.create_organization(FeatureSet='ALL')
create_status = client.create_account( create_status = client.create_account(
AccountName=mockname, Email=mockemail)['CreateAccountStatus'] AccountName=mockname, Email=mockemail
)['CreateAccountStatus']
#print(yaml.dump(create_status, default_flow_style=False)) #print(yaml.dump(create_status, default_flow_style=False))
validate_create_account_status(create_status) validate_create_account_status(create_status)
create_status['AccountName'].should.equal(mockname) create_status['AccountName'].should.equal(mockname)
#assert False #assert False
@mock_organizations @mock_organizations
def test_describe_account(): def test_describe_account():
client = boto3.client('organizations', region_name='us-east-1') client = boto3.client('organizations', region_name='us-east-1')
org = client.create_organization(FeatureSet='ALL')['Organization'] org = client.create_organization(FeatureSet='ALL')['Organization']
account_id = client.create_account( account_id = client.create_account(
AccountName=mockname, Email=mockemail)['CreateAccountStatus']['AccountId'] AccountName=mockname, Email=mockemail
)['CreateAccountStatus']['AccountId']
response = client.describe_account(AccountId=account_id) response = client.describe_account(AccountId=account_id)
#print(yaml.dump(response, default_flow_style=False)) #print(yaml.dump(response, default_flow_style=False))
validate_account(org, response['Account']) validate_account(org, response['Account'])
@ -172,6 +143,7 @@ def test_describe_account():
response['Account']['Email'].should.equal(mockemail) response['Account']['Email'].should.equal(mockemail)
#assert False #assert False
@mock_organizations @mock_organizations
def test_list_accounts(): def test_list_accounts():
client = boto3.client('organizations', region_name='us-east-1') client = boto3.client('organizations', region_name='us-east-1')
@ -190,4 +162,3 @@ def test_list_accounts():
accounts[3]['Name'].should.equal(mockname + '3') accounts[3]['Name'].should.equal(mockname + '3')
accounts[2]['Email'].should.equal(mockname + '2' + '@' + mockdomain) accounts[2]['Email'].should.equal(mockname + '2' + '@' + mockdomain)
#assert False #assert False

View File

@ -1,7 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import sure # noqa import sure # noqa
import moto
from moto.organizations import utils from moto.organizations import utils
ORG_ID_REGEX = r'o-[a-z0-9]{%s}' % utils.ORG_ID_SIZE ORG_ID_REGEX = r'o-[a-z0-9]{%s}' % utils.ORG_ID_SIZE
@ -9,18 +8,22 @@ ROOT_ID_REGEX = r'r-[a-z0-9]{%s}' % utils.ROOT_ID_SIZE
ACCOUNT_ID_REGEX = r'[0-9]{%s}' % utils.ACCOUNT_ID_SIZE ACCOUNT_ID_REGEX = r'[0-9]{%s}' % utils.ACCOUNT_ID_SIZE
CREATE_ACCOUNT_STATUS_ID_REGEX = r'car-[a-z0-9]{%s}' % utils.CREATE_ACCOUNT_STATUS_ID_SIZE CREATE_ACCOUNT_STATUS_ID_REGEX = r'car-[a-z0-9]{%s}' % utils.CREATE_ACCOUNT_STATUS_ID_SIZE
def test_make_random_org_id(): def test_make_random_org_id():
org_id = utils.make_random_org_id() org_id = utils.make_random_org_id()
org_id.should.match(ORG_ID_REGEX) org_id.should.match(ORG_ID_REGEX)
def test_make_random_root_id(): def test_make_random_root_id():
org_id = utils.make_random_root_id() org_id = utils.make_random_root_id()
org_id.should.match(ROOT_ID_REGEX) org_id.should.match(ROOT_ID_REGEX)
def test_make_random_account_id(): def test_make_random_account_id():
account_id = utils.make_random_account_id() account_id = utils.make_random_account_id()
account_id.should.match(ACCOUNT_ID_REGEX) account_id.should.match(ACCOUNT_ID_REGEX)
def test_make_random_create_account_status_id(): def test_make_random_create_account_status_id():
create_account_status_id = utils.make_random_create_account_status_id() create_account_status_id = utils.make_random_create_account_status_id()
create_account_status_id.should.match(CREATE_ACCOUNT_STATUS_ID_REGEX) create_account_status_id.should.match(CREATE_ACCOUNT_STATUS_ID_REGEX)