From 77c4fe302eea695a8873921183ceb2807336f746 Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Thu, 10 Jan 2019 15:21:18 +1100 Subject: [PATCH] Add some testing for ci_check_all_candidate_files Change-Id: Id5a89a684e377532858ba2e3e78dff47b688d52b --- openstack_election/tests/cmds/__init__.py | 0 .../tests/cmds/test_ci_checks.py | 57 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 openstack_election/tests/cmds/__init__.py create mode 100644 openstack_election/tests/cmds/test_ci_checks.py diff --git a/openstack_election/tests/cmds/__init__.py b/openstack_election/tests/cmds/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/openstack_election/tests/cmds/test_ci_checks.py b/openstack_election/tests/cmds/test_ci_checks.py new file mode 100644 index 00000000..3003f171 --- /dev/null +++ b/openstack_election/tests/cmds/test_ci_checks.py @@ -0,0 +1,57 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +import mock + +from openstack_election.cmds import ci_check_all_candidate_files +from openstack_election.tests import base +from openstack_election import utils + + +class TestFindModifiedCandidateFiles(base.ElectionTestCase): + @mock.patch('subprocess.check_output') + def test_find_modified_candidate_files_empty(self, mock_check_output): + mock_check_output.return_value = b'' + filenames = \ + ci_check_all_candidate_files.find_modified_candidate_files() + self.assertEqual([], filenames) + + @mock.patch('subprocess.check_output') + def test_find_modified_candidate_files_new_election(self, + mock_check_output): + check_output = (('configuration.yaml\n' + '%(path)s/.placeholder\n' + ) % ({'path': utils.CANDIDATE_PATH})).encode('utf-8') + expected_filenames = ['%s/.placeholder' % utils.CANDIDATE_PATH] + mock_check_output.return_value = check_output + filenames = \ + ci_check_all_candidate_files.find_modified_candidate_files() + self.assertEqual(expected_filenames, filenames) + + @mock.patch('subprocess.check_output') + def test_find_modified_candidate_files_all_good(self, mock_check_output): + check_output = (('configuration.yaml\n' + 'openstack_election/__init__py\n' + '%(path)s/cadidate\n' + '%(path)s/.placeholder\n' + ) % ({'path': utils.CANDIDATE_PATH})).encode('utf-8') + expected_filenames = ['%s/cadidate' % utils.CANDIDATE_PATH, + '%s/.placeholder' % utils.CANDIDATE_PATH + ] + mock_check_output.return_value = check_output + filenames = \ + ci_check_all_candidate_files.find_modified_candidate_files() + self.assertEqual(expected_filenames, filenames)