Make the public html pages valid xhtml, and validate more RDFa cases.
[htsworkflow.git] / htsworkflow / frontend / samples / tests.py
index 770d90a8e8925c81c3e77465bfb750fecf2527f3..bfe4b0e2c7260c6a5f18893c72c93708f80fde11 100644 (file)
@@ -20,7 +20,7 @@ from htsworkflow.frontend.samples.views import \
 
 from htsworkflow.frontend.auth import apidata
 from htsworkflow.util.conversion import unicode_or_none
-
+from htsworkflow.util.ethelp import validate_xhtml
 
 class LibraryTestCase(TestCase):
     fixtures = ['test_samples.json']
@@ -52,7 +52,6 @@ class SampleWebTestCase(TestCase):
     fixtures = ['test_samples.json']
 
     def test_library_info(self):
-
         for lib in Library.objects.all():
             lib_dict = library_dict(lib.id)
             url = '/samples/library/%s/json' % (lib.id,)
@@ -150,7 +149,8 @@ class SampleWebTestCase(TestCase):
 
         response = self.client.get('/library/10981/')
         self.assertEqual(response.status_code, 200)
-        load_string_into_model(model, 'rdfa', response.content)
+        content = response.content
+        load_string_into_model(model, 'rdfa', content)
 
         body = """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
         prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#>
@@ -171,6 +171,53 @@ class SampleWebTestCase(TestCase):
             self.assertEqual(fromTypedNode(r['gel_cut']), 400)
             self.assertEqual(fromTypedNode(r['made_by']), u'Igor')
 
+        state = validate_xhtml(content)
+        if state is not None: self.assertTrue(state)
+
+    def test_library_index_rdfa(self):
+        from htsworkflow.util.rdfhelp import \
+             add_default_schemas, get_model, load_string_into_model
+
+        from htsworkflow.util.rdfinfer import Infer
+
+        model = get_model()
+        add_default_schemas(model)
+        inference = Infer(model)
+
+        response = self.client.get('/library/')
+        self.assertEqual(response.status_code, 200)
+        load_string_into_model(model, 'rdfa', response.content)
+
+        errmsgs = list(inference.run_validation())
+        self.assertEqual(len(errmsgs), 2)
+        # didn't feel like giving the index page a type since all
+        # its doing is showing a list of things.
+        for err in errmsgs:
+            self.assertEqual(err, 'Missing type for: http://localhost/')
+
+        body =  """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+        prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#>
+
+        select ?library ?library_id ?name ?species
+        where {
+           ?library a libns:Library .
+           OPTIONAL { ?library libns:library_id ?library_id . }
+           OPTIONAL { ?library libns:species ?species . }
+           OPTIONAL { ?library libns:name ?name . }
+        }"""
+        bindings = set(['library', 'library_id', 'name', 'species'])
+        query = RDF.SPARQLQuery(body)
+        count = 0
+        for r in query.execute(model):
+            count += 1
+            for name, value in r.items():
+                self.assertTrue(name in bindings)
+                self.assertTrue(value is not None)
+
+        self.assertEqual(count, len(Library.objects.filter(hidden=False)))
+
+        state = validate_xhtml(response.content)
+        if state is not None: self.assertTrue(state)
 # The django test runner flushes the database between test suites not cases,
 # so to be more compatible with running via nose we flush the database tables
 # of interest before creating our sample data.