diff options
| author | Scott Bahling <sbahling@suse.de> | 2016-03-03 02:11:36 +0100 |
|---|---|---|
| committer | Scott Bahling <sbahling@suse.de> | 2016-03-03 02:11:36 +0100 |
| commit | 6ff6b6ba188bbadffb619edf16475c896a447aef (patch) | |
| tree | c766447118733ae3e2f726fff269ca20c9c4192b | |
| parent | 3f1196fbc783b77af647cebd99400edcf465dc9c (diff) | |
| download | obsapi-6ff6b6ba188bbadffb619edf16475c896a447aef.tar.gz obsapi-6ff6b6ba188bbadffb619edf16475c896a447aef.tar.xz obsapi-6ff6b6ba188bbadffb619edf16475c896a447aef.zip | |
Add ObsSourceApi class
| -rw-r--r-- | obsapi/sourceapi.py | 47 | ||||
| -rw-r--r-- | test/test_obs_source_api.py | 68 |
2 files changed, 115 insertions, 0 deletions
diff --git a/obsapi/sourceapi.py b/obsapi/sourceapi.py new file mode 100644 index 0000000..4841ad9 --- /dev/null +++ b/obsapi/sourceapi.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# +from obsapi.httpapi import ObsHttpApi + + +class ObsSourceApi(ObsHttpApi): + + rootapi = '/source/' + + def __get(self, *args, **kwargs): + return super(ObsSourceApi, self).get(*args, **kwargs) + + def __put(self, *args, **kwargs): + return super(ObsSourceApi, self).put(*args, **kwargs) + + def get(self, prj, pkg='', filename=''): + return self.__get(prj, pkg, filename) + + def put(self, prj, pkg, filename, data): + return self.__put(prj, pkg, filename, data=data) + + def get_meta(self, prj, pkg=''): + return self.__get(prj, pkg, '_meta') + + def put_meta(self, prj, xml, pkg=None): + return self.__put(prj, pkg, '_meta', data=xml) + + def get_attribute(self, prj, pkg='', binary='', attribute=''): + return self.__get(prj, pkg, binary, '_attribute', attribute) + + def get_config(self, prj): + return self.__get(prj, '_config') + + def put_config(self, prj, data): + return self.__put(prj, '_config', data=data) + + def get_pattern(self, prj, patternfile=''): + return self.__get(prj, '_pattern', patternfile) + + def put_pattern(self, prj, patternfile, data): + return self.__put(prj, '_pattern', patternfile, data=data) + + def get_pubkey(self, prj): + return self.__get(prj, '_pubkey') + + def get_history(self, prj, pkg): + return self.__get(prj, pkg, '_history') diff --git a/test/test_obs_source_api.py b/test/test_obs_source_api.py new file mode 100644 index 0000000..205e344 --- /dev/null +++ b/test/test_obs_source_api.py @@ -0,0 +1,68 @@ +from obsapi.sourceapi import ObsSourceApi + + +prj = 'Test:obsapi' +pkg = 'suse-hello-1.0' +repo = 'SLE_12' +arch = 'x86_64' + +sourceapi = ObsSourceApi(apiurl='https://api.suse.com') + + +def test_source_get_prj(): + xml = sourceapi.get(prj) + assert '<entry name="suse-hello-1.0"/>' in xml + + +def test_source_get_pkg(): + xml = sourceapi.get(prj, pkg) + assert '<directory name="suse-hello-1.0"' in xml + + +def test_source_get_file(): + source_file = sourceapi.get(prj, pkg, 'COPYING') + assert 'GNU GENERAL PUBLIC LICENSE' in source_file + + +def test_source_get_meta_prj(): + xml = sourceapi.get_meta(prj) + assert '<project name="{}">'.format(prj) in xml + + +def test_source_get_meta_pkg(): + xml = sourceapi.get_meta(prj, pkg) + assert '<package name="{}" project="{}">'.format(pkg, prj) in xml + + +def test_source_get_prj_attributes(): + xml = sourceapi.get_attribute(prj) + assert '<attributes>' in xml + + +def test_source_get_prj_attribute(): + xml = sourceapi.get_attribute(prj, attribute='OBS:MaintenanceIdTemplate') + assert '<attributes>' in xml + assert 'name="MaintenanceIdTemplate"' in xml + assert 'namespace="OBS"' in xml + + +def test_source_get_pkg_attributes(): + xml = sourceapi.get_attribute(prj, pkg) + assert '<attributes>' in xml + assert 'name="ScreenShots"' in xml + assert 'namespace="OBS"' in xml + + +def test_source_get_prj_config(): + config = sourceapi.get_config(prj) + assert 'Macros:' in config + + +def test_source_get_prj_pubkey(): + pubkey = sourceapi.get_pubkey(prj) + assert '-BEGIN PGP PUBLIC KEY BLOCK-' in pubkey + + +def test_source_get_history(): + xml = sourceapi.get_history(prj, pkg) + assert '<revisionlist>' in xml |
