Ejemplo n.º 1
0
 def test_positive_context(self):
     A = {
         "@context": [ "http://www.w3.org/ns/csvw", { "@language": "en" } ],
         "tables": [{
             "url": "http://example.org/countries.csv",
             "tableSchema": {
                 "columns": [{
                     "name": "countryCode",
                     "datatype": "string",
                     "propertyUrl": "http://www.geonames.org/ontology{#_name}"
                 }, {
                     "name": "latitude",
                     "datatype": "number"
                 }, {
                     "name": "longitude",
                     "datatype": "number"
                 }, {
                     "name": "name",
                     "datatype": "string"
                 }],
                 "aboutUrl": "http://example.org/countries.csv{#countryCode}",
                 "propertyUrl": "http://schema.org/{_name}",
                 "primaryKey": "countryCode"
             }
         }]
     }
     result = metadata.validate(A)
     self.assertTrue(isinstance(result, Model))
     # context is string only
     A = {
         "@context": "http://www.w3.org/ns/csvw",
         "tables": [{
             "url": "http://example.org/countries.csv",
             "tableSchema": {
                 "columns": [{
                     "name": "countryCode",
                     "datatype": "string",
                     "propertyUrl": "http://www.geonames.org/ontology{#_name}"
                 }, {
                     "name": "latitude",
                     "datatype": "number"
                 }, {
                     "name": "longitude",
                     "datatype": "number"
                 }, {
                     "name": "name",
                     "datatype": "string"
                 }],
                 "aboutUrl": "http://example.org/countries.csv{#countryCode}",
                 "propertyUrl": "http://schema.org/{_name}",
                 "primaryKey": "countryCode"
             }
         }]
     }
     result = metadata.validate(A)
     self.assertTrue(isinstance(result, Model))
Ejemplo n.º 2
0
 def test_normalize2(self):
     self.maxDiff = None
     A = {
           "@context": [ "http://www.w3.org/ns/csvw", { "@base": "http://example.com/" } ],
           "@type": "Table",
           "url": "table.csv",
           "schema:url": {"@id": "table.csv"}
     }
     norm = {
           "@context": "http://www.w3.org/ns/csvw",
           "tables": [
               {
                   "@type": "Table",
                   "url": "http://example.com/table.csv",
                   "schema:url": {"@id": "http://example.com/table.csv"}
               }
           ]
     }
     val = metadata.validate(A)
     #print val.json()
     #self.assertEqual(val.json(), A)
     val.normalize()
     json_res = val.json()
     print json_res
     self.assertEqual(json_res, norm)
Ejemplo n.º 3
0
 def test_normalize(self):
     self.maxDiff = None
     A = {
       "@context": [ "http://www.w3.org/ns/csvw", { "@language": "en" } ],
       "@type": "Table",
       "url": "http://example.com/table.csv",
       "dc:title": [
         "The title of this Table",
         {"@value": "Der Titel dieser Tabelle", "@language": "de"}
       ]
     }
     norm = {
       "@context": "http://www.w3.org/ns/csvw",
       "tables": [
           {
               "@type": "Table",
               "url": "http://example.com/table.csv",
               "dc:title": [
                 {"@value": "The title of this Table", "@language": "en"},
                 {"@value": "Der Titel dieser Tabelle", "@language": "de"}
               ]
           }
       ],
     }
     val = metadata.validate(A)
     #print val.json()
     #self.assertEqual(val.json(), A)
     val.normalize()
     json_res = val.json()
     print json_res
     self.assertEqual(json_res, norm)
Ejemplo n.º 4
0
 def test_negative_validate(self):
     # url is missing
     A = {
         "@context": [ "http://www.w3.org/ns/csvw", { "@language": "en" } ],
         "tables": [{
             # "url": "http://example.org/countries.csv",
             "tableSchema": {
                 "columns": [{
                     "name": "countryCode",
                     "datatype": "string",
                     "propertyUrl": "http://www.geonames.org/ontology{#_name}"
                 }, {
                     "name": "latitude",
                     "datatype": "number"
                 }, {
                     "name": "longitude",
                     "datatype": "number"
                 }, {
                     "name": "name",
                     "datatype": "string"
                 }],
                 "aboutUrl": "http://example.org/countries.csv{#countryCode}",
                 "propertyUrl": "http://schema.org/{_name}",
                 "primaryKey": "countryCode"
             }
         }]
     }
     result = metadata.validate(A)
     self.assertFalse(result)
