organizations: clean up for flake8
This commit is contained in:
parent
f20898da0e
commit
c40d2be646
@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import unix_time
|
||||
@ -126,6 +125,3 @@ class OrganizationsBackend(BaseBackend):
|
||||
|
||||
|
||||
organizations_backend = OrganizationsBackend()
|
||||
|
||||
|
||||
|
||||
|
@ -45,4 +45,3 @@ class OrganizationsResponse(BaseResponse):
|
||||
return json.dumps(
|
||||
self.organizations_backend.list_accounts()
|
||||
)
|
||||
|
||||
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import random
|
||||
import string
|
||||
|
||||
CHARSET=string.ascii_lowercase + string.digits
|
||||
CHARSET = string.ascii_lowercase + string.digits
|
||||
ORG_ID_SIZE = 10
|
||||
ROOT_ID_SIZE = 4
|
||||
ACCOUNT_ID_SIZE = 12
|
||||
@ -16,17 +16,20 @@ def make_random_org_id():
|
||||
# e.g. 'o-vipjnq5z86'
|
||||
return 'o-' + ''.join(random.choice(CHARSET) for x in range(ORG_ID_SIZE))
|
||||
|
||||
|
||||
def make_random_root_id():
|
||||
# The regex pattern for a root ID string requires "r-" followed by
|
||||
# from 4 to 32 lower-case letters or digits.
|
||||
# e.g. 'r-3zwx'
|
||||
return 'r-' + ''.join(random.choice(CHARSET) for x in range(ROOT_ID_SIZE))
|
||||
|
||||
|
||||
def make_random_account_id():
|
||||
# The regex pattern for an account ID string requires exactly 12 digits.
|
||||
# e.g. '488633172133'
|
||||
return ''.join([random.choice(string.digits) for n in range(ACCOUNT_ID_SIZE)])
|
||||
|
||||
|
||||
def make_random_create_account_status_id():
|
||||
# The regex pattern for an create account request ID string requires
|
||||
# "car-" followed by from 8 to 32 lower-case letters or digits.
|
||||
|
@ -4,7 +4,6 @@ models. This module will go away.
|
||||
"""
|
||||
|
||||
import yaml
|
||||
import moto
|
||||
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())
|
||||
|
||||
# models
|
||||
my_org = orgs.models.FakeOrganization(feature_set = 'ALL')
|
||||
my_org = orgs.models.FakeOrganization(feature_set='ALL')
|
||||
print(yaml.dump(my_org._describe()))
|
||||
#assert False
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
import botocore.exceptions
|
||||
import sure # noqa
|
||||
import yaml
|
||||
import re
|
||||
import datetime
|
||||
|
||||
import moto
|
||||
from moto import mock_organizations
|
||||
from moto.organizations.models import (
|
||||
MASTER_ACCOUNT_ID,
|
||||
@ -53,21 +49,7 @@ def validate_organization(response):
|
||||
'Type': 'SERVICE_CONTROL_POLICY',
|
||||
'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):
|
||||
sorted(account.keys()).should.equal([
|
||||
@ -90,15 +72,7 @@ def validate_account(org, account):
|
||||
account['Status'].should.be.within(['ACTIVE', 'SUSPENDED'])
|
||||
account['Name'].should.be.a(str)
|
||||
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):
|
||||
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['RequestedTimestamp'].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
|
||||
def test_create_organization():
|
||||
@ -134,6 +100,7 @@ def test_create_organization():
|
||||
response['Organization']['FeatureSet'].should.equal('ALL')
|
||||
#assert False
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_describe_organization():
|
||||
client = boto3.client('organizations', region_name='us-east-1')
|
||||
@ -148,23 +115,27 @@ mockname = 'mock-account'
|
||||
mockdomain = 'moto-example.org'
|
||||
mockemail = '@'.join([mockname, mockdomain])
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_create_account():
|
||||
client = boto3.client('organizations', region_name='us-east-1')
|
||||
client.create_organization(FeatureSet='ALL')
|
||||
create_status = client.create_account(
|
||||
AccountName=mockname, Email=mockemail)['CreateAccountStatus']
|
||||
AccountName=mockname, Email=mockemail
|
||||
)['CreateAccountStatus']
|
||||
#print(yaml.dump(create_status, default_flow_style=False))
|
||||
validate_create_account_status(create_status)
|
||||
create_status['AccountName'].should.equal(mockname)
|
||||
#assert False
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_describe_account():
|
||||
client = boto3.client('organizations', region_name='us-east-1')
|
||||
org = client.create_organization(FeatureSet='ALL')['Organization']
|
||||
account_id = client.create_account(
|
||||
AccountName=mockname, Email=mockemail)['CreateAccountStatus']['AccountId']
|
||||
AccountName=mockname, Email=mockemail
|
||||
)['CreateAccountStatus']['AccountId']
|
||||
response = client.describe_account(AccountId=account_id)
|
||||
#print(yaml.dump(response, default_flow_style=False))
|
||||
validate_account(org, response['Account'])
|
||||
@ -172,6 +143,7 @@ def test_describe_account():
|
||||
response['Account']['Email'].should.equal(mockemail)
|
||||
#assert False
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_list_accounts():
|
||||
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[2]['Email'].should.equal(mockname + '2' + '@' + mockdomain)
|
||||
#assert False
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import sure # noqa
|
||||
import moto
|
||||
from moto.organizations import utils
|
||||
|
||||
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
|
||||
CREATE_ACCOUNT_STATUS_ID_REGEX = r'car-[a-z0-9]{%s}' % utils.CREATE_ACCOUNT_STATUS_ID_SIZE
|
||||
|
||||
|
||||
def test_make_random_org_id():
|
||||
org_id = utils.make_random_org_id()
|
||||
org_id.should.match(ORG_ID_REGEX)
|
||||
|
||||
|
||||
def test_make_random_root_id():
|
||||
org_id = utils.make_random_root_id()
|
||||
org_id.should.match(ROOT_ID_REGEX)
|
||||
|
||||
|
||||
def test_make_random_account_id():
|
||||
account_id = utils.make_random_account_id()
|
||||
account_id.should.match(ACCOUNT_ID_REGEX)
|
||||
|
||||
|
||||
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(CREATE_ACCOUNT_STATUS_ID_REGEX)
|
||||
|
Loading…
Reference in New Issue
Block a user