+try:
+ import RDF
+ HAVE_RDF = True
+
+ rdfNS = RDF.NS("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+ xsdNS = RDF.NS("http://www.w3.org/2001/XMLSchema#")
+ libNS = RDF.NS("http://jumpgate.caltech.edu/wiki/LibraryOntology#")
+except ImportError,e:
+ HAVE_RDF = False
+
+
+@unittest.skipIf(not HAVE_RDF,
+ 'Install python librdf to test RDFa encoded in pages')
+class TestRDFaLibrary(TestCase):
+ fixtures = ['test_samples.json']
+
+ def test_parse_rdfa(self):
+ model = get_rdf_memory_model()
+ parser = RDF.Parser(name='rdfa')
+ url = '/library/10981/'
+ lib_response = self.client.get(url)
+ self.failIfEqual(len(lib_response.content), 0)
+
+ parser.parse_string_into_model(model,
+ lib_response.content,
+ 'http://localhost'+url)
+ # http://jumpgate.caltech.edu/wiki/LibraryOntology#affiliation>
+ self.check_literal_object(model, ['Bob'], p=libNS['affiliation'])
+ self.check_literal_object(model, ['Multiplexed'], p=libNS['experiment_type'])
+ self.check_literal_object(model, ['400'], p=libNS['gel_cut'])
+ self.check_literal_object(model, ['Igor'], p=libNS['made_by'])
+ self.check_literal_object(model, ['Paired End Multiplexed Sp-BAC'], p=libNS['name'])
+ self.check_literal_object(model, ['Drosophila melanogaster'], p=libNS['species'])
+
+ self.check_uri_object(model,
+ [u'http://localhost/flowcell/303TUAAXX/1/'],
+ p=libNS['has_lane'])
+
+ self.check_literal_object(model,
+ [u"303TUAAXX"],
+ s=RDF.Uri('http://localhost/flowcell/303TUAAXX/'))
+
+ def check_literal_object(self, model, values, s=None, p=None, o=None):
+ statements = list(model.find_statements(
+ RDF.Statement(s,p,o)))
+ self.failUnlessEqual(len(statements), len(values),
+ "Couln't find %s %s %s" % (s,p,o))
+ for s in statements:
+ self.failUnless(s.object.literal_value['string'] in values)
+
+
+ def check_uri_object(self, model, values, s=None, p=None, o=None):
+ statements = list(model.find_statements(
+ RDF.Statement(s,p,o)))
+ self.failUnlessEqual(len(statements), len(values),
+ "Couln't find %s %s %s" % (s,p,o))
+ for s in statements:
+ self.failUnless(unicode(s.object.uri) in values)
+
+
+
+def get_rdf_memory_model():
+ storage = RDF.MemoryStorage()
+ model = RDF.Model(storage)
+ return model
+