def test_post(self, mock_post): mock_post.return_value = MockResponse() cert_post("any url", data="any data", headers={"a": 0}) mock_post.assert_called_with("any url", data="any data", headers={"a": 0}, pkcs12_filename="PKCS12_FILENAME", pkcs12_password="******") # headers is a default argument response = cert_post("any url", data="any data", headers={}) mock_post.assert_called_with("any url", data="any data", headers={}, pkcs12_filename="PKCS12_FILENAME", pkcs12_password="******") self.assertIsInstance(response, MockResponse)
def _make_request(self, request_template: StufRequest): """Makes the MKS request :param request_template: :return: """ soap_headers = { 'Soapaction': request_template.soap_action, 'Content-Type': 'text/xml' } url = f'{ROUTE_SCHEME}://{ROUTE_NETLOC}{ROUTE_PATH_310}' return cert_post(url, data=request_template.to_string(), headers=soap_headers)
def _post_stuf(url, data, headers): """ Post the data to the given url :param url: url of SOAP endpoint of underlying SOAP server :param data: XML message contents :param headers: incoming request headers :return: response object """ soap_action = headers.get("Soapaction") content_type = headers.get("Content-Type", "") if soap_action is None: raise BadRequest("Missing Soapaction in header") if "text/xml" not in content_type: raise BadRequest(f"Wrong content {content_type}; text/xml expected") headers = {"Soapaction": soap_action, "Content-Type": content_type} return cert_post(url, data=data, headers=headers)