Skip to content

Commit

Permalink
test the uplift method
Browse files Browse the repository at this point in the history
  • Loading branch information
jhford committed Feb 26, 2014
1 parent 584fa48 commit 228bd9e
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/uplift_tests.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 228bd9e

Please sign in to comment.