Implements the callable interface that discovery.build() expects of requestBuilder, which is to build an object compatible with HttpRequest.execute(). See that method for the description of the parameters and the expected response.
(
self,
http,
postproc,
uri,
method="GET",
body=None,
headers=None,
methodId=None,
resumable=None,
)
| 1682 | self.check_unexpected = check_unexpected |
| 1683 | |
| 1684 | def __call__( |
| 1685 | self, |
| 1686 | http, |
| 1687 | postproc, |
| 1688 | uri, |
| 1689 | method="GET", |
| 1690 | body=None, |
| 1691 | headers=None, |
| 1692 | methodId=None, |
| 1693 | resumable=None, |
| 1694 | ): |
| 1695 | """Implements the callable interface that discovery.build() expects |
| 1696 | of requestBuilder, which is to build an object compatible with |
| 1697 | HttpRequest.execute(). See that method for the description of the |
| 1698 | parameters and the expected response. |
| 1699 | """ |
| 1700 | if methodId in self.responses: |
| 1701 | response = self.responses[methodId] |
| 1702 | resp, content = response[:2] |
| 1703 | if len(response) > 2: |
| 1704 | # Test the body against the supplied expected_body. |
| 1705 | expected_body = response[2] |
| 1706 | if bool(expected_body) != bool(body): |
| 1707 | # Not expecting a body and provided one |
| 1708 | # or expecting a body and not provided one. |
| 1709 | raise UnexpectedBodyError(expected_body, body) |
| 1710 | if isinstance(expected_body, str): |
| 1711 | expected_body = json.loads(expected_body) |
| 1712 | body = json.loads(body) |
| 1713 | if body != expected_body: |
| 1714 | raise UnexpectedBodyError(expected_body, body) |
| 1715 | return HttpRequestMock(resp, content, postproc) |
| 1716 | elif self.check_unexpected: |
| 1717 | raise UnexpectedMethodError(methodId=methodId) |
| 1718 | else: |
| 1719 | model = JsonModel(False) |
| 1720 | return HttpRequestMock(None, "{}", model.response) |
| 1721 | |
| 1722 | |
| 1723 | class HttpMock(object): |
nothing calls this directly
no test coverage detected