[IMP] runbot: adapt test for github status

Adapt test for eb7f5de . The mentioned commit fixes an issue that occurs
when updating github status. A test already exists but was assuming that
the build is in 'done' state when reaching the job_29.

With this commit, the build used in test is set to 'testing' state like
in the real cases.

Also, a new test is added to test the job_00_init which also send
github status but with a minimal build.

Finally, the runtime that should appear in status description was
forgotten in the previous commit. Now the runtime is always sent with
the github status.
This commit is contained in:
Christophe Monniez 2019-01-24 21:31:23 +01:00
parent ba542a204c
commit 3632463f80
3 changed files with 29 additions and 2 deletions

View File

@ -741,9 +741,9 @@ class runbot_build(models.Model):
state = 'pending'
elif build.state in ('running', 'done'):
state = 'error'
desc += " (runtime %ss)" % (build.job_time,)
else:
continue
desc += " (runtime %ss)" % (build.job_time,)
if build.result == 'ok':
state = 'success'
if build.result == 'ko':

View File

@ -19,6 +19,32 @@ class Test_Jobs(common.TransactionCase):
})
self.Build = self.env['runbot.build']
@patch('odoo.addons.runbot.models.repo.runbot_repo._domain')
@patch('odoo.addons.runbot.models.repo.runbot_repo._github')
@patch('odoo.addons.runbot.models.build.runbot_build._checkout')
def test_job_00_set_pending(self, mock_checkout, mock_github, mock_domain):
"""Test that job_00_init sets the pending status on github"""
mock_domain.return_value = 'runbotxx.somewhere.com'
build = self.Build.create({
'branch_id': self.branch_master.id,
'name': 'd0d0caca0000ffffffffffffffffffffffffffff',
'host': 'runbotxx',
'port': '1234',
'state': 'testing',
'job': 'job_00_init',
'job_start': datetime.datetime.now(),
'job_end': False,
})
res = self.Build._job_00_init(build, '/tmp/x.log')
self.assertEqual(res, -2)
expected_status = {
'state': 'pending',
'target_url': 'http://runbotxx.somewhere.com/runbot/build/%s' % build.id,
'description': 'runbot build %s (runtime 0s)' % build.dest,
'context': 'ci/runbot'
}
mock_github.assert_called_with('/repos/:owner/:repo/statuses/d0d0caca0000ffffffffffffffffffffffffffff', expected_status, ignore_errors=True)
@patch('odoo.addons.runbot.models.build.docker_get_gateway_ip')
@patch('odoo.addons.runbot.models.repo.runbot_repo._domain')
@patch('odoo.addons.runbot.models.repo.runbot_repo._github')
@ -41,7 +67,7 @@ class Test_Jobs(common.TransactionCase):
'branch_id': self.branch_master.id,
'name': 'd0d0caca0000ffffffffffffffffffffffffffff',
'port' : '1234',
'state': 'done',
'state': 'testing',
'job_start': a_time,
'job_end': a_time
})

View File

@ -37,6 +37,7 @@ class TestSchedule(common.TransactionCase):
'name': 'd0d0caca0000ffffffffffffffffffffffffffff',
'port': '1234',
'host': 'runbotxx',
'job_start': datetime.datetime.now(),
'job_type': 'testing',
'job': 'job_20_test_all'
})