Revision de4f53e6

b/test/ganeti.rapi.client_unittest.py
81 81

  
82 82

  
83 83
class RapiMock(object):
84

  
85 84
  def __init__(self):
86 85
    self._mapper = connector.Mapper()
87 86
    self._responses = []
88 87
    self._last_handler = None
89 88

  
90
  def AddResponse(self, response):
91
    self._responses.insert(0, response)
92

  
93
  def PopResponse(self):
94
    if len(self._responses) > 0:
95
      return self._responses.pop()
96
    else:
97
      return None
89
  def AddResponse(self, response, code=200):
90
    self._responses.insert(0, (code, response))
98 91

  
99 92
  def GetLastHandler(self):
100 93
    return self._last_handler
101 94

  
102 95
  def FetchResponse(self, path, method):
103
    code = 200
104
    response = None
105

  
106 96
    try:
107 97
      HandlerClass, items, args = self._mapper.getController(path)
108 98
      self._last_handler = HandlerClass(items, args, None)
109 99
      if not hasattr(self._last_handler, method.upper()):
110
        code = 501
111
        response = "Method not implemented"
100
        raise http.HttpNotImplemented(message="Method not implemented")
101

  
112 102
    except http.HttpException, ex:
113 103
      code = ex.code
114 104
      response = ex.message
105
    else:
106
      if not self._responses:
107
        raise Exception("No responses")
115 108

  
116
    if not response:
117
      response = self.PopResponse()
109
      (code, response) = self._responses.pop()
118 110

  
119 111
    return code, response
120 112

  

Also available in: Unified diff