def test_from_env_json(self, monkeypatch): exp = BuildsList.from_dict_list(self.data) monkeypatch.setenv('BUILDS_LIST', self.data_str) bl = BuildsList.from_env_json() assert id(exp) != id(bl) assert exp == bl monkeypatch.delenv('BUILDS_LIST', raising=False) bl = BuildsList.from_env_json() assert bl == []
def test_add(self): bl1 = BuildsList.from_dict_list(self.data) bl2 = BuildsList.from_dict_list(self.more_data) exp_data = self.data + self.more_data exp_bl = BuildsList.from_dict_list(exp_data) out_bl = bl1 + bl2 assert id(out_bl) != id(exp_bl) assert out_bl == exp_bl assert len(out_bl) == len(self.data) + len(self.more_data) assert isinstance(out_bl, BuildsList)
def test_init(self): assert BuildsList() == [] data = [ BuildPtr(job_name='j1', job_url='u1', queue_id=1), BuildPtr(job_name='j2', job_url='u2', build_id=2, build_url='bu2'), ] bl = BuildsList(data) assert bl == data data = [ BuildPtr(job_name='j1', job_url='u1', queue_id=1), dict(job_name='j2', job_url='u2', build_id=2, build_url='bu2'), ] with pytest.raises(TypeError): BuildsList(data)
def test_as_repoman_conf(self, monkeypatch): monkeypatch.setenv('JENKINS_URL', 'http://jenkins.example.org') exp = dedent(""" http://jenkins.example.org/u3/5 http://jenkins.example.org/u4/3 """).lstrip() bl = BuildsList.from_dict_list(self.more_data) out = bl.as_repoman_conf() assert exp == out
def visible_builds(self): """Get all builds from visible changes rtype: BuildsList returns: the set of builds tracked by visible_changes """ return BuildsList(chain.from_iterable( ChangeWithBuildsWrapper(c).builds for c in self.visible_changes ))
class ChangeWithBuilds(object_witp_opt_attrs): """Base/Mixin class for change objects that track build jobs to get built artifacts Builds are specified as a BuildsList object """ default_builds = BuildsList() def set_builds_from_env(self, env_var='BUILDS_LIST'): self.builds = BuildsList.from_env_json(env_var)
def test_from_currnt_build_env(self, monkeypatch): monkeypatch.setenv('JENKINS_URL', 'http://jenkins.example.com') monkeypatch.setenv('JOB_BASE_NAME', 'j1') monkeypatch.setenv('JOB_URL', 'http://jenkins.example.com/job/j1') monkeypatch.setenv('BUILD_ID', '7') monkeypatch.setenv('BUILD_URL', 'http://jenkins.example.com/job/j1/7') bl = BuildsList.from_currnt_build_env() bp = BuildPtr.from_currnt_build_env() assert len(bl) == 1 assert id(bl[0]) != id(bp) assert bl[0] == bp
def test_as_dict_list(self): bl = BuildsList.from_dict_list(self.data) out = bl.as_dict_list() assert self.data == out
def test_from_dict_list(self): bl = BuildsList.from_dict_list(self.data) assert len(self.data) == len(bl) assert next((False for b in bl if not isinstance(b, BuildPtr)), True)
def test_from_json_str(self): exp = BuildsList.from_dict_list(self.data) bl = BuildsList.from_json_str(self.data_str) assert id(exp) != id(bl) assert exp == bl
def set_current_build_from_env(self): self.builds = BuildsList.from_currnt_build_env()
def set_builds_from_env(self, env_var='BUILDS_LIST'): self.builds = BuildsList.from_env_json(env_var)