def test_download(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:download 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> <entityIds xsi:type="soap:ArrayOfString"> <item xsi:type="xsd:string">LC80130292014100LGN00</item> </entityIds> <products xsi:type="soap:ArrayOfString"> <item xsi:type="xsd:string">STANDARD</item> </products> </soap:download> </soapenv:Body> </soapenv:Envelope> """ request = soap.download("LANDSAT_8", "EE", ["LC80130292014100LGN00"], ["STANDARD"], api_key="USERS API KEY") request = minidom.parseString(request).toprettyxml() assert compare_xml(request, expected)
def test_datasets(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:datasets soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <node xsi:type="xsd:string">EE</node> <datasetName xsi:type="xsd:string">L8</datasetName> <apiKey xsi:type="xsd:string">USERS API KEY</apiKey> <lowerLeft xsi:type="soap:Service_Class_Coordinate"> <latitude xsi:type="xsd:double">44.60847</latitude> <longitude xsi:type="xsd:double">-99.69639</longitude> </lowerLeft> <upperRight xsi:type="soap:Service_Class_Coordinate"> <latitude xsi:type="xsd:double">44.60847</latitude> <longitude xsi:type="xsd:double">-99.69639</longitude> </upperRight> <startDate xsi:type="xsd:string">2014-10-01T00:00:00Z</startDate> <endDate xsi:type="xsd:string">2014-10-01T23:59:59Z</endDate> </soap:datasets> </soapenv:Body> </soapenv:Envelope> """ ll = { "longitude": -99.69639, "latitude": 44.60847 } ur = { "longitude": -99.69639, "latitude": 44.60847 } start_date = "2014-10-01T00:00:00Z" end_date = "2014-10-01T23:59:59Z" request = soap.datasets("L8", "EE", ll=ll, ur=ur, start_date=start_date, end_date=end_date, api_key="USERS API KEY") request = minidom.parseString(request).toprettyxml() assert compare_xml(request, expected)
def assertXMLNotEqual(self, xml1, xml2, msg=None): """ Asserts that two XML snippets are not semantically equivalent. Whitespace in most cases is ignored, and attribute ordering is not significant. The passed-in arguments must be valid XML. """ try: result = compare_xml(xml1, xml2) except Exception as e: standardMsg = 'First or second argument is not valid XML\n%s' % e self.fail(self._formatMessage(msg, standardMsg)) else: if result: standardMsg = '%s == %s' % (safe_repr(xml1, True), safe_repr(xml2, True)) self.fail(self._formatMessage(msg, standardMsg))
def test_logout(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:logout soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <apiKey xsi:type="xsd:string">USERS API KEY</apiKey> </soap:logout> </soapenv:Body> </soapenv:Envelope> """ request = soap.logout(api_key="USERS API KEY") request = minidom.parseString(request).toprettyxml() assert compare_xml(request, expected)
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 create(cls, version, hashedID, request=None): filename = os.path.join(settings.MANIFEST_DIR, version, 'manifest.xml') if hashedID != None: device = Device.create(hashedID) else: device = None template = Template(open(filename, 'rb').read()) if hashedID != None: ctx = Manifest.make_context(device=device, request=None) else: ctx = Manifest.make_context(device=None, request=request) xml = template.render(ctx) root = etree.fromstring(StringIO.StringIO( xml.decode('utf-8')).getvalue().encode('utf-8'), parser=etree.XMLParser(encoding='utf-8')) if device == None: return_string = StringIO.StringIO() etree.ElementTree(root).write_c14n(return_string) return return_string.getvalue() if device.last_manifest and device.last_manifest.exists and compare_xml( root, device.last_manifest.root): return device.last_manifest else: manifest = Manifest(device=Device.create(hashedID), version=version, retrieved_time=now()) if os.path.exists(manifest.filename): raise BackendValidationError("manifest file already exists") else: write_canonical_xml(root, manifest.filename) try: manifest.full_clean() except: do_remove_linked_file(manifest.filename, manifest.basedir()) raise return manifest
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)
def create(cls, version, hashedID, request=None): filename = os.path.join(settings.MANIFEST_DIR, version, 'manifest.xml') if hashedID != None: device = Device.create(hashedID) else: device = None template = Template(open(filename, 'rb').read()) if hashedID != None: ctx = Manifest.make_context(device=device, request=None) else: ctx = Manifest.make_context(device=None, request=request) xml = template.render(ctx) root = etree.fromstring(StringIO.StringIO(xml.decode('utf-8')).getvalue().encode('utf-8'), parser=etree.XMLParser(encoding='utf-8')) if device == None: return_string = StringIO.StringIO() etree.ElementTree(root).write_c14n(return_string) return return_string.getvalue() if device.last_manifest and device.last_manifest.exists and compare_xml(root, device.last_manifest.root): return device.last_manifest else: manifest = Manifest(device=Device.create(hashedID), version=version, retrieved_time=now()) if os.path.exists(manifest.filename): raise BackendValidationError("manifest file already exists") else: write_canonical_xml(root, manifest.filename) try: manifest.full_clean() except: do_remove_linked_file(manifest.filename, manifest.basedir()) raise return manifest
def test_search(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:search soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <datasetName xsi:type="xsd:string">GLS2005</datasetName> <node xsi:type="xsd:string">EE</node> <lowerLeft xsi:type="soap:Service_Class_Coordinate"> <latitude xsi:type="xsd:double">75</latitude> <longitude xsi:type="xsd:double">-135</longitude> </lowerLeft> <upperRight xsi:type="soap:Service_Class_Coordinate"> <latitude xsi:type="xsd:double">90</latitude> <longitude xsi:type="xsd:double">-120</longitude> </upperRight> <startDate xsi:type="xsd:string">2006-01-01T00:00:00Z</startDate> <endDate xsi:type="xsd:string">2007-12-01T00:00:00Z</endDate> <maxResults xsi:type="xsd:int">3</maxResults> <startingNumber xsi:type="xsd:int">1</startingNumber> <sortOrder xsi:type="xsd:string">ASC</sortOrder> <apiKey xsi:type="xsd:string">USERS API KEY</apiKey> </soap:search> </soapenv:Body> </soapenv:Envelope> """ ll = { "longitude": -135, "latitude": 75 } ur = { "longitude": -120, "latitude": 90 } start_date = "2006-01-01T00:00:00Z" end_date = "2007-12-01T00:00:00Z" request = soap.search("GLS2005", "EE", ll=ll, ur=ur, start_date=start_date, end_date=end_date, max_results=3, sort_order="ASC", api_key="USERS API KEY") request = minidom.parseString(request).toprettyxml() assert compare_xml(request, expected)
def check_output_xml(self, want, got, optionsflags): try: return compare_xml(want, got) except Exception: return False
def assertXMLEqual(self, expected, actual): if not compare_xml(actual, expected): self.assertMultiLineEqual(self.norm_whitespace(expected), self.norm_whitespace(actual))