Mock of HttpRequest. Do not construct directly, instead use RequestMockBuilder.
| 1607 | |
| 1608 | |
| 1609 | class HttpRequestMock(object): |
| 1610 | """Mock of HttpRequest. |
| 1611 | |
| 1612 | Do not construct directly, instead use RequestMockBuilder. |
| 1613 | """ |
| 1614 | |
| 1615 | def __init__(self, resp, content, postproc): |
| 1616 | """Constructor for HttpRequestMock |
| 1617 | |
| 1618 | Args: |
| 1619 | resp: httplib2.Response, the response to emulate coming from the request |
| 1620 | content: string, the response body |
| 1621 | postproc: callable, the post processing function usually supplied by |
| 1622 | the model class. See model.JsonModel.response() as an example. |
| 1623 | """ |
| 1624 | self.resp = resp |
| 1625 | self.content = content |
| 1626 | self.postproc = postproc |
| 1627 | if resp is None: |
| 1628 | self.resp = httplib2.Response({"status": 200, "reason": "OK"}) |
| 1629 | if "reason" in self.resp: |
| 1630 | self.resp.reason = self.resp["reason"] |
| 1631 | |
| 1632 | def execute(self, http=None): |
| 1633 | """Execute the request. |
| 1634 | |
| 1635 | Same behavior as HttpRequest.execute(), but the response is |
| 1636 | mocked and not really from an HTTP request/response. |
| 1637 | """ |
| 1638 | return self.postproc(self.resp, self.content) |
| 1639 | |
| 1640 | |
| 1641 | class RequestMockBuilder(object): |
no outgoing calls
no test coverage detected
searching dependent graphs…