Skip to content

Commit

Permalink
Increase test coverage on senza domains
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcs committed Aug 4, 2016
1 parent 71baafb commit a8a7214
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
25 changes: 25 additions & 0 deletions tests/fixtures.py
Expand Up @@ -122,6 +122,10 @@ def boto_client(monkeypatch):
'TTL': 20,
'Type': 'CNAME',
'Weight': 20},
{'Name': 'test-2.example.org.',
'AliasTarget': {'DNSName': 'test-2-123.myregion.elb.amazonaws.com'},
'TTL': 20,
'Type': 'A'},
]}

def my_client(rtype, *args, **kwargs):
Expand Down Expand Up @@ -157,6 +161,27 @@ def my_client(rtype, *args, **kwargs):
@pytest.fixture
def boto_resource(monkeypatch):
def my_resource(rtype, *args):
if rtype == 'cloudformation':
res = MagicMock()
res.resource_type = 'AWS::Route53::RecordSet'
res.physical_resource_id = 'test-1.example.org'
res.logical_id = 'VersionDomain'
res.last_updated_timestamp = datetime.now()
res2 = MagicMock()
res2.resource_type = 'AWS::Route53::RecordSet'
res2.physical_resource_id = 'mydomain.example.org'
res2.logical_id = 'MainDomain'
res2.last_updated_timestamp = datetime.now()
res3 = MagicMock()
res3.resource_type = 'AWS::Route53::RecordSet'
res3.physical_resource_id = 'test-2.example.org'
res3.logical_id = 'VersionDomain'
res3.last_updated_timestamp = datetime.now()
stack = MagicMock()
stack.resource_summaries.all.return_value = [res, res2, res3]
cf = MagicMock()
cf.Stack.return_value = stack
return cf
if rtype == 'ec2':
ec2 = MagicMock()
ec2.security_groups.filter.return_value = [
Expand Down
24 changes: 2 additions & 22 deletions tests/test_cli.py
Expand Up @@ -795,33 +795,12 @@ def my_client(rtype, *args):
assert 'Resource Type' in result.output


def test_domains(monkeypatch, boto_client):
def test_domains(monkeypatch, boto_resource, boto_client):
senza.traffic.DNS_ZONE_CACHE = {}
senza.traffic.DNS_RR_CACHE = {}

def my_resource(rtype, *args):
if rtype == 'cloudformation':
res = MagicMock()
res.resource_type = 'AWS::Route53::RecordSet'
res.physical_resource_id = 'test-1.example.org'
res.logical_id = 'VersionDomain'
res.last_updated_timestamp = datetime.datetime.now()
res2 = MagicMock()
res2.resource_type = 'AWS::Route53::RecordSet'
res2.physical_resource_id = 'mydomain.example.org'
res2.logical_id = 'MainDomain'
res2.last_updated_timestamp = datetime.datetime.now()
stack = MagicMock()
stack.resource_summaries.all.return_value = [res, res2]
cf = MagicMock()
cf.Stack.return_value = stack
return cf
return MagicMock()

boto_client['route53'].list_hosted_zones.return_value = {'HostedZones': [HOSTED_ZONE_EXAMPLE_ORG]}

monkeypatch.setattr('boto3.resource', my_resource)

runner = CliRunner()

data = {'SenzaInfo': {'StackName': 'test',
Expand All @@ -834,6 +813,7 @@ def my_resource(rtype, *args):
catch_exceptions=False)
assert 'mydomain.example.org' in result.output
assert 'VersionDomain test-1.example.org CNAME test-1-123.myregion.elb.amazonaws.com' in result.output
assert 'VersionDomain test-2.example.org A test-2-123.myregion.elb.amazonaws.com' in result.output
assert 'MainDomain mydomain.example.org 20 CNAME test-1.example.org' in result.output


Expand Down

0 comments on commit a8a7214

Please sign in to comment.