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']
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,)
def test_library_rdf(self):
import RDF
from htsworkflow.util.rdfhelp import get_model, \
+ dump_model, \
fromTypedNode, \
load_string_into_model, \
rdfNS, \
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#>
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)
+
+ # validate a library page.
+ from htsworkflow.util.rdfhelp import add_default_schemas
+ from htsworkflow.util.rdfinfer import Infer
+ add_default_schemas(model)
+ inference = Infer(model)
+ ignored = {'Missing type for: http://localhost/'}
+ errmsgs = [msg for msg in inference.run_validation()
+ if msg not in ignored ]
+ self.assertEqual(len(errmsgs), 0)
+
+ def test_library_index_rdfa(self):
+ from htsworkflow.util.rdfhelp import \
+ add_default_schemas, get_model, load_string_into_model, \
+ dump_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)
+
+ ignored = {'Missing type for: http://localhost/'}
+ errmsgs = [msg for msg in inference.run_validation()
+ if msg not in ignored ]
+ self.assertEqual(len(errmsgs), 0)
+
+ 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_name
+ where {
+ ?library a libns:Library .
+ OPTIONAL { ?library libns:library_id ?library_id . }
+ OPTIONAL { ?library libns:species_name ?species_name . }
+ OPTIONAL { ?library libns:name ?name . }
+ }"""
+ bindings = set(['library', 'library_id', 'name', 'species_name'])
+ 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.
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_literal_object(model, ['Drosophila melanogaster'], p=libNS['species_name'])
self.check_uri_object(model,
[u'http://localhost/lane/1193'],
storage = RDF.MemoryStorage()
model = RDF.Model(storage)
return model
-