From d445026c5655f781a74d97b98a294f853e732f7d Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Mon, 20 Jun 2016 09:26:39 -0600 Subject: [PATCH 1/3] Updated test to work with new moto version. Changed strings to unicode --- tests/unit/modules/boto_vpc_test.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/unit/modules/boto_vpc_test.py b/tests/unit/modules/boto_vpc_test.py index 0e945cdd4570..3ec1ee410b0b 100644 --- a/tests/unit/modules/boto_vpc_test.py +++ b/tests/unit/modules/boto_vpc_test.py @@ -436,14 +436,20 @@ def test_that_when_describing_vpc_by_id_it_returns_the_dict_of_properties_return ''' Tests describing parameters via vpc id if vpc exist ''' + # With moto 0.4.25 is_default is set to True. 0.4.24 and older, is_default is False + if LooseVersion(moto.__version__) >= LooseVersion('0.4.25'): + is_default = True + else: + is_default = False + vpc = self._create_vpc(name='test', tags={'test': 'testvalue'}) describe_vpc = boto_vpc.describe(vpc_id=vpc.id, **conn_parameters) vpc_properties = dict(cidr_block=unicode(cidr_block), - is_default=False, + is_default=is_default, state=u'available', - tags={'Name': 'test', 'test': 'testvalue'}, + tags={u'Name': u'test', u'test': u'testvalue'}, dhcp_options_id=u'dopt-7a8b9c2d', instance_tenancy=u'default') From 02f9ba99baae774d647c0cba63c4be81c0c4a35c Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Mon, 20 Jun 2016 10:33:13 -0600 Subject: [PATCH 2/3] Updated version check. Moved check into it's own function --- tests/unit/modules/boto_vpc_test.py | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/unit/modules/boto_vpc_test.py b/tests/unit/modules/boto_vpc_test.py index 3ec1ee410b0b..648306f74831 100644 --- a/tests/unit/modules/boto_vpc_test.py +++ b/tests/unit/modules/boto_vpc_test.py @@ -73,6 +73,21 @@ def _has_required_boto(): return True +def _get_moto_version(): + ''' + Returns the moto version + ''' + try: + return LooseVersion(moto.__version__) + except AttributeError: + import pkg_resources + from pkg_resources import DistributionNotFound + try: + return LooseVersion(pkg_resources.get_distribution('moto').version) + except DistributionNotFound: + return False + + def _has_required_moto(): ''' Returns True/False boolean depending on if Moto is installed and correct @@ -81,17 +96,8 @@ def _has_required_moto(): if not HAS_MOTO: return False else: - try: - if LooseVersion(moto.__version__) < LooseVersion(required_moto_version): - return False - except AttributeError: - import pkg_resources - from pkg_resources import DistributionNotFound - try: - if LooseVersion(pkg_resources.get_distribution('moto').version) < LooseVersion(required_moto_version): - return False - except DistributionNotFound: - return False + if _get_moto_version() < LooseVersion(required_moto_version): + return False return True @@ -437,7 +443,7 @@ def test_that_when_describing_vpc_by_id_it_returns_the_dict_of_properties_return Tests describing parameters via vpc id if vpc exist ''' # With moto 0.4.25 is_default is set to True. 0.4.24 and older, is_default is False - if LooseVersion(moto.__version__) >= LooseVersion('0.4.25'): + if _get_moto_version() >= LooseVersion('0.4.25'): is_default = True else: is_default = False From b7ac6c735ac1ed27677c115441d8e955a419850c Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Mon, 20 Jun 2016 13:20:43 -0600 Subject: [PATCH 3/3] Moved imports to top, out of _get_moto_version function --- tests/unit/modules/boto_vpc_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/modules/boto_vpc_test.py b/tests/unit/modules/boto_vpc_test.py index 648306f74831..1c34f674a654 100644 --- a/tests/unit/modules/boto_vpc_test.py +++ b/tests/unit/modules/boto_vpc_test.py @@ -2,6 +2,8 @@ # Import Python Libs from distutils.version import LooseVersion # pylint: disable=no-name-in-module +import pkg_resources +from pkg_resources import DistributionNotFound # Import Salt Testing Libs from salttesting import skipIf, TestCase @@ -80,8 +82,6 @@ def _get_moto_version(): try: return LooseVersion(moto.__version__) except AttributeError: - import pkg_resources - from pkg_resources import DistributionNotFound try: return LooseVersion(pkg_resources.get_distribution('moto').version) except DistributionNotFound: