Custom Search

Sunday, November 30, 2014

OpenStack Python Client Unit Testing mocked self.client.httpclient.request

1)
https://github.com/openstack/python-neutronclient/blob/master/neutronclient/tests/unit/test_cli20.py

def _test_create_resource(--):
    self.mox.StubOutWithMock(cmd, "get_client")
    self.mox.StubOutWithMock(self.client.httpclient, "request")
    cmd.get_client().MultipleTimes().AndReturn(self.client)

    self.client.httpclient.request(
        end_url(path, format=self.format), 'POST',
        body=mox_body,
        headers=mox.ContainsKeyValue(
        'X-Auth-Token', TOKEN)).AndReturn((MyResp(200), resstr)) <====

2)
https://github.com/openstack/python-neutronclient/blob/master/neutronclient/client.py

def do_request(self, url, method, **kwargs):
    resp, body = self._cs_request(self.endpoint_url + url, method,
                                  **kwargs)

def _cs_request(self, *args, **kwargs):

    #raise Exception(type(self.request)) <==
    resp, body = self.request(*args, **kargs) <=== self.client.httpclient.request




No comments:

Post a Comment