Skip to content

Commit

Permalink
PR #64 finish unit test coverage for new STS-enabled connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Sep 30, 2015
1 parent f818a28 commit 46ca14f
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 39 deletions.
1 change: 0 additions & 1 deletion awslimitchecker/services/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

import abc # noqa
import boto
import boto.ec2
import logging
from collections import defaultdict
from copy import deepcopy
Expand Down
33 changes: 28 additions & 5 deletions awslimitchecker/tests/services/test_autoscaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"""

import sys
from boto.ec2.autoscale import AutoScaleConnection
from boto.ec2.autoscale import AutoScaleConnection, connect_to_region
from awslimitchecker.services.autoscaling import _AutoscalingService

# https://code.google.com/p/mock/issues/detail?id=249
Expand All @@ -54,7 +54,9 @@

class Test_AutoscalingService(object):

# path base paths
pb = 'awslimitchecker.services.autoscaling._AutoscalingService'
pbm = 'awslimitchecker.services.autoscaling'

def test_init(self):
"""test __init__()"""
Expand All @@ -67,13 +69,34 @@ def test_init(self):
def test_connect(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _AutoscalingService(21, 43)
with patch('awslimitchecker.services.autoscaling.boto.connect_'
'autoscale') as mock_autoscaling:
mock_autoscaling.return_value = mock_conn
cls.connect()
with patch('%s.boto.connect_autoscale' % self.pbm) as mock_autoscaling:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_autoscaling.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_autoscaling.mock_calls == [call()]
assert mock_connect_via.mock_calls == []
assert mock_conn.mock_calls == []
assert cls.conn == mock_conn

def test_connect_region(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _AutoscalingService(21, 43, region='myreg')
with patch('%s.boto.connect_autoscale' % self.pbm) as mock_autoscaling:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_autoscaling.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_autoscaling.mock_calls == []
assert mock_connect_via.mock_calls == [
call(connect_to_region)
]
assert mock_conn.mock_calls == []
assert cls.conn == mock_conn_via

def test_connect_again(self):
"""make sure we re-use the connection"""
Expand Down
36 changes: 30 additions & 6 deletions awslimitchecker/tests/services/test_ebs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from boto.ec2.connection import EC2Connection
from boto.ec2.volume import Volume
from boto.ec2.snapshot import Snapshot
from boto.ec2 import connect_to_region
from awslimitchecker.services.ebs import _EbsService
from awslimitchecker.limit import AwsLimit

Expand All @@ -58,6 +59,7 @@
class Test_EbsService(object):

pb = 'awslimitchecker.services.ebs._EbsService' # patch base path
pbm = 'awslimitchecker.services.ebs' # patch base path for module

def test_init(self):
"""test __init__()"""
Expand All @@ -70,23 +72,45 @@ def test_init(self):
def test_connect(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _EbsService(21, 43)
with patch('awslimitchecker.services.ec2.boto.connect_ec2') as mock_ec2:
mock_ec2.return_value = mock_conn
cls.connect()
with patch('%s.boto.connect_ec2' % self.pbm) as mock_ec2:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_ec2.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_ec2.mock_calls == [call()]
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []
assert cls.conn == mock_conn

def test_connect_region(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _EbsService(21, 43, region='foo')
with patch('%s.boto.connect_ec2' % self.pbm) as mock_ec2:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_ec2.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_ec2.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == [call(connect_to_region)]
assert cls.conn == mock_conn_via

def test_connect_again(self):
"""make sure we re-use the connection"""
mock_conn = Mock()
cls = _EbsService(21, 43)
cls.conn = mock_conn
with patch('awslimitchecker.services.ec2.boto.connect_ec2') as mock_ec2:
mock_ec2.return_value = mock_conn
cls.connect()
with patch('%s.boto.connect_ec2' % self.pbm) as mock_ec2:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_ec2.return_value = mock_conn
cls.connect()
assert mock_ec2.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []

def test_get_limits_again(self):
"""test that existing limits dict is returned on subsequent calls"""
Expand Down
28 changes: 25 additions & 3 deletions awslimitchecker/tests/services/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from boto.ec2.securitygroup import SecurityGroup
from boto.ec2.address import Address
from boto.ec2.networkinterface import NetworkInterface
from boto.ec2 import connect_to_region
from awslimitchecker.services.ec2 import _Ec2Service
from awslimitchecker.limit import AwsLimit

Expand All @@ -61,6 +62,7 @@
class Test_Ec2Service(object):

pb = 'awslimitchecker.services.ec2._Ec2Service' # patch base path
pbm = 'awslimitchecker.services.ec2' # module patch base path

def test_init(self):
"""test __init__()"""
Expand All @@ -73,12 +75,32 @@ def test_init(self):
def test_connect(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _Ec2Service(21, 43)
with patch('awslimitchecker.services.ec2.boto.connect_ec2') as mock_ec2:
mock_ec2.return_value = mock_conn
cls.connect()
with patch('%s.boto.connect_ec2' % self.pbm) as mock_ec2:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_ec2.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_ec2.mock_calls == [call()]
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []
assert cls.conn == mock_conn

def test_connect_region(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _Ec2Service(21, 43, region='bar')
with patch('%s.boto.connect_ec2' % self.pbm) as mock_ec2:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_ec2.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_ec2.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == [call(connect_to_region)]
assert cls.conn == mock_conn_via

def test_connect_again(self):
"""make sure we re-use the connection"""
Expand Down
37 changes: 31 additions & 6 deletions awslimitchecker/tests/services/test_elasticache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import sys
from boto.elasticache.layer1 import ElastiCacheConnection
from boto.elasticache import connect_to_region
from boto.exception import BotoServerError
from awslimitchecker.services.elasticache import _ElastiCacheService

Expand All @@ -56,6 +57,7 @@
class TestElastiCacheService(object):

pb = 'awslimitchecker.services.elasticache._ElastiCacheService' # patch
pbm = 'awslimitchecker.services.elasticache' # module patch

def test_init(self):
"""test __init__()"""
Expand All @@ -68,13 +70,34 @@ def test_init(self):
def test_connect(self):
"""test connect()"""
mock_conn = Mock(spec_set=ElastiCacheConnection)
mock_conn_via = Mock(spec_set=ElastiCacheConnection)
cls = _ElastiCacheService(21, 43)
with patch('awslimitchecker.services.elasticache.ElastiCacheConnection'
'') as mock_elasticache:
mock_elasticache.return_value = mock_conn
cls.connect()
with patch('%s.ElastiCacheConnection' % self.pbm) as mock_elasticache:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_elasticache.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_elasticache.mock_calls == [call()]
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []
assert cls.conn == mock_conn

def test_connect_region(self):
"""test connect()"""
mock_conn = Mock(spec_set=ElastiCacheConnection)
mock_conn_via = Mock(spec_set=ElastiCacheConnection)
cls = _ElastiCacheService(21, 43, region='foo')
with patch('%s.ElastiCacheConnection' % self.pbm) as mock_elasticache:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_elasticache.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_elasticache.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == [
call(connect_to_region)
]
assert cls.conn == mock_conn_via

def test_connect_again(self):
"""make sure we re-use the connection"""
Expand All @@ -83,10 +106,12 @@ def test_connect_again(self):
cls.conn = mock_conn
with patch('awslimitchecker.services.elasticache.ElastiCacheConnection'
'') as mock_elasticache:
mock_elasticache.return_value = mock_conn
cls.connect()
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_elasticache.return_value = mock_conn
cls.connect()
assert mock_elasticache.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []

def test_get_limits(self):
cls = _ElastiCacheService(21, 43)
Expand Down
36 changes: 31 additions & 5 deletions awslimitchecker/tests/services/test_elb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import sys
from boto.ec2.elb import ELBConnection
from boto.ec2.elb.loadbalancer import LoadBalancer
from boto.ec2.elb import connect_to_region
from awslimitchecker.services.elb import _ElbService

# https://code.google.com/p/mock/issues/detail?id=249
Expand All @@ -56,6 +57,7 @@
class Test_ElbService(object):

pb = 'awslimitchecker.services.elb._ElbService' # patch base path
pbm = 'awslimitchecker.services.elb' # patch base path - module

def test_init(self):
"""test __init__()"""
Expand All @@ -68,23 +70,47 @@ def test_init(self):
def test_connect(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _ElbService(21, 43)
with patch('awslimitchecker.services.elb.boto.connect_elb') as mock_elb:
mock_elb.return_value = mock_conn
cls.connect()
with patch('%s.boto.connect_elb' % self.pbm) as mock_elb:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_elb.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_elb.mock_calls == [call()]
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []
assert cls.conn == mock_conn

def test_connect_region(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _ElbService(21, 43, region='myregion')
with patch('%s.boto.connect_elb' % self.pbm) as mock_elb:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_elb.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_elb.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == [
call(connect_to_region)
]
assert cls.conn == mock_conn_via

def test_connect_again(self):
"""make sure we re-use the connection"""
mock_conn = Mock()
cls = _ElbService(21, 43)
cls.conn = mock_conn
with patch('awslimitchecker.services.elb.boto.connect_elb') as mock_elb:
mock_elb.return_value = mock_conn
cls.connect()
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_elb.return_value = mock_conn
cls.connect()
assert mock_elb.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []

def test_get_limits(self):
cls = _ElbService(21, 43)
Expand Down
37 changes: 31 additions & 6 deletions awslimitchecker/tests/services/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import sys
from boto.rds2.layer1 import RDSConnection
from boto.rds2 import connect_to_region
from awslimitchecker.services.rds import _RDSService

# https://code.google.com/p/mock/issues/detail?id=249
Expand All @@ -55,6 +56,7 @@
class Test_RDSService(object):

pb = 'awslimitchecker.services.rds._RDSService' # patch base path
pbm = 'awslimitchecker.services.rds' # patch base path - module

def test_init(self):
"""test __init__()"""
Expand All @@ -67,13 +69,34 @@ def test_init(self):
def test_connect(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _RDSService(21, 43)
with patch('awslimitchecker.services.rds.boto.connect_rds2'
'') as mock_rds:
mock_rds.return_value = mock_conn
cls.connect()
with patch('%s.boto.connect_rds2' % self.pbm) as mock_rds:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_rds.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_rds.mock_calls == [call()]
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []
assert cls.conn == mock_conn

def test_connect_region(self):
"""test connect()"""
mock_conn = Mock()
mock_conn_via = Mock()
cls = _RDSService(21, 43, region='foo')
with patch('%s.boto.connect_rds2' % self.pbm) as mock_rds:
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_rds.return_value = mock_conn
mock_connect_via.return_value = mock_conn_via
cls.connect()
assert mock_rds.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == [
call(connect_to_region)
]
assert cls.conn == mock_conn_via

def test_connect_again(self):
"""make sure we re-use the connection"""
Expand All @@ -82,10 +105,12 @@ def test_connect_again(self):
cls.conn = mock_conn
with patch('awslimitchecker.services.rds.boto.connect_rds2'
'') as mock_rds:
mock_rds.return_value = mock_conn
cls.connect()
with patch('%s.connect_via' % self.pb) as mock_connect_via:
mock_rds.return_value = mock_conn
cls.connect()
assert mock_rds.mock_calls == []
assert mock_conn.mock_calls == []
assert mock_connect_via.mock_calls == []

def test_get_limits(self):
cls = _RDSService(21, 43)
Expand Down
Loading

0 comments on commit 46ca14f

Please sign in to comment.