コード例 #1
0
 def testGatherMetadataWmsInvalidXml(self):
     self.maxDiff = None
     # An WMS response with invalid XML.
     self.assertTrue(
         metadata_fetch.GatherMetadata(
             'WMS',
             utils.Struct(status_code=200,
                          headers=RESPONSE_HEADERS,
                          content=INVALID_XML_WMS_RESPONSE))['ill_formed'])
コード例 #2
0
 def testGatherMetadataWmsInvalid(self):
     self.maxDiff = None
     # An invalid WMS response that is valid XML.
     self.assertEquals({},
                       metadata_fetch.GatherMetadata(
                           'WMS',
                           utils.Struct(
                               status_code=200,
                               headers=RESPONSE_HEADERS,
                               content=INVALID_WMS_RESPONSE))['wms_layers'])
コード例 #3
0
    def testGatherMetadataWmsValid(self):
        self.maxDiff = None
        # A valid WMS GetCapabilities response.
        self.assertEquals(
            METADATA_VALID_WMS_RESPONSE,
            metadata_fetch.GatherMetadata(
                'WMS',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=VALID_WMS_RESPONSE))['wms_layers'])

        # A response with a valid layer and several invalid Layers.
        self.assertEquals(
            METADATA_INVALID_LAYERS_WMS_RESPONSE,
            metadata_fetch.GatherMetadata(
                'WMS',
                utils.Struct(
                    status_code=200,
                    headers=RESPONSE_HEADERS,
                    content=INVALID_LAYERS_WMS_RESPONSE))['wms_layers'])
コード例 #4
0
    def testGatherMetadataKmz(self):
        # KMZ containing valid KML.
        kmz = CreateZip([('doc.kml', SIMPLE_KML)])
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(kmz),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'update_time': LAST_MODIFIED_TIMESTAMP,
                'length': len(kmz),
                'md5_hash': hashlib.md5(kmz).hexdigest()
            },
            metadata_fetch.GatherMetadata(
                'KML',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=kmz)))

        # KMZ containing valid KML with unsupported features.
        content = '<kml><Document><Placemark><Camera/></Placemark></Document></kml>'
        kmz = CreateZip([('doc.kml', content)])
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(kmz),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'update_time': LAST_MODIFIED_TIMESTAMP,
                'length': len(kmz),
                'md5_hash': hashlib.md5(kmz).hexdigest(),
                'has_unsupported_kml': True
            },
            metadata_fetch.GatherMetadata(
                'KML',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=kmz)))
コード例 #5
0
    def testGatherMetadataGeorss(self):
        # Valid GeoRSS.
        content = '<rss><channel><item></item></channel></rss>'
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(content),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'update_time': LAST_MODIFIED_TIMESTAMP,
                'length': len(content),
                'md5_hash': hashlib.md5(content).hexdigest()
            },
            metadata_fetch.GatherMetadata(
                'GEORSS',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=content)))

        # Valid GeoRSS with no features.
        content = '<rss><channel></channel></rss>'
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(content),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'update_time': LAST_MODIFIED_TIMESTAMP,
                'length': len(content),
                'md5_hash': hashlib.md5(content).hexdigest(),
                'has_no_features': True
            },
            metadata_fetch.GatherMetadata(
                'GEORSS',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=content)))
コード例 #6
0
 def testGatherMetadataInvalid(self):
     # Invalid XML syntax.
     content = '<blah'
     self.assertEquals(
         {
             'fetch_status': 200,
             'fetch_length': len(content),
             'fetch_last_modified': LAST_MODIFIED_STRING,
             'fetch_etag': ETAG,
             'update_time': LAST_MODIFIED_TIMESTAMP,
             'length': len(content),
             'md5_hash': hashlib.md5(content).hexdigest(),
             'ill_formed': True
         },
         metadata_fetch.GatherMetadata(
             'KML',
             utils.Struct(status_code=200,
                          headers=RESPONSE_HEADERS,
                          content=content)))
コード例 #7
0
    def testGatherMetadataKml(self):
        # Valid KML.
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(SIMPLE_KML),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'update_time': LAST_MODIFIED_TIMESTAMP,
                'length': len(SIMPLE_KML),
                'md5_hash': hashlib.md5(SIMPLE_KML).hexdigest()
            },
            metadata_fetch.GatherMetadata(
                'KML',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=SIMPLE_KML)))

        # Valid KML with no features.
        content = '<kml><Document></Document></kml>'
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(content),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'update_time': LAST_MODIFIED_TIMESTAMP,
                'length': len(content),
                'md5_hash': hashlib.md5(content).hexdigest(),
                'has_no_features': True
            },
            metadata_fetch.GatherMetadata(
                'KML',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=content)))

        # Valid KML with unsupported features.
        content = '<kml><Document><Placemark><Camera/></Placemark></Document></kml>'
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(content),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'update_time': LAST_MODIFIED_TIMESTAMP,
                'length': len(content),
                'md5_hash': hashlib.md5(content).hexdigest(),
                'has_unsupported_kml': True
            },
            metadata_fetch.GatherMetadata(
                'KML',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=content)))

        # Valid KML with a NetworkLink, but no ETag or Last-modified header.
        content = '<kml><Document><NetworkLink/></Document></kml>'
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(content),
                'length': len(content),
                'md5_hash': hashlib.md5(content).hexdigest()
            },
            metadata_fetch.GatherMetadata(
                'KML',
                utils.Struct(status_code=200, headers={}, content=content)))

        # Valid KML with a NetworkLink, which invalidates the update time.
        content = '<kml><Document><NetworkLink/></Document></kml>'
        self.assertEquals(
            {
                'fetch_status': 200,
                'fetch_length': len(content),
                'fetch_last_modified': LAST_MODIFIED_STRING,
                'fetch_etag': ETAG,
                'length': len(content),
                'md5_hash': hashlib.md5(content).hexdigest()
            },
            metadata_fetch.GatherMetadata(
                'KML',
                utils.Struct(status_code=200,
                             headers=RESPONSE_HEADERS,
                             content=content)))