summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--obsapi/buildapi.py53
-rw-r--r--test/test_obs_build_api.py124
2 files changed, 177 insertions, 0 deletions
diff --git a/obsapi/buildapi.py b/obsapi/buildapi.py
new file mode 100644
index 0000000..40054b1
--- /dev/null
+++ b/obsapi/buildapi.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+#
+from obsapi.httpapi import ObsHttpApi
+
+class ObsBuildApi(ObsHttpApi):
+
+ rootapi = '/build/'
+
+ def __get(self, *args, **kwargs):
+ return super(ObsBuildApi, self).get(*args, **kwargs)
+
+ def __put(self, *args, **kwargs):
+ return super(ObsBuildApi, self).put(*args, **kwargs)
+
+ def get(self, prj='', repo='', arch='', pkg='', binaryname='', view=None):
+ return self.__get(prj, repo, arch, pkg, binaryname, view=view)
+
+ def get_builddepinfo(self, prj, pkg, repo, arch):
+ return self.__get(prj, repo, arch, '_builddepinfo', package=pkg)
+
+ def get_buildconfig(self, prj, repo):
+ return self.__get(prj, repo, '_buildconfig')
+
+ def get_buildinfo(self, prj, pkg, repo, arch):
+ return self.__get(prj, repo, arch, pkg, '_buildinfo')
+
+ def get_jobhistory(self, prj, repo, arch, pkg=None, code=None, limit=None):
+ return self.__get(prj, repo, arch, '_jobhistory',
+ package=pkg, code=code, limit=limit)
+
+ def get_result(self, prj):
+ return self.__get(prj, '_result')
+
+ def get_workstatus(self):
+ return self.__get('_workerstatus')
+
+ def get_history(self, prj, repo, arch, pkg):
+ return self.__get(prj, repo, arch, pkg, '_history')
+
+ def get_reason(self, prj, repo, arch, pkg):
+ return self.__get(prj, repo, arch, pkg, '_reason')
+
+ def get_jobstatus(self, prj, repo, arch, pkg):
+ return self.__get(prj, repo, arch, pkg, '_jobstatus')
+
+ def get_status(self, prj, repo, arch, pkg):
+ return self.__get(prj, repo, arch, pkg, '_status')
+
+ def get_log(self, prj, repo, arch, pkg):
+ return self.__get(prj, repo, arch, pkg, '_log')
+
+ def get_repository(self, prj, repo, arch, binaryname=''):
+ return self.__get(prj, repo, arch, '_repository', binaryname)
diff --git a/test/test_obs_build_api.py b/test/test_obs_build_api.py
new file mode 100644
index 0000000..08515ec
--- /dev/null
+++ b/test/test_obs_build_api.py
@@ -0,0 +1,124 @@
+from obsapi.buildapi import ObsBuildApi
+
+prj = 'Test:obsapi'
+pkg = 'suse-hello-1.0'
+repo = 'SLE_12'
+arch = 'x86_64'
+
+buildapi = ObsBuildApi(apiurl='https://api.suse.com')
+
+
+def test_build_get():
+ xml = buildapi.get()
+ assert '<directory>' in xml
+
+
+def test_build_get_prj():
+ xml = buildapi.get(prj)
+ assert '<directory>' in xml
+
+
+def test_build_get_repo():
+ xml = buildapi.get(prj, repo)
+ assert '<directory>' in xml
+
+
+def test_build_get_arch():
+ xml = buildapi.get(prj, repo, arch)
+ assert '<directory>' in xml
+
+
+def test_build_get_binary_list():
+ xml = buildapi.get(prj, repo, arch, pkg)
+ assert '<binarylist>' in xml
+ assert '<binary filename="suse-hello-1.0-2.1.src.rpm"' in xml
+
+
+def test_build_get_binary():
+ bname = '_statistics'
+ binary = buildapi.get(prj, repo, arch, pkg, bname)
+ assert '<buildstatistics>' in binary
+
+
+def test_build_get_binary_fileinfo():
+ bname = 'suse-hello-1.0-2.1.src.rpm'
+ xml = buildapi.get(prj, repo, arch, pkg, bname, view='fileinfo')
+ assert '<fileinfo filename="{}">'.format(bname) in xml
+
+
+def test_build_get_binary_fileinfo_ext():
+ bname = 'suse-hello-1.0-2.1.src.rpm'
+ xml = buildapi.get(prj, repo, arch, pkg, bname, view='fileinfo_ext')
+ assert '<fileinfo filename="{}">'.format(bname) in xml
+ assert '<requires_ext' in xml
+
+
+def test_build_get_builddepinfo():
+ xml = buildapi.get_builddepinfo(prj, pkg, repo, arch)
+ assert '<builddepinfo>' in xml
+
+
+def test_build_get_buildconf():
+ buildconfig = buildapi.get_buildconfig(prj, repo)
+ assert '%define _project Test:obsapi' in buildconfig
+
+
+def test_build_get_buildinfo():
+ xml = buildapi.get_buildinfo(prj, pkg, repo, arch)
+ assert '<buildinfo ' in xml
+
+
+def test_build_get_jobhistory():
+ xml = buildapi.get_jobhistory(prj, repo, arch)
+ assert '<jobhistlist>' in xml
+
+
+def test_build_get_jobhistory_pkg():
+ xml = buildapi.get_jobhistory(prj, repo, arch, pkg)
+ assert '<jobhistlist>' in xml
+
+
+def test_build_get_result():
+ xml = buildapi.get_result(prj)
+ assert '<resultlist' in xml
+
+
+def test_build_get_workerstatus():
+ xml = buildapi.get_workstatus()
+ assert '<workerstatus' in xml
+
+
+def test_build_get_history():
+ xml = buildapi.get_history(prj, repo, arch, pkg)
+ assert '<buildhistory>' in xml
+
+
+def test_build_get_reason():
+ xml = buildapi.get_reason(prj, repo, arch, pkg)
+ assert '<reason>' in xml
+
+
+# def test_build_get_jobstatus():
+# xml = buildapi.get_jobstatus(prj, repo, arch, pkg)
+# assert '<None/>' in xml
+
+
+def test_build_get_status():
+ xml = buildapi.get_status(prj, repo, arch, pkg)
+ assert '<status' in xml
+
+
+def test_build_get_log():
+ log = buildapi.get_log(prj, repo, arch, pkg)
+ assert '[ 0s]' in log
+
+
+def test_build_get_repository():
+ xml = buildapi.get_repository(prj, repo, arch)
+ assert '<binarylist>' in xml
+
+
+def test_build_get_repository_binary():
+ bname = 'suse-hello-kmp-default.rpm'
+ binary = buildapi.get_repository(prj, repo, arch, bname)
+ assert len(binary) == 25869