diff --git a/tests/OBSLocal.py b/tests/OBSLocal.py index 028f49b0..03869108 100644 --- a/tests/OBSLocal.py +++ b/tests/OBSLocal.py @@ -195,6 +195,7 @@ class StagingWorkflow(object): self.requests = [] self.groups = [] self.users = [] + self.attributes = {} logging.basicConfig() # clear cache from other tests - otherwise the VCR is replayed depending @@ -230,6 +231,10 @@ class StagingWorkflow(object): self.config = Config(APIURL, project) def create_attribute_type(self, namespace, name, values=None): + if not namespace in self.attributes: self.attributes[namespace] = [] + + if not name in self.attributes[namespace]: self.attributes[namespace].append(name) + meta = """ @@ -484,20 +489,56 @@ class StagingWorkflow(object): def remove(self): print('deleting staging workflow') + for project in self.projects.values(): project.remove() for request in self.requests: request.revoke() for group in self.groups: - url = osc.core.makeurl(APIURL, ['group', group]) - try: - osc.core.http_DELETE(url) - except HTTPError: - pass + self.remove_group(group) + for namespace in self.attributes: + self.remove_attributes(namespace) + print('done') + if hasattr(self.api, '_invalidate_all'): self.api._invalidate_all() + def remove_group(self, group): + """Removes a group from the OBS instance + + :param group: name of the group to remove + :type group: str + """ + print('deleting group', group) + url = osc.core.makeurl(APIURL, ['group', group]) + self._safe_delete(url) + + def remove_attributes(self, namespace): + """Removes an attributes namespace and all the attributes it contains + + :param namespace: attributes namespace to remove + :type namespace: str + """ + for name in self.attributes[namespace]: + print('deleting attribute {}:{}'.format(namespace, name)) + url = osc.core.makeurl(APIURL, ['attribute', namespace, name, '_meta']) + self._safe_delete(url) + print('deleting namespace', namespace) + url = osc.core.makeurl(APIURL, ['attribute', namespace, '_meta']) + self._safe_delete(url) + + def _safe_delete(self, url): + """Performs a delete request to the OBS instance, ignoring possible http errors + + :param url: url to use for the http delete request + :type url: str + """ + try: + osc.core.http_DELETE(url) + except HTTPError: + pass + class Project(object): """This class represents a project in the testing environment of the release tools. It usually corresponds to a project in the local OBS instance that is used by the tests.