示例#1
0
    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)
示例#2
0
文件: api.py 项目: apatriz/usgs
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
示例#3
0
 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)
示例#4
0
文件: api.py 项目: danlopez00/usgs
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