Implement a way to use custom statuses

This commit is contained in:
Michal Hrusecky 2014-03-04 15:13:19 +01:00 committed by Michal Hrusecky
parent 23ec30a4ca
commit ba8dd50bd5
2 changed files with 10 additions and 5 deletions

View File

@ -145,6 +145,12 @@ class OBS:
reply = self.responses[request.method][path]
# We have something to reply with
if reply:
# It's a dict, therefore there is return code as well
if isinstance(reply, dict):
ret_code = reply['status']
reply = reply['reply']
else:
ret_code = 200
# It's a list, so take the first
if isinstance(reply, list):
reply = reply.pop(0)
@ -152,13 +158,13 @@ class OBS:
if isinstance(reply, string_types):
# It's XML
if reply.startswith('<'):
return (200, headers, reply)
return (ret_code, headers, reply)
# It's fixture
else:
return (200, headers, self._get_fixture_content(reply))
return (ret_code, headers, self._get_fixture_content(reply))
# All is left is callback function
else:
return (200, headers, reply(self.responses, request, uri))
return (ret_code, headers, reply(self.responses, request, uri))
# No possible response found
else:
if len(path) == 0:

View File

@ -55,8 +55,7 @@ class TestSelect(unittest.TestCase):
# search for requests
self.obs.responses['GET']['/request'] = '<collection matches="0"/>'
# TODO: it's actually 404 - but OBS class can't handle that ;(
self.obs.responses['GET']['/request/bash'] = '<collection matches="0"/>'
self.obs.responses['GET']['/request/bash'] = {'status': 404, 'reply': '<collection matches="0"/>' }
with self.assertRaises(oscerr.WrongArgs) as cm:
SelectCommand(self.obs.api).perform('openSUSE:Factory:Staging:A', ['bash'])