def __init__(self, ref_name): self.ref_name = ref_name self.project = Project.get(request.context['project_id']) if not self.project: # TODO: nice project not found error template abort(404, 'project not found') request.context['ref'] = ref_name
def test_list_a_few_projects(self, session): for p in range(20): Project('foo_%s' % p) session.commit() result = session.app.get('/api/repos/') assert result.status_int == 200 assert len(result.json) == 20
def __init__(self, _id): self.project = Project.get(request.context['project_id']) self.build = Build.get(_id) if not self.project: # TODO: nice project not found error template abort(404, 'project not found') if not self.build: # TODO: nice project not found error template abort(404, 'build not found')
def index_get(self): project = Project.get(request.context['project_id']) repos = Repo.query.filter_by( project=project, ref=request.context['ref'], sha1=request.context['sha1'], distro=request.context['distro'], distro_version=request.context['distro_version']).all() return [r.flavor for r in repos]
def setup(self): self.p = Project("ceph") self.data = dict( ref="master", sha1="sha1", url="jenkins.ceph.com/build", log_url="jenkins.ceph.com/build/console", build_id="250", status="failed", )
def test_list_sha1s_by_id(self, session): project = Project(name='ceph') Build(build_id=1, project=project, ref='master', sha1='1234') Build(build_id=2, project=project, ref='master', sha1='1234') Build(build_id=100, project=project, ref='master', sha1='1234') commit() result = session.app.get('/builds/ceph/master/1234/') assert result.namespace['builds'][0].build_id == '100' assert result.namespace['builds'][1].build_id == '2' assert result.namespace['builds'][2].build_id == '1'
def apply_filters(self, filters): # TODO: allow operators filters = deepcopy(filters) try: project = Project.filter_by(name=filters.pop('project')).first() query = Repo.filter_by(project=project) except KeyError: query = Repo.query if filters.get("distros", None): # TODO: we'll need some sort of schema validation here distro_list = util.parse_distro_query(filters.pop("distros")) distro_filter_list = [] has_arch_filter = False for distro in distro_list: # for deb-based distros we store codename in the db as version, # so try first with the codename, but fallback to # distro_version otherwise version_filter = distro["distro_codename"] or distro['distro_version'] if not version_filter: abort(400, "Invalid version or codename for distro: %s" % distro["distro"]) repo_filters = [Repo.distro == distro["distro"], Repo.distro_version == version_filter] if distro["arch"]: repo_filters.append(Arch.name == distro["arch"]) has_arch_filter = True distro_filter_list.append( and_(*repo_filters) ) if has_arch_filter: query = query.join(Repo.archs).filter(or_(*distro_filter_list)) else: query = query.filter(or_(*distro_filter_list)) for k, v in filters.items(): if k not in self.filters: # TODO: improve error reporting # 'invalid query params: %s' % k abort(400) if k in self.filters: query = self.filter_repo(k, v, query) return query
def test_get_index_shows_projects(self, session): Project("ceph") session.commit() result = session.app.get('/api/') assert result.status_int == 200 assert result.json == {'repos': ['ceph']}
def test_get_project_repos_is_empty(self, session): Project("ceph") session.commit() result = session.app.get('/api/repos/ceph/') assert result.json == []
def test_one_project_list_length(self, session): Project("ceph") session.commit() result = session.app.get('/api/repos/') assert result.status_int == 200 assert len(result.json.keys()) == 1
def test_list_a_project(self, session): Project("ceph") session.commit() result = session.app.get('/api/repos/') assert result.status_int == 200 assert "ceph" in result.json.keys()
def setup(self): self.p = Project("ceph") self.data = dict( distro="ubuntu", distro_version="trusty", )
def setup(self): self.p = Project("ceph") self.data = base_repo_data() self.repo = Repo(self.p, **self.data) Arch(name="x86_64", repo=self.repo)