Esempio 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))
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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))
Esempio 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)