1import json
2from mock import patch
3
4import jenkins
5from tests.jobs.base import JenkinsJobsTestBase
6
7
8class JenkinsDebugJobInfoTest(JenkinsJobsTestBase):
9
10    @patch.object(jenkins.Jenkins, 'jenkins_open')
11    def test_debug_job_info(self, jenkins_mock):
12        job_info_to_return = {
13            u'building': False,
14            u'msg': u'test',
15            u'revision': 66,
16            u'user': u'unknown'
17        }
18        jenkins_mock.return_value = json.dumps(job_info_to_return)
19
20        self.j.debug_job_info(u'Test Job')
21
22        self.assertEqual(
23            jenkins_mock.call_args[0][0].url,
24            self.make_url('job/Test%20Job/api/json?depth=0'))
25        self._check_requests(jenkins_mock.call_args_list)
26
27    @patch.object(jenkins.Jenkins, 'jenkins_open')
28    def test_in_folder(self, jenkins_mock):
29        job_info_to_return = {
30            u'building': False,
31            u'msg': u'test',
32            u'revision': 66,
33            u'user': u'unknown'
34        }
35        jenkins_mock.return_value = json.dumps(job_info_to_return)
36
37        self.j.debug_job_info(u'a Folder/Test Job')
38
39        self.assertEqual(
40            jenkins_mock.call_args[0][0].url,
41            self.make_url('job/a%20Folder/job/Test%20Job/api/json?depth=0'))
42        self._check_requests(jenkins_mock.call_args_list)
43