Ejemplo n.º 5
0
 def test_normalize2(self):
     self.maxDiff = None
     A = {
         "@context":
         ["http://www.w3.org/ns/csvw", {
             "@base": "http://example.com/"
         }],
         "@type":
         "Table",
         "url":
         "table.csv",
         "schema:url": {
             "@id": "table.csv"
         }
     }
     norm = {
         "@context":
         "http://www.w3.org/ns/csvw",
         "tables": [{
             "@type": "Table",
             "url": "http://example.com/table.csv",
             "schema:url": {
                 "@id": "http://example.com/table.csv"
             }
         }]
     }
     val = metadata.validate(A)
     #print val.json()
     #self.assertEqual(val.json(), A)
     val.normalize()
     json_res = val.json()
     print json_res
     self.assertEqual(json_res, norm)
Ejemplo n.º 6
0
 def test_positive_validate(self):
     self.maxDiff = None
     A = {
         "@context": "http://www.w3.org/ns/csvw",
         "tables": [{
             "url": "http://example.org/countries.csv",
             "tableSchema": {
               "columns": [{
                 "name": "countryCode",
                 "datatype": "string",
                 "propertyUrl": "http://www.geonames.org/ontology{#_name}"
               }, {
                 "name": "latitude",
                 "datatype": "number"
               }, {
                 "name": "longitude",
                 "datatype": "number"
               }, {
                 "name": "name",
                 "datatype": "string"
               }],
               "aboutUrl": "http://example.org/countries.csv{#countryCode}",
               "propertyUrl": "http://schema.org/{_name}",
               "primaryKey": "countryCode"
             }
             }, {
             "url": "http://example.org/country_slice.csv",
             "tableSchema": {
               "columns": [{
                 "name": "countryRef",
                 "valueUrl": "http://example.org/countries.csv{#countryRef}"
               }, {
                 "name": "year",
                 "datatype": "gYear"
               }, {
                 "name": "population",
                 "datatype": "integer"
               }],
               "foreignKeys": [{
                 "columnReference": "countryRef",
                 "reference": {
                   "resource": "http://example.org/countries.csv",
                   "columnReference": "countryCode"
                 }
               }]
             }
         }]
     }
     result = metadata.validate(A)
     self.assertTrue(isinstance(result, Model))
     json_res = result.json()
     print json_res
     self.assertEqual(json_res, A)
Ejemplo n.º 7
0
 def test_normalize(self):
     self.maxDiff = None
     A = {
         "@context": ["http://www.w3.org/ns/csvw", {
             "@language": "en"
         }],
         "@type":
         "Table",
         "url":
         "http://example.com/table.csv",
         "dc:title": [
             "The title of this Table", {
                 "@value": "Der Titel dieser Tabelle",
                 "@language": "de"
             }
         ]
     }
     norm = {
         "@context":
         "http://www.w3.org/ns/csvw",
         "tables": [{
             "@type":
             "Table",
             "url":
             "http://example.com/table.csv",
             "dc:title": [{
                 "@value": "The title of this Table",
                 "@language": "en"
             }, {
                 "@value": "Der Titel dieser Tabelle",
                 "@language": "de"
             }]
         }],
     }
     val = metadata.validate(A)
     #print val.json()
     #self.assertEqual(val.json(), A)
     val.normalize()
     json_res = val.json()
     print json_res
     self.assertEqual(json_res, norm)
