def dataset_fields(dataset, node): api_key = _get_api_key() xml = soap.dataset_fields(dataset, node, api_key=api_key) r = requests.post(USGS_API, xml) root = ElementTree.fromstring(r.text) _check_for_usgs_error(root) items = root.findall("SOAP-ENV:Body/ns1:datasetFieldsResponse/return/item", NAMESPACES) data = map(lambda item: {el.tag: xsi.get(el) for el in item}, items) return data
def test_dataset_fields(self): expected = """ <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://earthexplorer.usgs.gov/inventory/soap"> <soapenv:Header/> <soapenv:Body> <soap:datasetFields soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <datasetName xsi:type="xsd:string">LANDSAT_8</datasetName> <node xsi:type="xsd:string">EE</node> <apiKey xsi:type="xsd:string">USERS API KEY</apiKey> </soap:datasetFields> </soapenv:Body> </soapenv:Envelope> """ request = soap.dataset_fields("LANDSAT_8", "EE", api_key="USERS API KEY") request = minidom.parseString(request).toprettyxml() assert compare_xml(request, expected)