def test_empty_field__add_missing_builds(self, get_data): url = "http://halob:8080/job/foo/%s" % config.JENKINS_API data = TestJob.URL_DATA[url].copy() data.update({"firstBuild": None}) get_data.return_value = data j = Job("http://halob:8080/job/foo/", "foo", self.J) initial_call_count = get_data.call_count j._add_missing_builds(data) self.assertEquals(get_data.call_count, initial_call_count)
def test_empty_field__add_missing_builds(self, get_data): url = 'http://halob:8080/job/foo/%s' % config.JENKINS_API data = TestJob.URL_DATA[url].copy() data.update({'firstBuild': None}) get_data.return_value = data j = Job('http://halob:8080/job/foo/', 'foo', self.J) initial_call_count = get_data.call_count j._add_missing_builds(data) self.assertEquals(get_data.call_count, initial_call_count)
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)
def test__add_missing_builds_no_first_build(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["firstBuild"] = None j._add_missing_builds(mock_data) self.assertEquals(initial_call_count, get_data.call_count)
def test__add_missing_builds_not_all_loaded(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) # to test this function we change data to not have one build # and set it to mark that firstBuild was not loaded # in that condition function will call j.get_data # and will use syntetic field 'allBuilds' to # repopulate 'builds' field with all builds mock_data = TestJob.URL_DATA[url].copy() mock_data['firstBuild'] = {'number': 1} del mock_data['builds'][-1] self.assertEquals(len(mock_data['builds']), 2) new_data = j._add_missing_builds(mock_data) self.assertEquals(len(new_data['builds']), 3)
def test__add_missing_builds_not_all_loaded(jenkins, monkeypatch): def fake_get_data(cls, url, tree): # pylint: disable=unused-argument return configs.JOB_DATA.copy() monkeypatch.setattr(JenkinsBase, 'get_data', fake_get_data) job = Job('http://halob:8080/job/foo/', 'foo', jenkins) # to test this function we change data to not have one build # and set it to mark that firstBuild was not loaded # in that condition function will call j.get_data # and will use syntetic field 'allBuilds' to # repopulate 'builds' field with all builds mock_data = configs.JOB_DATA.copy() mock_data['firstBuild'] = {'number': 1} del mock_data['builds'][-1] job._data = mock_data assert len(mock_data['builds']) == 2 new_data = job._add_missing_builds(mock_data) assert len(new_data['builds']) == 3