Ejemplo n.º 8
0
 def test_negative_validate(self):
     # url is missing
     A = {
         "@context": ["http://www.w3.org/ns/csvw", {
             "@language": "en"
         }],
         "tables": [{
             # "url": "http://example.org/countries.csv",
             "tableSchema": {
                 "columns": [{
                     "name":
                     "countryCode",
                     "datatype":
                     "string",
                     "propertyUrl":
                     "http://www.geonames.org/ontology{#_name}"
                 }, {
                     "name": "latitude",
                     "datatype": "number"
                 }, {
                     "name": "longitude",
                     "datatype": "number"
                 }, {
                     "name": "name",
                     "datatype": "string"
                 }],
                 "aboutUrl":
                 "http://example.org/countries.csv{#countryCode}",
                 "propertyUrl":
                 "http://schema.org/{_name}",
                 "primaryKey":
                 "countryCode"
             }
         }]
     }
     result = metadata.validate(A)
     self.assertFalse(result)
Ejemplo n.º 9
0
 def test_positive_context(self):
     A = {
         "@context": ["http://www.w3.org/ns/csvw", {
             "@language": "en"
         }],
         "tables": [{
             "url": "http://example.org/countries.csv",
             "tableSchema": {
                 "columns": [{
                     "name":
                     "countryCode",
                     "datatype":
                     "string",
                     "propertyUrl":
                     "http://www.geonames.org/ontology{#_name}"
                 }, {
                     "name": "latitude",
                     "datatype": "number"
                 }, {
                     "name": "longitude",
                     "datatype": "number"
                 }, {
                     "name": "name",
                     "datatype": "string"
                 }],
                 "aboutUrl":
                 "http://example.org/countries.csv{#countryCode}",
                 "propertyUrl":
                 "http://schema.org/{_name}",
                 "primaryKey":
                 "countryCode"
             }
         }]
     }
     result = metadata.validate(A)
     self.assertTrue(isinstance(result, Model))
     # context is string only
     A = {
         "@context":
         "http://www.w3.org/ns/csvw",
         "tables": [{
             "url": "http://example.org/countries.csv",
             "tableSchema": {
                 "columns": [{
                     "name":
                     "countryCode",
                     "datatype":
                     "string",
                     "propertyUrl":
                     "http://www.geonames.org/ontology{#_name}"
                 }, {
                     "name": "latitude",
                     "datatype": "number"
                 }, {
                     "name": "longitude",
                     "datatype": "number"
                 }, {
                     "name": "name",
                     "datatype": "string"
                 }],
                 "aboutUrl":
                 "http://example.org/countries.csv{#countryCode}",
                 "propertyUrl":
                 "http://schema.org/{_name}",
                 "primaryKey":
                 "countryCode"
             }
         }]
     }
     result = metadata.validate(A)
     self.assertTrue(isinstance(result, Model))
Ejemplo n.º 10
0
 def test_positive_validate(self):
     self.maxDiff = None
     A = {
         "@context":
         "http://www.w3.org/ns/csvw",
         "tables": [{
             "url": "http://example.org/countries.csv",
             "tableSchema": {
                 "columns": [{
                     "name":
                     "countryCode",
                     "datatype":
                     "string",
                     "propertyUrl":
                     "http://www.geonames.org/ontology{#_name}"
                 }, {
                     "name": "latitude",
                     "datatype": "number"
                 }, {
                     "name": "longitude",
                     "datatype": "number"
                 }, {
                     "name": "name",
                     "datatype": "string"
                 }],
                 "aboutUrl":
                 "http://example.org/countries.csv{#countryCode}",
                 "propertyUrl":
                 "http://schema.org/{_name}",
                 "primaryKey":
                 "countryCode"
             }
         }, {
             "url": "http://example.org/country_slice.csv",
             "tableSchema": {
                 "columns": [{
                     "name":
                     "countryRef",
                     "valueUrl":
                     "http://example.org/countries.csv{#countryRef}"
                 }, {
                     "name": "year",
                     "datatype": "gYear"
                 }, {
                     "name": "population",
                     "datatype": "integer"
                 }],
                 "foreignKeys": [{
                     "columnReference": "countryRef",
                     "reference": {
                         "resource": "http://example.org/countries.csv",
                         "columnReference": "countryCode"
                     }
                 }]
             }
         }]
     }
     result = metadata.validate(A)
     self.assertTrue(isinstance(result, Model))
     json_res = result.json()
     print json_res
     self.assertEqual(json_res, A)