当前位置: 首页>>代码示例>>Python>>正文


Python Job.get_build_metadata方法代码示例

本文整理汇总了Python中jenkinsapi.job.Job.get_build_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python Job.get_build_metadata方法的具体用法?Python Job.get_build_metadata怎么用?Python Job.get_build_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jenkinsapi.job.Job的用法示例。


在下文中一共展示了Job.get_build_metadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestJob

# 需要导入模块: from jenkinsapi.job import Job [as 别名]
# 或者: from jenkinsapi.job.Job import get_build_metadata [as 别名]

#.........这里部分代码省略.........
        j._add_missing_builds(mock_data)
        self.assertEquals(initial_call_count, get_data.call_count)

    @mock.patch.object(JenkinsBase, 'get_data')
    def test__add_missing_builds_no_builds(self, get_data):
        url = 'http://halob:8080/job/foo/%s' % config.JENKINS_API
        data = TestJob.URL_DATA[url].copy()
        get_data.return_value = data
        j = Job('http://halob:8080/job/foo/', 'foo', self.J)
        initial_call_count = get_data.call_count
        mock_data = TestJob.URL_DATA[url].copy()
        mock_data['builds'] = None
        j._add_missing_builds(mock_data)
        self.assertEquals(initial_call_count, get_data.call_count)

    @mock.patch.object(JenkinsBase, 'get_data')
    def test_get_params(self, get_data):
        url = 'http://halob:8080/job/foo/%s' % config.JENKINS_API
        get_data.return_value = TestJob.URL_DATA[url].copy()
        j = Job('http://halob:8080/job/foo/', 'foo', self.J)
        params = list(j.get_params())
        self.assertEquals(len(params), 2)

    @mock.patch.object(JenkinsBase, 'get_data')
    def test_get_params_list(self, get_data):
        url = 'http://halob:8080/job/foo/%s' % config.JENKINS_API
        get_data.return_value = TestJob.URL_DATA[url].copy()
        j = Job('http://halob:8080/job/foo/', 'foo', self.J)

        self.assertTrue(j.has_params())
        params = j.get_params_list()

        self.assertIsInstance(params, list)
        self.assertEquals(len(params), 2)
        self.assertEquals(params, ['param1', 'param2'])

    @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree)
    # @mock.patch.object(JenkinsBase, 'get_data', fakeGetLastBuild)
    def test_get_build(self):
        buildnumber = 1
        with mock.patch('jenkinsapi.job.Build') as build_mock:
            instance = build_mock.return_value
            build = self.j.get_build(buildnumber)
            self.assertEquals(build, instance)
            build_mock.assert_called_with('http://halob:8080/job/foo/1/',
                                          buildnumber, job=self.j)

    @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree)
    def test_get_build_metadata(self):
        buildnumber = 1
        with mock.patch('jenkinsapi.job.Build') as build_mock:
            instance = build_mock.return_value
            build = self.j.get_build_metadata(buildnumber)
            self.assertEquals(build, instance)
            build_mock.assert_called_with('http://halob:8080/job/foo/1/',
                                          buildnumber, job=self.j, depth=0)

    def assertJsonEqual(self, jsonA, jsonB, msg=None):
        A = json.loads(jsonA)
        B = json.loads(jsonB)
        self.assertEqual(
            A,
            B,
            msg
        )

    def test_get_json_for_single_param(self):
        params = {"B": "one two three"}
        expected = '{"parameter": {"name": "B", "value": "one two three"}, "statusCode": "303", "redirectTo": "."}'
        self.assertJsonEqual(
            Job.mk_json_from_build_parameters(params),
            expected
        )

    def test_get_json_for_many_params(self):
        params = {"B": "Honey", "A": "Boo", "C": 2}
        expected = '{"parameter": [{"name": "A", "value": "Boo"}, {"name": "B", "value": "Honey"}, {"name": "C", "value": "2"}], "statusCode": "303", "redirectTo": "."}'

        self.assertJsonEqual(
            Job.mk_json_from_build_parameters(params),
            expected
        )

    def test__mk_json_from_build_parameters(self):
        params = {'param1': 'value1', 'param2': 'value2'}
        result = self.j._mk_json_from_build_parameters(build_params=params)
        self.assertTrue(isinstance(result, dict))

        self.assertEquals(
            result,
            {"parameter": [{"name": "param1", "value": "value1"}, {
                "name": "param2", "value": "value2"}]}
        )

    def test_wrong_mk_json_from_build_parameters(self):
        with self.assertRaises(AssertionError) as ar:
            self.j.mk_json_from_build_parameters(build_params='bad parameter')

        self.assertEquals(
            str(ar.exception), 'Build parameters must be a dict')
开发者ID:Khan,项目名称:jenkinsapi,代码行数:104,代码来源:test_job.py


注:本文中的jenkinsapi.job.Job.get_build_metadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。