diff --git a/tests/uplift_tests.py b/tests/uplift_tests.py index d902eba..b6d2b8e 100644 --- a/tests/uplift_tests.py +++ b/tests/uplift_tests.py @@ -3,6 +3,7 @@ import json from mock import patch import tempfile +import copy import gaia_uplift.git as git import gaia_uplift.bzapi as bzapi @@ -281,3 +282,84 @@ def test_existing(self): actual = subject.build_uplift_requirements(None) self.assertEqual(expected, actual) + + +class Uplift(unittest.TestCase): + def setUp(self): + self.old_config = c.json_file + self.config = os.path.join(os.path.dirname(__file__), 'uplift_tests_config.json') + c.change_file(self.config) + + def tearDown(self): + c.change_file(self.old_config) + + def test_success(self): + with patch('gaia_uplift.uplift.order_commits') as order_commits, \ + patch('gaia_uplift.uplift.uplift_commit') as uplift_commit, \ + patch('gaia_uplift.git.sort_commits') as sort_commits, \ + patch('gaia_uplift.git.create_gaia') as create_gaia: + + uplift_outcome = { + 'success': {'v3': '321dcba'}, + 'failure': [] + } + + requirements = { + '1': { + 'needed_on': [u'v3'], + 'already_fixed_on': [], + 'summary': "success", + 'commits': ["abcd123"] + } + } + + expected = copy.deepcopy(requirements) + expected['1']['uplift_status'] = { + 'abcd123': uplift_outcome + } + expected['1']['flags_to_set'] = { + 'v3-status': 'fixed' + } + + # Set up mocks + uplift_commit.return_value = uplift_outcome + order_commits.return_value = ['abcd123'] + sort_commits.return_value = ['abcd123'] + + actual = subject.uplift(None, None, requirements) + self.assertEqual(expected, actual) + + def test_failure(self): + with patch('gaia_uplift.uplift.order_commits') as order_commits, \ + patch('gaia_uplift.uplift.uplift_commit') as uplift_commit, \ + patch('gaia_uplift.git.sort_commits') as sort_commits, \ + patch('gaia_uplift.git.create_gaia') as create_gaia: + + uplift_outcome = { + 'success': {}, + 'failure': ['v3'] + } + + requirements = { + '1': { + 'needed_on': [u'v3'], + 'already_fixed_on': [], + 'summary': "success", + 'commits': ["abcd123"] + } + } + + expected = copy.deepcopy(requirements) + expected['1']['uplift_status'] = { + 'abcd123': uplift_outcome + } + expected['1']['flags_to_set'] = {} + + # Set up mocks + uplift_commit.return_value = uplift_outcome + order_commits.return_value = ['abcd123'] + sort_commits.return_value = ['abcd123'] + + actual = subject.uplift(None, None, requirements) + self.assertEqual(expected, actual) +