Ejemplo n.º 1
0
 def test01_parse_turtle(self):
     """Parse turtle."""
     r = LDPRS()
     r.parse(b'<http://ex.org/a> <http://ex.org/b> "1".')
     self.assertEqual(len(r.content), 1)
     r = LDPRS()
     r.parse(b'<> <http://ex.org/a> "123".',
             context="http://x.y/a")
     self.assertEqual(len(r.content), 1)
     for (s, p, o) in r.content:
         self.assertEqual(str(s), 'http://x.y/a')
         self.assertEqual(str(p), 'http://ex.org/a')
         self.assertEqual(str(o), '123')
Ejemplo n.º 2
0
 def test04_get_container_type(self):
     """Test extraction of container type."""
     r = LDPRS()
     self.assertEqual(r.get_container_type(context="http://ex.org/aa"),
                      None)
     self.assertEqual(
         r.get_container_type(context="http://ex.org/aa",
                              default=LDP.BasicContainer),
         LDP.BasicContainer)
     r.parse(b'<http://ex.org/aa> <http://ex.org/b> "1".')
     self.assertEqual(r.get_container_type(context="http://ex.org/aa"),
                      None)
     r.parse(
         b'<http://ex.org/aa> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/some_type>.'
     )
     self.assertEqual(r.get_container_type(context="http://ex.org/aa"),
                      None)
     r.parse(
         b'<http://ex.org/aa> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/ldp#DirectContainer>.'
     )
     self.assertEqual(r.get_container_type(context="http://ex.org/aa"),
                      LDP.DirectContainer)
     r.parse(
         b'<http://ex.org/aa> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/ldp#IndirectContainer>.'
     )
     self.assertRaises(Exception,
                       r.get_container_type,
                       context="http://ex.org/aa")
     self.assertEqual(r.get_container_type(context="http://ex.org/NOT_aa"),
                      None)
Ejemplo n.º 3
0
 def test36_triples(self):
     """Test triples()."""
     r = LDPRS()
     g = list(r.triples((None, None, URIRef('info:aaa'))))
     self.assertEqual(len(g), 0)
     r.parse(b'<info:bbb> <info:bbb> <info:aaa>.')
     r.parse(b'<info:ccc> <info:ccc> "info:bbb".')  # not a URI ref!
     g = list(r.triples((None, None, URIRef('info:aaa'))))
     self.assertEqual(len(g), 1)
     self.assertEqual(g[0], (URIRef('info:bbb'), URIRef('info:bbb'), URIRef('info:aaa')))
     g = list(r.triples((None, None, URIRef('info:bbb'))))
     self.assertEqual(len(g), 0)
     r.parse(b'<http://ex.org/a> <http://ex.org/b> <info:bbb>.')
     g = list(r.triples((None, None, URIRef('info:bbb'))))
     self.assertEqual(len(g), 1)
     self.assertEqual(g[0], (URIRef('http://ex.org/a'), URIRef('http://ex.org/b'), URIRef('info:bbb')))
Ejemplo n.º 4
0
 def test03_patch(self):
     """Test PATCH update."""
     r = LDPRS()
     r.parse('''
         @prefix x: <http://example.org/> .
         x:simeon x:has x:pizza .
         ''')
     sparql_update = '''
         PREFIX x: <http://example.org/>
         DELETE { ?s x:has ?o . }
         INSERT { ?s x:ate ?o .
                  ?o x:was_eaten_by ?s . }
         WHERE { ?s x:has ?o . }
         '''
     self.assertEqual(len(r.content), 1)
     r.patch(sparql_update, 'application/sparql-update')
     self.assertEqual(len(r.content), 2)
     self.assertEqual(
         len(
             list(
                 r.content.triples(
                     (None, URIRef('http://example.org/has'), None)))), 0)
     self.assertEqual(
         len(
             list(
                 r.content.triples(
                     (None, URIRef('http://example.org/ate'), None)))), 1)
     self.assertEqual(
         len(
             list(
                 r.content.triples(
                     (None, URIRef('http://example.org/was_eaten_by'),
                      None)))), 1)
     # bad type
     self.assertRaises(PatchFailed, r.patch, sparql_update, 'bad/type')
     # bad update command
     self.assertRaises(PatchFailed, r.patch, 'update syntax error',
                       'application/sparql-update')
Ejemplo n.º 5
0
 def test40_compute_etag(self):
     """Test computation of etag."""
     r = LDPRS()
     self.assertEqual(r._compute_etag(), '"d41d8cd98f00b204e9800998ecf8427e"')
     r.parse(b'<http://ex.org/a> <http://ex.org/b> <http://ex.org/c>.')
     self.assertEqual(r._compute_etag(), '"d06b10aa24d65ebf1fc913ce2e8d23ff"')
     r.parse(b'<http://ex.org/a> <http://ex.org/b> "hello".')
     self.assertEqual(r._compute_etag(), '"5777dd3a4bc5065c7ed42bb86655c83f"')
     r = LDPRS()
     r.parse(b'<http://ex.org/d> <http://ex.org/e> [ <http://ex.org/f> "111"; <http://ex.org/g> "222"].')
     self.assertEqual(r._compute_etag(), '"afe90adc3b4a1778ee5c4bb32083b061"')
     # This graph is different from the previous one because
     # it has two BNodes instead of one, and ETag will differ
     r = LDPRS()
     r.parse(b'<http://ex.org/d> <http://ex.org/e1> [ <http://ex.org/f> "111" ].' +
             b'<http://ex.org/d> <http://ex.org/e2> [ <http://ex.org/g> "222" ].')
     self.assertEqual(r._compute_etag(), '"f1c12772ce8d7e485155601c2c095d2b"')
     # FIXME - This graph is different from the previous one but
     # will end up with the same ETag because BNodes are conflated
     r = LDPRS()
     r.parse(b'<http://ex.org/d> <http://ex.org/e2> [ <http://ex.org/f> "111" ].' +
             b'<http://ex.org/d> <http://ex.org/e1> [ <http://ex.org/g> "222" ].')
     self.assertEqual(r._compute_etag(), '"f1c12772ce8d7e485155601c2c095d2b"')
Ejemplo n.º 6
0
 def test05_parse_json_ld(self):
     """Parse JSON-LD."""
     r = LDPRS()
     r.parse(b'{ "@id": "http://ex.org/a", "http://ex.org/b": "123"}',
             content_type='application/ld+json')
     self.assertEqual(len(r.content), 1)