def call_soap_method_xml(self, xml, headers=DEFAULT_HEADERS): """ Send an XML file as a request to the SOAP client. The path to the Request XML file is required as argument, the SOAP method is inside the XML file. *Input Arguments:* | *Name* | *Description* | | xml | file path to xml file | | headers | dictionary with request headers. Default ``{'Content-Type': 'text/xml; charset=utf-8'}`` | *Example:* | ${response}= | Call SOAP Method With XML | C:\\Request.xml | """ # TODO check with different headers: 'SOAPAction': self.url + '/%s' % method} raw_text_xml = self._convert_xml_to_raw_text(xml) xml_obj = etree.fromstring(raw_text_xml) response = self.client.transport.post_xml(address=self.url, envelope=xml_obj, headers=headers) etree_response = self._parse_from_unicode(response.text) if response.status_code != 200: logger.debug('URL: %s' % response.url) logger.debug( etree.tostring(etree_response, pretty_print=True, encoding='unicode')) raise AssertionError('Request Error! Status Code: %s! Reason: %s' % (response.status_code, response.reason)) return etree_response
def call_soap_method_string_xml(self, string_xml, headers=DEFAULT_HEADERS): """ Send an string representation of XML as a request to the SOAP client. The SOAP method is inside the XML string. *Input Arguments:* | *Name* | *Description* | | string_xml | string representation of XML | | headers | dictionary with request headers. Default ``{'Content-Type': 'text/xml; charset=utf-8'}`` | *Example:* | ${response}= | Call SOAP Method With String XML | "<sample><Id>1</Id></sample>" | """ # TODO check with different headers: 'SOAPAction': self.url + '/%s' % method} xml_obj = etree.fromstring(string_xml) response = self.client.transport.post_xml(address=self.url, envelope=xml_obj, headers=headers) etree_response = self._parse_from_unicode(response.text) if response.status_code != 200: logger.debug('URL: %s' % response.url) logger.debug( etree.tostring(etree_response, pretty_print=True, encoding='unicode')) raise AssertionError('Request Error! Status Code: %s! Reason: %s' % (response.status_code, response.reason)) self._print_request_info(etree_response) return etree_response
def _convert_string_to_xml(xml_string): """ Converts a given string to xml object using etree. :param xml_string: string with xml content :return: xml object """ return etree.fromstring(xml_string)
def _parse_from_unicode(unicode_str): """ Parses a unicode string. :param unicode_str: unicode string :return: parsed string """ utf8_parser = etree.XMLParser(encoding='utf-8') string_utf8 = unicode_str.encode('utf-8') return etree.fromstring(string_utf8, parser=utf8_parser)