From 6ff6b6ba188bbadffb619edf16475c896a447aef Mon Sep 17 00:00:00 2001 From: Scott Bahling Date: Thu, 3 Mar 2016 02:11:36 +0100 Subject: Add ObsSourceApi class --- obsapi/sourceapi.py | 47 +++++++++++++++++++++++++++++++ test/test_obs_source_api.py | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 obsapi/sourceapi.py create mode 100644 test/test_obs_source_api.py 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 '' in xml + + +def test_source_get_pkg(): + xml = sourceapi.get(prj, pkg) + assert ''.format(prj) in xml + + +def test_source_get_meta_pkg(): + xml = sourceapi.get_meta(prj, pkg) + assert ''.format(pkg, prj) in xml + + +def test_source_get_prj_attributes(): + xml = sourceapi.get_attribute(prj) + assert '' in xml + + +def test_source_get_prj_attribute(): + xml = sourceapi.get_attribute(prj, attribute='OBS:MaintenanceIdTemplate') + assert '' 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 '' 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 '' in xml -- cgit v1.2.3