From 731fdc43c9dc4f94860386c14b2ad383b77a24f0 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 04:09:28 +0100 Subject: Rename test for consistency --- .../test/openshift_master_facts_default_predicates_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index bcfaa55c8..5013d1302 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -244,6 +244,6 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): self.lookup.run(None, variables=facts) @raises(AnsibleError) - def testMissingOpenShiftFacts(self): + def test_missing_openshift_facts(self): facts = {} self.lookup.run(None, variables=facts) -- cgit v1.2.3 From c48a8d56d8d469465df5c44a7715062bf8c6f313 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 17:46:08 +0100 Subject: Insert paths in the second position of sys.path http://stackoverflow.com/a/10097543/4804690 Additionally, avoid using platform-specific '/' and '..'. --- .../test/openshift_master_facts_default_predicates_tests.py | 2 +- .../test/openshift_master_facts_default_priorities_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index 5013d1302..94c4495c9 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -5,7 +5,7 @@ import sys from ansible.errors import AnsibleError from nose.tools import raises, assert_equal -sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../lookup_plugins/")] + sys.path +sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) from openshift_master_facts_default_predicates import LookupModule # noqa: E402 diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 7ddc5dcb2..0bcd240d6 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -5,7 +5,7 @@ import sys from ansible.errors import AnsibleError from nose.tools import raises, assert_equal -sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../lookup_plugins/")] + sys.path +sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) from openshift_master_facts_default_priorities import LookupModule # noqa: E402 -- cgit v1.2.3 From 7a61e36919ef3597c41c9bf5a77d8762bd1b9cf0 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 03:33:25 +0100 Subject: Move similar test cases together And reorganize them in such a way to show that there are a bunch of duplicated tests that are exactly the same. --- ...nshift_master_facts_default_predicates_tests.py | 64 +++++++++++----------- ...nshift_master_facts_default_priorities_tests.py | 64 +++++++++++----------- 2 files changed, 64 insertions(+), 64 deletions(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index 94c4495c9..c7cf73523 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -97,12 +97,44 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): } } + @raises(AnsibleError) + def test_missing_openshift_facts(self): + facts = {} + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_missing_deployment_type(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '10.10' + self.lookup.run(None, variables=facts) + @raises(AnsibleError) def test_missing_short_version_and_missing_openshift_release(self): facts = copy.deepcopy(self.default_facts) facts['openshift']['common']['deployment_type'] = 'origin' self.lookup.run(None, variables=facts) + @raises(AnsibleError) + def test_unknown_deployment_types(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '1.1' + facts['openshift']['common']['deployment_type'] = 'bogus' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_unknown_origin_version(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_unknown_ocp_version(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' + self.lookup.run(None, variables=facts) + def check_defaults_short_version(self, short_version, deployment_type, default_predicates, regions_enabled): facts = copy.deepcopy(self.default_facts) @@ -215,35 +247,3 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): for release, deployment_type, default_predicates in TEST_VARS: release = release + '.1' yield self.check_defaults_release, release, deployment_type, default_predicates, False - - @raises(AnsibleError) - def test_unknown_deployment_types(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '1.1' - facts['openshift']['common']['deployment_type'] = 'bogus' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_origin_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_ocp_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_deployment_type(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '10.10' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_openshift_facts(self): - facts = {} - self.lookup.run(None, variables=facts) diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 0bcd240d6..36d159f4a 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -85,12 +85,44 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): } } + @raises(AnsibleError) + def test_missing_openshift_facts(self): + facts = {} + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_missing_deployment_type(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '10.10' + self.lookup.run(None, variables=facts) + @raises(AnsibleError) def test_missing_short_version_and_missing_openshift_release(self): facts = copy.deepcopy(self.default_facts) facts['openshift']['common']['deployment_type'] = 'origin' self.lookup.run(None, variables=facts) + @raises(AnsibleError) + def test_unknown_deployment_types(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '1.1' + facts['openshift']['common']['deployment_type'] = 'bogus' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_unknown_origin_version(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_unknown_ocp_version(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' + self.lookup.run(None, variables=facts) + def check_defaults_short_version(self, release, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) @@ -201,35 +233,3 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): for release, deployment_type, default_priorities in TEST_VARS: release = release + '.1' yield self.check_defaults_release, release, deployment_type, default_priorities, False - - @raises(AnsibleError) - def test_unknown_origin_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_ocp_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_deployment_types(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '1.1' - facts['openshift']['common']['deployment_type'] = 'bogus' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_deployment_type(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '10.10' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_openshift_facts(self): - facts = {} - self.lookup.run(None, variables=facts) -- cgit v1.2.3 From 7887248c3b3af3733622d53e89af5afacad72e67 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 16:23:26 +0100 Subject: Remove test duplication Consolidate tests for bad input into a single file instead of having the same code in two files. --- .../test/openshift_master_facts_bad_input_tests.py | 58 ++++++++++++++++++++++ ...nshift_master_facts_default_predicates_tests.py | 41 +-------------- ...nshift_master_facts_default_priorities_tests.py | 41 +-------------- 3 files changed, 60 insertions(+), 80 deletions(-) create mode 100644 roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py new file mode 100644 index 000000000..ec6c7ae4a --- /dev/null +++ b/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py @@ -0,0 +1,58 @@ +import copy +import os +import sys + +from ansible.errors import AnsibleError +from nose.tools import raises + +sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) + +from openshift_master_facts_default_predicates import LookupModule # noqa: E402 + + +class TestOpenShiftMasterFactsBadInput(object): + def setUp(self): + self.lookup = LookupModule() + self.default_facts = { + 'openshift': { + 'common': {} + } + } + + @raises(AnsibleError) + def test_missing_openshift_facts(self): + facts = {} + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_missing_deployment_type(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '10.10' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_missing_short_version_and_missing_openshift_release(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_unknown_deployment_types(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '1.1' + facts['openshift']['common']['deployment_type'] = 'bogus' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_unknown_origin_version(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) + + @raises(AnsibleError) + def test_unknown_ocp_version(self): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' + self.lookup.run(None, variables=facts) diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index c7cf73523..ec1120bd5 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -2,8 +2,7 @@ import copy import os import sys -from ansible.errors import AnsibleError -from nose.tools import raises, assert_equal +from nose.tools import assert_equal sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) @@ -97,44 +96,6 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): } } - @raises(AnsibleError) - def test_missing_openshift_facts(self): - facts = {} - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_deployment_type(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '10.10' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_short_version_and_missing_openshift_release(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_deployment_types(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '1.1' - facts['openshift']['common']['deployment_type'] = 'bogus' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_origin_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_ocp_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' - self.lookup.run(None, variables=facts) - def check_defaults_short_version(self, short_version, deployment_type, default_predicates, regions_enabled): facts = copy.deepcopy(self.default_facts) diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 36d159f4a..974cc1d0c 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -2,8 +2,7 @@ import copy import os import sys -from ansible.errors import AnsibleError -from nose.tools import raises, assert_equal +from nose.tools import assert_equal sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) @@ -85,44 +84,6 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): } } - @raises(AnsibleError) - def test_missing_openshift_facts(self): - facts = {} - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_deployment_type(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '10.10' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_missing_short_version_and_missing_openshift_release(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_deployment_types(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '1.1' - facts['openshift']['common']['deployment_type'] = 'bogus' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_origin_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) - - @raises(AnsibleError) - def test_unknown_ocp_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' - self.lookup.run(None, variables=facts) - def check_defaults_short_version(self, release, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) -- cgit v1.2.3 From 8c0c5384341fb0a0ab70b4770c44a799178c90af Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 03:34:44 +0100 Subject: Reorganize tests and helper functions logically This is intented to make it easier to read tests top-down. The test methods in both files are sorted somehow logically, and in the same order in both files, to help visualizing the similarities between them with diff tools. --- ...nshift_master_facts_default_predicates_tests.py | 130 ++++++++++----------- ...nshift_master_facts_default_priorities_tests.py | 128 ++++++++++---------- 2 files changed, 129 insertions(+), 129 deletions(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index ec1120bd5..a33c183f6 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -96,6 +96,56 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): } } + def test_openshift_version(self): + for regions_enabled in (True, False): + for release, deployment_type, default_predicates in TEST_VARS: + release = release + '.1' + yield self.check_defaults_version, release, deployment_type, default_predicates, regions_enabled + + def check_defaults_version(self, version, deployment_type, default_predicates, + regions_enabled): + facts = copy.deepcopy(self.default_facts) + facts['openshift_version'] = version + facts['openshift']['common']['deployment_type'] = deployment_type + results = self.lookup.run(None, variables=facts, + regions_enabled=regions_enabled) + if regions_enabled: + assert_equal(results, default_predicates + [REGION_PREDICATE]) + else: + assert_equal(results, default_predicates) + + def test_release_defaults(self): + for regions_enabled in (True, False): + for release, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_release, release, deployment_type, default_predicates, regions_enabled + + def test_v_release_defaults(self): + for regions_enabled in (True, False): + for release, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_release, 'v' + release, deployment_type, default_predicates, regions_enabled + + def test_trunc_openshift_release(self): + for release, deployment_type, default_predicates in TEST_VARS: + release = release + '.1' + yield self.check_defaults_release, release, deployment_type, default_predicates, False + + def check_defaults_release(self, release, deployment_type, default_predicates, + regions_enabled): + facts = copy.deepcopy(self.default_facts) + facts['openshift_release'] = release + facts['openshift']['common']['deployment_type'] = deployment_type + results = self.lookup.run(None, variables=facts, + regions_enabled=regions_enabled) + if regions_enabled: + assert_equal(results, default_predicates + [REGION_PREDICATE]) + else: + assert_equal(results, default_predicates) + + def test_short_version_defaults(self): + for regions_enabled in (True, False): + for release, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_short_version, release, deployment_type, default_predicates, regions_enabled + def check_defaults_short_version(self, short_version, deployment_type, default_predicates, regions_enabled): facts = copy.deepcopy(self.default_facts) @@ -108,6 +158,11 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_predicates) + def test_short_version_kwarg(self): + for regions_enabled in (True, False): + for release, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_short_version_kwarg, release, deployment_type, default_predicates, regions_enabled + def check_defaults_short_version_kwarg(self, short_version, deployment_type, default_predicates, regions_enabled): facts = copy.deepcopy(self.default_facts) @@ -120,6 +175,11 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_predicates) + def test_deployment_type_kwarg(self): + for regions_enabled in (True, False): + for release, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_deployment_type_kwarg, release, deployment_type, default_predicates, regions_enabled + def check_defaults_deployment_type_kwarg(self, short_version, deployment_type, default_predicates, regions_enabled): facts = copy.deepcopy(self.default_facts) @@ -132,6 +192,11 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_predicates) + def test_only_kwargs(self): + for regions_enabled in (True, False): + for release, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_only_kwargs, release, deployment_type, default_predicates, regions_enabled + def check_defaults_only_kwargs(self, short_version, deployment_type, default_predicates, regions_enabled): facts = copy.deepcopy(self.default_facts) @@ -143,68 +208,3 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): assert_equal(results, default_predicates + [REGION_PREDICATE]) else: assert_equal(results, default_predicates) - - def check_defaults_release(self, release, deployment_type, default_predicates, - regions_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_release'] = release - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled) - if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) - else: - assert_equal(results, default_predicates) - - def check_defaults_version(self, version, deployment_type, default_predicates, - regions_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_version'] = version - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled) - if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) - else: - assert_equal(results, default_predicates) - - def test_openshift_version(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - release = release + '.1' - yield self.check_defaults_version, release, deployment_type, default_predicates, regions_enabled - - def test_v_release_defaults(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_release, 'v' + release, deployment_type, default_predicates, regions_enabled - - def test_release_defaults(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_release, release, deployment_type, default_predicates, regions_enabled - - def test_short_version_defaults(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_short_version, release, deployment_type, default_predicates, regions_enabled - - def test_short_version_kwarg(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_short_version_kwarg, release, deployment_type, default_predicates, regions_enabled - - def test_only_kwargs(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_only_kwargs, release, deployment_type, default_predicates, regions_enabled - - def test_deployment_type_kwarg(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_deployment_type_kwarg, release, deployment_type, default_predicates, regions_enabled - - def test_trunc_openshift_release(self): - for release, deployment_type, default_predicates in TEST_VARS: - release = release + '.1' - yield self.check_defaults_release, release, deployment_type, default_predicates, False diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 974cc1d0c..326af3e13 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -84,6 +84,55 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): } } + def test_openshift_version(self): + for zones_enabled in (True, False): + for release, deployment_type, default_priorities in TEST_VARS: + release = release + '.1' + yield self.check_defaults_version, release, deployment_type, default_priorities, zones_enabled + + def check_defaults_version(self, release, deployment_type, default_priorities, + zones_enabled): + facts = copy.deepcopy(self.default_facts) + facts['openshift_version'] = release + facts['openshift']['common']['deployment_type'] = deployment_type + results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) + else: + assert_equal(results, default_priorities) + + def test_release_defaults(self): + for zones_enabled in (True, False): + for release, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled + + def test_v_release_defaults(self): + for zones_enabled in (True, False): + for release, deployment_type, default_priorities in TEST_VARS: + release = 'v' + release + yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled + + def test_trunc_openshift_release(self): + for release, deployment_type, default_priorities in TEST_VARS: + release = release + '.1' + yield self.check_defaults_release, release, deployment_type, default_priorities, False + + def check_defaults_release(self, release, deployment_type, default_priorities, + zones_enabled): + facts = copy.deepcopy(self.default_facts) + facts['openshift_release'] = release + facts['openshift']['common']['deployment_type'] = deployment_type + results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) + if zones_enabled: + assert_equal(results, default_priorities + [ZONE_PRIORITY]) + else: + assert_equal(results, default_priorities) + + def test_short_version_defaults(self): + for zones_enabled in (True, False): + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_short_version, short_version, deployment_type, default_priorities, zones_enabled + def check_defaults_short_version(self, release, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) @@ -95,6 +144,11 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_priorities) + def test_release_kwarg(self): + for zones_enabled in (True, False): + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_priorities, zones_enabled + def check_defaults_short_version_kwarg(self, release, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) @@ -107,6 +161,11 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_priorities) + def test_deployment_type_kwarg(self): + for zones_enabled in (True, False): + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_priorities, zones_enabled + def check_defaults_deployment_type_kwarg(self, release, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) @@ -119,6 +178,11 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_priorities) + def test_only_kwargs(self): + for zones_enabled in (True, False): + for short_version, deployment_type, default_priorities in TEST_VARS: + yield self.check_defaults_only_kwargs, short_version, deployment_type, default_priorities, zones_enabled + def check_defaults_only_kwargs(self, release, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) @@ -130,67 +194,3 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): assert_equal(results, default_priorities + [ZONE_PRIORITY]) else: assert_equal(results, default_priorities) - - def check_defaults_release(self, release, deployment_type, default_priorities, - zones_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_release'] = release - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) - if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) - else: - assert_equal(results, default_priorities) - - def check_defaults_version(self, release, deployment_type, default_priorities, - zones_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_version'] = release - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) - if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) - else: - assert_equal(results, default_priorities) - - def test_openshift_version(self): - for zones_enabled in (True, False): - for release, deployment_type, default_priorities in TEST_VARS: - release = release + '.1' - yield self.check_defaults_version, release, deployment_type, default_priorities, zones_enabled - - def test_v_release_defaults(self): - for zones_enabled in (True, False): - for release, deployment_type, default_priorities in TEST_VARS: - release = 'v' + release - yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled - - def test_release_defaults(self): - for zones_enabled in (True, False): - for release, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled - - def test_short_version_defaults(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_short_version, short_version, deployment_type, default_priorities, zones_enabled - - def test_only_kwargs(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_only_kwargs, short_version, deployment_type, default_priorities, zones_enabled - - def test_deployment_type_kwarg(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_priorities, zones_enabled - - def test_release_kwarg(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_priorities, zones_enabled - - def test_trunc_openshift_release(self): - for release, deployment_type, default_priorities in TEST_VARS: - release = release + '.1' - yield self.check_defaults_release, release, deployment_type, default_priorities, False -- cgit v1.2.3 From e7b4e49247097323d0ef07b5ca63759b5ab502ee Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 17:37:07 +0100 Subject: Make usage of short_version/release consistent This removes irrelevant differences between the two test files, making it easier to observe similarities. --- ...nshift_master_facts_default_predicates_tests.py | 22 +++++++-------- ...nshift_master_facts_default_priorities_tests.py | 31 +++++++++++----------- 2 files changed, 26 insertions(+), 27 deletions(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index a33c183f6..1d6de616a 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -98,9 +98,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_openshift_version(self): for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - release = release + '.1' - yield self.check_defaults_version, release, deployment_type, default_predicates, regions_enabled + for version, deployment_type, default_predicates in TEST_VARS: + version = version + '.1' + yield self.check_defaults_version, version, deployment_type, default_predicates, regions_enabled def check_defaults_version(self, version, deployment_type, default_predicates, regions_enabled): @@ -143,8 +143,8 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_short_version_defaults(self): for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_short_version, release, deployment_type, default_predicates, regions_enabled + for short_version, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_short_version, short_version, deployment_type, default_predicates, regions_enabled def check_defaults_short_version(self, short_version, deployment_type, default_predicates, regions_enabled): @@ -160,8 +160,8 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_short_version_kwarg(self): for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_short_version_kwarg, release, deployment_type, default_predicates, regions_enabled + for short_version, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_predicates, regions_enabled def check_defaults_short_version_kwarg(self, short_version, deployment_type, default_predicates, regions_enabled): @@ -177,8 +177,8 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_deployment_type_kwarg(self): for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_deployment_type_kwarg, release, deployment_type, default_predicates, regions_enabled + for short_version, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_predicates, regions_enabled def check_defaults_deployment_type_kwarg(self, short_version, deployment_type, default_predicates, regions_enabled): @@ -194,8 +194,8 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_only_kwargs(self): for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_only_kwargs, release, deployment_type, default_predicates, regions_enabled + for short_version, deployment_type, default_predicates in TEST_VARS: + yield self.check_defaults_only_kwargs, short_version, deployment_type, default_predicates, regions_enabled def check_defaults_only_kwargs(self, short_version, deployment_type, default_predicates, regions_enabled): diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 326af3e13..32edc4c34 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -86,14 +86,14 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_openshift_version(self): for zones_enabled in (True, False): - for release, deployment_type, default_priorities in TEST_VARS: - release = release + '.1' - yield self.check_defaults_version, release, deployment_type, default_priorities, zones_enabled + for version, deployment_type, default_priorities in TEST_VARS: + version = version + '.1' + yield self.check_defaults_version, version, deployment_type, default_priorities, zones_enabled - def check_defaults_version(self, release, deployment_type, default_priorities, + def check_defaults_version(self, version, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) - facts['openshift_version'] = release + facts['openshift_version'] = version facts['openshift']['common']['deployment_type'] = deployment_type results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) if zones_enabled: @@ -109,8 +109,7 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): def test_v_release_defaults(self): for zones_enabled in (True, False): for release, deployment_type, default_priorities in TEST_VARS: - release = 'v' + release - yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled + yield self.check_defaults_release, 'v' + release, deployment_type, default_priorities, zones_enabled def test_trunc_openshift_release(self): for release, deployment_type, default_priorities in TEST_VARS: @@ -133,10 +132,10 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): for short_version, deployment_type, default_priorities in TEST_VARS: yield self.check_defaults_short_version, short_version, deployment_type, default_priorities, zones_enabled - def check_defaults_short_version(self, release, deployment_type, + def check_defaults_short_version(self, short_version, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = release + facts['openshift']['common']['short_version'] = short_version facts['openshift']['common']['deployment_type'] = deployment_type results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) if zones_enabled: @@ -144,18 +143,18 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): else: assert_equal(results, default_priorities) - def test_release_kwarg(self): + def test_short_version_kwarg(self): for zones_enabled in (True, False): for short_version, deployment_type, default_priorities in TEST_VARS: yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_priorities, zones_enabled - def check_defaults_short_version_kwarg(self, release, deployment_type, + def check_defaults_short_version_kwarg(self, short_version, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) facts['openshift']['common']['deployment_type'] = deployment_type results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled, - short_version=release) + short_version=short_version) if zones_enabled: assert_equal(results, default_priorities + [ZONE_PRIORITY]) else: @@ -166,10 +165,10 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): for short_version, deployment_type, default_priorities in TEST_VARS: yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_priorities, zones_enabled - def check_defaults_deployment_type_kwarg(self, release, deployment_type, + def check_defaults_deployment_type_kwarg(self, short_version, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = release + facts['openshift']['common']['short_version'] = short_version results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled, deployment_type=deployment_type) @@ -183,12 +182,12 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): for short_version, deployment_type, default_priorities in TEST_VARS: yield self.check_defaults_only_kwargs, short_version, deployment_type, default_priorities, zones_enabled - def check_defaults_only_kwargs(self, release, deployment_type, + def check_defaults_only_kwargs(self, short_version, deployment_type, default_priorities, zones_enabled): facts = copy.deepcopy(self.default_facts) results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled, - short_version=release, + short_version=short_version, deployment_type=deployment_type) if zones_enabled: assert_equal(results, default_priorities + [ZONE_PRIORITY]) -- cgit v1.2.3 From c008153397d5a34a21301cb5dabb6fe27df2fe47 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 04:13:31 +0100 Subject: Replace assert_equal with plain assert In the intention to remove the dependency on nose and use only pytest. --- ...nshift_master_facts_default_predicates_tests.py | 26 ++++++++++------------ ...nshift_master_facts_default_priorities_tests.py | 26 ++++++++++------------ 2 files changed, 24 insertions(+), 28 deletions(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index 1d6de616a..855f42273 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -2,8 +2,6 @@ import copy import os import sys -from nose.tools import assert_equal - sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) from openshift_master_facts_default_predicates import LookupModule # noqa: E402 @@ -110,9 +108,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): results = self.lookup.run(None, variables=facts, regions_enabled=regions_enabled) if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) + assert results == default_predicates + [REGION_PREDICATE] else: - assert_equal(results, default_predicates) + assert results == default_predicates def test_release_defaults(self): for regions_enabled in (True, False): @@ -137,9 +135,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): results = self.lookup.run(None, variables=facts, regions_enabled=regions_enabled) if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) + assert results == default_predicates + [REGION_PREDICATE] else: - assert_equal(results, default_predicates) + assert results == default_predicates def test_short_version_defaults(self): for regions_enabled in (True, False): @@ -154,9 +152,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): results = self.lookup.run(None, variables=facts, regions_enabled=regions_enabled) if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) + assert results == default_predicates + [REGION_PREDICATE] else: - assert_equal(results, default_predicates) + assert results == default_predicates def test_short_version_kwarg(self): for regions_enabled in (True, False): @@ -171,9 +169,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): regions_enabled=regions_enabled, short_version=short_version) if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) + assert results == default_predicates + [REGION_PREDICATE] else: - assert_equal(results, default_predicates) + assert results == default_predicates def test_deployment_type_kwarg(self): for regions_enabled in (True, False): @@ -188,9 +186,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): regions_enabled=regions_enabled, deployment_type=deployment_type) if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) + assert results == default_predicates + [REGION_PREDICATE] else: - assert_equal(results, default_predicates) + assert results == default_predicates def test_only_kwargs(self): for regions_enabled in (True, False): @@ -205,6 +203,6 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): short_version=short_version, deployment_type=deployment_type) if regions_enabled: - assert_equal(results, default_predicates + [REGION_PREDICATE]) + assert results == default_predicates + [REGION_PREDICATE] else: - assert_equal(results, default_predicates) + assert results == default_predicates diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 32edc4c34..d27a48ede 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -2,8 +2,6 @@ import copy import os import sys -from nose.tools import assert_equal - sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) from openshift_master_facts_default_priorities import LookupModule # noqa: E402 @@ -97,9 +95,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): facts['openshift']['common']['deployment_type'] = deployment_type results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) + assert results == default_priorities + [ZONE_PRIORITY] else: - assert_equal(results, default_priorities) + assert results == default_priorities def test_release_defaults(self): for zones_enabled in (True, False): @@ -123,9 +121,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): facts['openshift']['common']['deployment_type'] = deployment_type results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) + assert results == default_priorities + [ZONE_PRIORITY] else: - assert_equal(results, default_priorities) + assert results == default_priorities def test_short_version_defaults(self): for zones_enabled in (True, False): @@ -139,9 +137,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): facts['openshift']['common']['deployment_type'] = deployment_type results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) + assert results == default_priorities + [ZONE_PRIORITY] else: - assert_equal(results, default_priorities) + assert results == default_priorities def test_short_version_kwarg(self): for zones_enabled in (True, False): @@ -156,9 +154,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): zones_enabled=zones_enabled, short_version=short_version) if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) + assert results == default_priorities + [ZONE_PRIORITY] else: - assert_equal(results, default_priorities) + assert results == default_priorities def test_deployment_type_kwarg(self): for zones_enabled in (True, False): @@ -173,9 +171,9 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): zones_enabled=zones_enabled, deployment_type=deployment_type) if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) + assert results == default_priorities + [ZONE_PRIORITY] else: - assert_equal(results, default_priorities) + assert results == default_priorities def test_only_kwargs(self): for zones_enabled in (True, False): @@ -190,6 +188,6 @@ class TestOpenShiftMasterFactsDefaultPredicates(object): short_version=short_version, deployment_type=deployment_type) if zones_enabled: - assert_equal(results, default_priorities + [ZONE_PRIORITY]) + assert results == default_priorities + [ZONE_PRIORITY] else: - assert_equal(results, default_priorities) + assert results == default_priorities -- cgit v1.2.3 From 95f11aa9410c8db4794b51932931e6ee3da46402 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 04:25:32 +0100 Subject: Make tests run with either nosetests or pytest And remove explicit dependencies on nose, replacing with pytest. The former is the way forward, for it is a better maintained test library, and a transitive dependency of `molecule`, the test framework we're using to add integration tests to this repo (work in progress). --- .../test/openshift_master_facts_bad_input_tests.py | 65 +++++++++++----------- ...nshift_master_facts_default_predicates_tests.py | 11 ++-- ...nshift_master_facts_default_priorities_tests.py | 11 ++-- 3 files changed, 42 insertions(+), 45 deletions(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py index ec6c7ae4a..e8da1e04a 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_bad_input_tests.py @@ -3,7 +3,7 @@ import os import sys from ansible.errors import AnsibleError -from nose.tools import raises +import pytest sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) @@ -11,48 +11,47 @@ from openshift_master_facts_default_predicates import LookupModule # noqa: E402 class TestOpenShiftMasterFactsBadInput(object): - def setUp(self): - self.lookup = LookupModule() - self.default_facts = { - 'openshift': { - 'common': {} - } + lookup = LookupModule() + default_facts = { + 'openshift': { + 'common': {} } + } - @raises(AnsibleError) def test_missing_openshift_facts(self): - facts = {} - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = {} + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_missing_deployment_type(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '10.10' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '10.10' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_missing_short_version_and_missing_openshift_release(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_unknown_deployment_types(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '1.1' - facts['openshift']['common']['deployment_type'] = 'bogus' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '1.1' + facts['openshift']['common']['deployment_type'] = 'bogus' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_unknown_origin_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'origin' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'origin' + self.lookup.run(None, variables=facts) - @raises(AnsibleError) def test_unknown_ocp_version(self): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = '0.1' - facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' - self.lookup.run(None, variables=facts) + with pytest.raises(AnsibleError): + facts = copy.deepcopy(self.default_facts) + facts['openshift']['common']['short_version'] = '0.1' + facts['openshift']['common']['deployment_type'] = 'openshift-enterprise' + self.lookup.run(None, variables=facts) diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index 855f42273..51547ce7e 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -86,13 +86,12 @@ TEST_VARS = [ class TestOpenShiftMasterFactsDefaultPredicates(object): - def setUp(self): - self.lookup = LookupModule() - self.default_facts = { - 'openshift': { - 'common': {} - } + lookup = LookupModule() + default_facts = { + 'openshift': { + 'common': {} } + } def test_openshift_version(self): for regions_enabled in (True, False): diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index d27a48ede..4fb900b98 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -74,13 +74,12 @@ TEST_VARS = [ class TestOpenShiftMasterFactsDefaultPredicates(object): - def setUp(self): - self.lookup = LookupModule() - self.default_facts = { - 'openshift': { - 'common': {} - } + lookup = LookupModule() + default_facts = { + 'openshift': { + 'common': {} } + } def test_openshift_version(self): for zones_enabled in (True, False): -- cgit v1.2.3 From d9c87a571f03fcd9eb386e4b112de3307d8c27c9 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 22:38:15 +0100 Subject: Replace nose yield-style tests w/ pytest fixtures --- roles/openshift_master_facts/test/conftest.py | 54 +++++ ...nshift_master_facts_default_predicates_tests.py | 221 +++++++++------------ ...nshift_master_facts_default_priorities_tests.py | 220 +++++++++----------- 3 files changed, 247 insertions(+), 248 deletions(-) create mode 100644 roles/openshift_master_facts/test/conftest.py (limited to 'roles') diff --git a/roles/openshift_master_facts/test/conftest.py b/roles/openshift_master_facts/test/conftest.py new file mode 100644 index 000000000..e67d24f04 --- /dev/null +++ b/roles/openshift_master_facts/test/conftest.py @@ -0,0 +1,54 @@ +import os +import sys + +import pytest + +sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) + +from openshift_master_facts_default_predicates import LookupModule as PredicatesLookupModule # noqa: E402 +from openshift_master_facts_default_priorities import LookupModule as PrioritiesLookupModule # noqa: E402 + + +@pytest.fixture() +def predicates_lookup(): + return PredicatesLookupModule() + + +@pytest.fixture() +def priorities_lookup(): + return PrioritiesLookupModule() + + +@pytest.fixture() +def facts(request): + return { + 'openshift': { + 'common': {} + } + } + + +@pytest.fixture(params=[True, False]) +def regions_enabled(request): + return request.param + + +@pytest.fixture(params=[True, False]) +def zones_enabled(request): + return request.param + + +def v_prefix(release): + """Prefix a release number with 'v'.""" + return "v" + release + + +def minor(release): + """Add a suffix to release, making 'X.Y' become 'X.Y.Z'.""" + return release + ".1" + + +@pytest.fixture(params=[str, v_prefix, minor]) +def release_mod(request): + """Modifies a release string to alternative valid values.""" + return request.param diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index 51547ce7e..bef02e548 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -1,10 +1,5 @@ -import copy -import os -import sys +import pytest -sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) - -from openshift_master_facts_default_predicates import LookupModule # noqa: E402 # Predicates ordered according to OpenShift Origin source: # origin/vendor/k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go @@ -85,123 +80,99 @@ TEST_VARS = [ ] -class TestOpenShiftMasterFactsDefaultPredicates(object): - lookup = LookupModule() - default_facts = { - 'openshift': { - 'common': {} - } - } +def test_openshift_version(predicates_lookup, openshift_version_fixture, regions_enabled): + facts, default_predicates = openshift_version_fixture + results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled) + if regions_enabled: + assert results == default_predicates + [REGION_PREDICATE] + else: + assert results == default_predicates + + +@pytest.fixture(params=TEST_VARS) +def openshift_version_fixture(request, facts): + version, deployment_type, default_predicates = request.param + version += '.1' + facts['openshift_version'] = version + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, default_predicates + + +def test_openshift_release(predicates_lookup, openshift_release_fixture, regions_enabled): + facts, default_predicates = openshift_release_fixture + results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled) + if regions_enabled: + assert results == default_predicates + [REGION_PREDICATE] + else: + assert results == default_predicates + + +@pytest.fixture(params=TEST_VARS) +def openshift_release_fixture(request, facts, release_mod): + release, deployment_type, default_predicates = request.param + facts['openshift_release'] = release_mod(release) + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, default_predicates + + +def test_short_version(predicates_lookup, short_version_fixture, regions_enabled): + facts, default_predicates = short_version_fixture + results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled) + if regions_enabled: + assert results == default_predicates + [REGION_PREDICATE] + else: + assert results == default_predicates + + +@pytest.fixture(params=TEST_VARS) +def short_version_fixture(request, facts): + short_version, deployment_type, default_predicates = request.param + facts['openshift']['common']['short_version'] = short_version + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, default_predicates + + +def test_short_version_kwarg(predicates_lookup, short_version_kwarg_fixture, regions_enabled): + facts, short_version, default_predicates = short_version_kwarg_fixture + results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled, short_version=short_version) + if regions_enabled: + assert results == default_predicates + [REGION_PREDICATE] + else: + assert results == default_predicates + + +@pytest.fixture(params=TEST_VARS) +def short_version_kwarg_fixture(request, facts): + short_version, deployment_type, default_predicates = request.param + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, short_version, default_predicates + + +def test_deployment_type_kwarg(predicates_lookup, deployment_type_kwarg_fixture, regions_enabled): + facts, deployment_type, default_predicates = deployment_type_kwarg_fixture + results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled, deployment_type=deployment_type) + if regions_enabled: + assert results == default_predicates + [REGION_PREDICATE] + else: + assert results == default_predicates + + +@pytest.fixture(params=TEST_VARS) +def deployment_type_kwarg_fixture(request, facts): + short_version, deployment_type, default_predicates = request.param + facts['openshift']['common']['short_version'] = short_version + return facts, deployment_type, default_predicates + + +def test_short_version_deployment_type_kwargs(predicates_lookup, short_version_deployment_type_kwargs_fixture, regions_enabled): + short_version, deployment_type, default_predicates = short_version_deployment_type_kwargs_fixture + results = predicates_lookup.run(None, regions_enabled=regions_enabled, short_version=short_version, deployment_type=deployment_type) + if regions_enabled: + assert results == default_predicates + [REGION_PREDICATE] + else: + assert results == default_predicates + - def test_openshift_version(self): - for regions_enabled in (True, False): - for version, deployment_type, default_predicates in TEST_VARS: - version = version + '.1' - yield self.check_defaults_version, version, deployment_type, default_predicates, regions_enabled - - def check_defaults_version(self, version, deployment_type, default_predicates, - regions_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_version'] = version - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates - - def test_release_defaults(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_release, release, deployment_type, default_predicates, regions_enabled - - def test_v_release_defaults(self): - for regions_enabled in (True, False): - for release, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_release, 'v' + release, deployment_type, default_predicates, regions_enabled - - def test_trunc_openshift_release(self): - for release, deployment_type, default_predicates in TEST_VARS: - release = release + '.1' - yield self.check_defaults_release, release, deployment_type, default_predicates, False - - def check_defaults_release(self, release, deployment_type, default_predicates, - regions_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_release'] = release - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates - - def test_short_version_defaults(self): - for regions_enabled in (True, False): - for short_version, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_short_version, short_version, deployment_type, default_predicates, regions_enabled - - def check_defaults_short_version(self, short_version, deployment_type, default_predicates, - regions_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = short_version - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates - - def test_short_version_kwarg(self): - for regions_enabled in (True, False): - for short_version, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_predicates, regions_enabled - - def check_defaults_short_version_kwarg(self, short_version, deployment_type, default_predicates, - regions_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled, - short_version=short_version) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates - - def test_deployment_type_kwarg(self): - for regions_enabled in (True, False): - for short_version, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_predicates, regions_enabled - - def check_defaults_deployment_type_kwarg(self, short_version, deployment_type, - default_predicates, regions_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = short_version - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled, - deployment_type=deployment_type) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates - - def test_only_kwargs(self): - for regions_enabled in (True, False): - for short_version, deployment_type, default_predicates in TEST_VARS: - yield self.check_defaults_only_kwargs, short_version, deployment_type, default_predicates, regions_enabled - - def check_defaults_only_kwargs(self, short_version, deployment_type, - default_predicates, regions_enabled): - facts = copy.deepcopy(self.default_facts) - results = self.lookup.run(None, variables=facts, - regions_enabled=regions_enabled, - short_version=short_version, - deployment_type=deployment_type) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates +@pytest.fixture(params=TEST_VARS) +def short_version_deployment_type_kwargs_fixture(request): + return request.param diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 4fb900b98..1343acb56 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -1,10 +1,5 @@ -import copy -import os -import sys +import pytest -sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, "lookup_plugins")) - -from openshift_master_facts_default_priorities import LookupModule # noqa: E402 DEFAULT_PRIORITIES_1_1 = [ {'name': 'LeastRequestedPriority', 'weight': 1}, @@ -73,120 +68,99 @@ TEST_VARS = [ ] -class TestOpenShiftMasterFactsDefaultPredicates(object): - lookup = LookupModule() - default_facts = { - 'openshift': { - 'common': {} - } - } - - def test_openshift_version(self): - for zones_enabled in (True, False): - for version, deployment_type, default_priorities in TEST_VARS: - version = version + '.1' - yield self.check_defaults_version, version, deployment_type, default_priorities, zones_enabled - - def check_defaults_version(self, version, deployment_type, default_priorities, - zones_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_version'] = version - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities - - def test_release_defaults(self): - for zones_enabled in (True, False): - for release, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_release, release, deployment_type, default_priorities, zones_enabled - - def test_v_release_defaults(self): - for zones_enabled in (True, False): - for release, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_release, 'v' + release, deployment_type, default_priorities, zones_enabled - - def test_trunc_openshift_release(self): - for release, deployment_type, default_priorities in TEST_VARS: - release = release + '.1' - yield self.check_defaults_release, release, deployment_type, default_priorities, False - - def check_defaults_release(self, release, deployment_type, default_priorities, - zones_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift_release'] = release - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities - - def test_short_version_defaults(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_short_version, short_version, deployment_type, default_priorities, zones_enabled - - def check_defaults_short_version(self, short_version, deployment_type, - default_priorities, zones_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = short_version - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, zones_enabled=zones_enabled) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities - - def test_short_version_kwarg(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_short_version_kwarg, short_version, deployment_type, default_priorities, zones_enabled - - def check_defaults_short_version_kwarg(self, short_version, deployment_type, - default_priorities, zones_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['deployment_type'] = deployment_type - results = self.lookup.run(None, variables=facts, - zones_enabled=zones_enabled, - short_version=short_version) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities - - def test_deployment_type_kwarg(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_deployment_type_kwarg, short_version, deployment_type, default_priorities, zones_enabled - - def check_defaults_deployment_type_kwarg(self, short_version, deployment_type, - default_priorities, zones_enabled): - facts = copy.deepcopy(self.default_facts) - facts['openshift']['common']['short_version'] = short_version - results = self.lookup.run(None, variables=facts, - zones_enabled=zones_enabled, - deployment_type=deployment_type) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities - - def test_only_kwargs(self): - for zones_enabled in (True, False): - for short_version, deployment_type, default_priorities in TEST_VARS: - yield self.check_defaults_only_kwargs, short_version, deployment_type, default_priorities, zones_enabled - - def check_defaults_only_kwargs(self, short_version, deployment_type, - default_priorities, zones_enabled): - facts = copy.deepcopy(self.default_facts) - results = self.lookup.run(None, variables=facts, - zones_enabled=zones_enabled, - short_version=short_version, - deployment_type=deployment_type) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities +def test_openshift_version(priorities_lookup, openshift_version_fixture, zones_enabled): + facts, default_priorities = openshift_version_fixture + results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled) + if zones_enabled: + assert results == default_priorities + [ZONE_PRIORITY] + else: + assert results == default_priorities + + +@pytest.fixture(params=TEST_VARS) +def openshift_version_fixture(request, facts): + version, deployment_type, default_priorities = request.param + version += '.1' + facts['openshift_version'] = version + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, default_priorities + + +def test_openshift_release(priorities_lookup, openshift_release_fixture, zones_enabled): + facts, default_priorities = openshift_release_fixture + results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled) + if zones_enabled: + assert results == default_priorities + [ZONE_PRIORITY] + else: + assert results == default_priorities + + +@pytest.fixture(params=TEST_VARS) +def openshift_release_fixture(request, facts, release_mod): + release, deployment_type, default_priorities = request.param + facts['openshift_release'] = release_mod(release) + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, default_priorities + + +def test_short_version(priorities_lookup, short_version_fixture, zones_enabled): + facts, default_priorities = short_version_fixture + results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled) + if zones_enabled: + assert results == default_priorities + [ZONE_PRIORITY] + else: + assert results == default_priorities + + +@pytest.fixture(params=TEST_VARS) +def short_version_fixture(request, facts): + short_version, deployment_type, default_priorities = request.param + facts['openshift']['common']['short_version'] = short_version + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, default_priorities + + +def test_short_version_kwarg(priorities_lookup, short_version_kwarg_fixture, zones_enabled): + facts, short_version, default_priorities = short_version_kwarg_fixture + results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled, short_version=short_version) + if zones_enabled: + assert results == default_priorities + [ZONE_PRIORITY] + else: + assert results == default_priorities + + +@pytest.fixture(params=TEST_VARS) +def short_version_kwarg_fixture(request, facts): + short_version, deployment_type, default_priorities = request.param + facts['openshift']['common']['deployment_type'] = deployment_type + return facts, short_version, default_priorities + + +def test_deployment_type_kwarg(priorities_lookup, deployment_type_kwarg_fixture, zones_enabled): + facts, deployment_type, default_priorities = deployment_type_kwarg_fixture + results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled, deployment_type=deployment_type) + if zones_enabled: + assert results == default_priorities + [ZONE_PRIORITY] + else: + assert results == default_priorities + + +@pytest.fixture(params=TEST_VARS) +def deployment_type_kwarg_fixture(request, facts): + short_version, deployment_type, default_priorities = request.param + facts['openshift']['common']['short_version'] = short_version + return facts, deployment_type, default_priorities + + +def test_short_version_deployment_type_kwargs(priorities_lookup, short_version_deployment_type_kwargs_fixture, zones_enabled): + short_version, deployment_type, default_priorities = short_version_deployment_type_kwargs_fixture + results = priorities_lookup.run(None, zones_enabled=zones_enabled, short_version=short_version, deployment_type=deployment_type) + if zones_enabled: + assert results == default_priorities + [ZONE_PRIORITY] + else: + assert results == default_priorities + + +@pytest.fixture(params=TEST_VARS) +def short_version_deployment_type_kwargs_fixture(request): + return request.param -- cgit v1.2.3 From a17ba66cb7a50f2d968ec5d6bca0a9722437f18c Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Sat, 18 Feb 2017 23:22:01 +0100 Subject: Extract assertion common to all tests as function --- ...nshift_master_facts_default_predicates_tests.py | 40 +++++++--------------- ...nshift_master_facts_default_priorities_tests.py | 40 +++++++--------------- 2 files changed, 24 insertions(+), 56 deletions(-) (limited to 'roles') diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py index bef02e548..25294d91a 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_predicates_tests.py @@ -80,15 +80,19 @@ TEST_VARS = [ ] -def test_openshift_version(predicates_lookup, openshift_version_fixture, regions_enabled): - facts, default_predicates = openshift_version_fixture - results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled) +def assert_ok(predicates_lookup, default_predicates, regions_enabled, **kwargs): + results = predicates_lookup.run(None, regions_enabled=regions_enabled, **kwargs) if regions_enabled: assert results == default_predicates + [REGION_PREDICATE] else: assert results == default_predicates +def test_openshift_version(predicates_lookup, openshift_version_fixture, regions_enabled): + facts, default_predicates = openshift_version_fixture + assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled) + + @pytest.fixture(params=TEST_VARS) def openshift_version_fixture(request, facts): version, deployment_type, default_predicates = request.param @@ -100,11 +104,7 @@ def openshift_version_fixture(request, facts): def test_openshift_release(predicates_lookup, openshift_release_fixture, regions_enabled): facts, default_predicates = openshift_release_fixture - results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates + assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled) @pytest.fixture(params=TEST_VARS) @@ -117,11 +117,7 @@ def openshift_release_fixture(request, facts, release_mod): def test_short_version(predicates_lookup, short_version_fixture, regions_enabled): facts, default_predicates = short_version_fixture - results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates + assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled) @pytest.fixture(params=TEST_VARS) @@ -134,11 +130,7 @@ def short_version_fixture(request, facts): def test_short_version_kwarg(predicates_lookup, short_version_kwarg_fixture, regions_enabled): facts, short_version, default_predicates = short_version_kwarg_fixture - results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled, short_version=short_version) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates + assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled, short_version=short_version) @pytest.fixture(params=TEST_VARS) @@ -150,11 +142,7 @@ def short_version_kwarg_fixture(request, facts): def test_deployment_type_kwarg(predicates_lookup, deployment_type_kwarg_fixture, regions_enabled): facts, deployment_type, default_predicates = deployment_type_kwarg_fixture - results = predicates_lookup.run(None, variables=facts, regions_enabled=regions_enabled, deployment_type=deployment_type) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates + assert_ok(predicates_lookup, default_predicates, variables=facts, regions_enabled=regions_enabled, deployment_type=deployment_type) @pytest.fixture(params=TEST_VARS) @@ -166,11 +154,7 @@ def deployment_type_kwarg_fixture(request, facts): def test_short_version_deployment_type_kwargs(predicates_lookup, short_version_deployment_type_kwargs_fixture, regions_enabled): short_version, deployment_type, default_predicates = short_version_deployment_type_kwargs_fixture - results = predicates_lookup.run(None, regions_enabled=regions_enabled, short_version=short_version, deployment_type=deployment_type) - if regions_enabled: - assert results == default_predicates + [REGION_PREDICATE] - else: - assert results == default_predicates + assert_ok(predicates_lookup, default_predicates, regions_enabled=regions_enabled, short_version=short_version, deployment_type=deployment_type) @pytest.fixture(params=TEST_VARS) diff --git a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py index 1343acb56..cec44faa4 100644 --- a/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py +++ b/roles/openshift_master_facts/test/openshift_master_facts_default_priorities_tests.py @@ -68,15 +68,19 @@ TEST_VARS = [ ] -def test_openshift_version(priorities_lookup, openshift_version_fixture, zones_enabled): - facts, default_priorities = openshift_version_fixture - results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled) +def assert_ok(priorities_lookup, default_priorities, zones_enabled, **kwargs): + results = priorities_lookup.run(None, zones_enabled=zones_enabled, **kwargs) if zones_enabled: assert results == default_priorities + [ZONE_PRIORITY] else: assert results == default_priorities +def test_openshift_version(priorities_lookup, openshift_version_fixture, zones_enabled): + facts, default_priorities = openshift_version_fixture + assert_ok(priorities_lookup, default_priorities, variables=facts, zones_enabled=zones_enabled) + + @pytest.fixture(params=TEST_VARS) def openshift_version_fixture(request, facts): version, deployment_type, default_priorities = request.param @@ -88,11 +92,7 @@ def openshift_version_fixture(request, facts): def test_openshift_release(priorities_lookup, openshift_release_fixture, zones_enabled): facts, default_priorities = openshift_release_fixture - results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities + assert_ok(priorities_lookup, default_priorities, variables=facts, zones_enabled=zones_enabled) @pytest.fixture(params=TEST_VARS) @@ -105,11 +105,7 @@ def openshift_release_fixture(request, facts, release_mod): def test_short_version(priorities_lookup, short_version_fixture, zones_enabled): facts, default_priorities = short_version_fixture - results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities + assert_ok(priorities_lookup, default_priorities, variables=facts, zones_enabled=zones_enabled) @pytest.fixture(params=TEST_VARS) @@ -122,11 +118,7 @@ def short_version_fixture(request, facts): def test_short_version_kwarg(priorities_lookup, short_version_kwarg_fixture, zones_enabled): facts, short_version, default_priorities = short_version_kwarg_fixture - results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled, short_version=short_version) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities + assert_ok(priorities_lookup, default_priorities, variables=facts, zones_enabled=zones_enabled, short_version=short_version) @pytest.fixture(params=TEST_VARS) @@ -138,11 +130,7 @@ def short_version_kwarg_fixture(request, facts): def test_deployment_type_kwarg(priorities_lookup, deployment_type_kwarg_fixture, zones_enabled): facts, deployment_type, default_priorities = deployment_type_kwarg_fixture - results = priorities_lookup.run(None, variables=facts, zones_enabled=zones_enabled, deployment_type=deployment_type) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities + assert_ok(priorities_lookup, default_priorities, variables=facts, zones_enabled=zones_enabled, deployment_type=deployment_type) @pytest.fixture(params=TEST_VARS) @@ -154,11 +142,7 @@ def deployment_type_kwarg_fixture(request, facts): def test_short_version_deployment_type_kwargs(priorities_lookup, short_version_deployment_type_kwargs_fixture, zones_enabled): short_version, deployment_type, default_priorities = short_version_deployment_type_kwargs_fixture - results = priorities_lookup.run(None, zones_enabled=zones_enabled, short_version=short_version, deployment_type=deployment_type) - if zones_enabled: - assert results == default_priorities + [ZONE_PRIORITY] - else: - assert results == default_priorities + assert_ok(priorities_lookup, default_priorities, zones_enabled=zones_enabled, short_version=short_version, deployment_type=deployment_type) @pytest.fixture(params=TEST_VARS) -- cgit v1.2.3