def test_login(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:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <username xsi:type="xsd:string">username</username> <password xsi:type="xsd:string">password</password> </soap:login> </soapenv:Body> </soapenv:Envelope> """ request = soap.login("username", "password") request = minidom.parseString(request).toprettyxml() assert compare_xml(request, expected)
def login(username, password): xml = soap.login(username, password) r = requests.post(USGS_API, xml) if r.status_code is not 200: raise USGSError(r.text) root = ElementTree.fromstring(r.text) _check_for_usgs_error(root) element = root.find("SOAP-ENV:Body/ns1:loginResponse/return", NAMESPACES) api_key = element.text with open(TMPFILE, "w") as f: f.write(api_key) return api_key
def login(username, password, save=True): xml = soap.login(username, password) r = requests.post(USGS_API, xml) if r.status_code is not 200: raise USGSError(r.text) root = ElementTree.fromstring(r.text) _check_for_usgs_error(root) element = root.find("SOAP-ENV:Body/ns1:loginResponse/return", NAMESPACES) api_key = element.text if save: with open(TMPFILE, "w") as f: f.write(api_key) return api_key