def _request_mock(self, method, url, **kwargs):
        """
        :param method:
        :param url:
        :param kwargs:
        :rtype: requests.Response
        """
        # TODO: make it simplier, mocking and replacing requests.request of BZAObject
        if method == 'GET':
            resp = self.mock_get[url]
        elif method == 'POST':
            resp = self.mock_post[url]
        elif method == 'PATCH':
            resp = self.mock_patch[url]
        else:
            raise ValueError()

        response = requests.Response()

        if isinstance(resp, list):
            resp = resp.pop(0)

        data = kwargs['data']
        ROOT_LOGGER.debug("Emulated %s %s %s: %s", method, url,
                          ("%s" % data)[:4096], resp)
        self.requests.append({"method": method, "url": url, "data": data})
        if isinstance(resp, BaseException):
            raise resp
        response._content = to_json(resp)
        response.status_code = 200
        return response
Beispiel #2
0
    def _request_mock(self, method, url, **kwargs):
        """
        :param method:
        :param url:
        :param kwargs:
        :rtype: requests.Response
        """
        # TODO: make it simplier, mocking and replacing requests.request of BZAObject
        if method == 'GET':
            resp = self.mock_get[url]
        elif method == 'POST':
            resp = self.mock_post[url]
        elif method == 'PATCH':
            resp = self.mock_patch[url]
        else:
            raise ValueError()

        response = requests.Response()

        if isinstance(resp, list):
            resp = resp.pop(0)

        data = kwargs['data']
        ROOT_LOGGER.debug("Emulated %s %s %s: %s", method, url, ("%s" % data)[:4096], resp)
        self.requests.append({"method": method, "url": url, "data": data})
        if isinstance(resp, BaseException):
            raise resp
        response._content = to_json(resp)
        response.status_code = 200
        return response
 def close(self):
     ROOT_LOGGER.debug("Emulated close")
 def setblocking(self, state):
     ROOT_LOGGER.debug("Emulate setblocking=%s", state)
 def send(self, data, flags=None):
     self.sent_data += data
     ROOT_LOGGER.debug("Emulated send: %s", data)
 def recv(self, buf_size, flags=None):
     data = self.recv_data[:buf_size]
     self.recv_data = self.recv_data[buf_size + 1:]
     ROOT_LOGGER.debug("Emulated recv: %s", data)
     return data
 def connect(self, address):
     ROOT_LOGGER.debug("Emulated connect to %s", address)
 def dump_config(self):
     """ test """
     fname = temp_file()
     self.config.dump(fname, Configuration.JSON)
     with open(fname) as fh:
         ROOT_LOGGER.debug("JSON:\n%s", fh.read())
Beispiel #9
0
 def close(self):
     ROOT_LOGGER.debug("Emulated close")
Beispiel #10
0
 def setblocking(self, state):
     ROOT_LOGGER.debug("Emulate setblocking=%s", state)
Beispiel #11
0
 def send(self, data, flags=None):
     self.sent_data += data
     ROOT_LOGGER.debug("Emulated send: %s", data)
Beispiel #12
0
 def recv(self, buf_size, flags=None):
     data = self.recv_data[:buf_size]
     self.recv_data = self.recv_data[buf_size + 1:]
     ROOT_LOGGER.debug("Emulated recv: %s", data)
     return data
Beispiel #13
0
 def connect(self, address):
     ROOT_LOGGER.debug("Emulated connect to %s", address)
Beispiel #14
0
 def dump_config(self):
     """ test """
     fname = temp_file()
     self.config.dump(fname, Configuration.JSON)
     with open(fname) as fh:
         ROOT_LOGGER.debug("JSON:\n%s", fh.read())