X-Git-Url: http://woldlab.caltech.edu/gitweb/?a=blobdiff_plain;f=htsworkflow%2Ffrontend%2Fsamples%2Ftest_samples.py;h=594f2813e6519988b42abccf0c070a81c99c16f8;hb=6b0392dd1788ee645fe4a467fce28d8640d2c8f2;hp=4e0c2a3cb87736033c117c650167a6254d5558be;hpb=c37ae6c2feec007d63757e161dcd8495f8e8bd67;p=htsworkflow.git diff --git a/htsworkflow/frontend/samples/test_samples.py b/htsworkflow/frontend/samples/test_samples.py index 4e0c2a3..594f281 100644 --- a/htsworkflow/frontend/samples/test_samples.py +++ b/htsworkflow/frontend/samples/test_samples.py @@ -1,5 +1,4 @@ import datetime -import unittest try: import json @@ -7,6 +6,10 @@ except ImportError, e: import simplejson as json from django.test import TestCase +from django.test.utils import setup_test_environment, \ + teardown_test_environment +from django.db import connection +from django.conf import settings from htsworkflow.frontend.samples.models import \ Affiliation, \ @@ -181,9 +184,7 @@ class SampleWebTestCase(TestCase): 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 ] + errmsgs = list(inference.run_validation()) self.assertEqual(len(errmsgs), 0) def test_library_index_rdfa(self): @@ -200,22 +201,21 @@ class SampleWebTestCase(TestCase): 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 ] + errmsgs = list(inference.run_validation()) self.assertEqual(len(errmsgs), 0) body = """prefix rdf: prefix libns: - select ?library ?library_id ?name ?species_name + select ?library ?library_id ?name ?species ?species_name where { ?library a libns:Library . OPTIONAL { ?library libns:library_id ?library_id . } - OPTIONAL { ?library libns:species_name ?species_name . } + OPTIONAL { ?library libns:species ?species . + ?species libns:species_name ?species_name . } OPTIONAL { ?library libns:name ?name . } }""" - bindings = set(['library', 'library_id', 'name', 'species_name']) + bindings = set(['library', 'library_id', 'name', 'species', 'species_name']) query = RDF.SPARQLQuery(body) count = 0 for r in query.execute(model): @@ -229,7 +229,7 @@ class SampleWebTestCase(TestCase): 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. @@ -331,3 +331,15 @@ def get_rdf_memory_model(): storage = RDF.MemoryStorage() model = RDF.Model(storage) return model + +def suite(): + from unittest2 import TestSuite, defaultTestLoader + suite = TestSuite() + suite.addTests(defaultTestLoader.loadTestsFromTestCase(LibraryTestCase)) + suite.addTests(defaultTestLoader.loadTestsFromTestCase(SampleWebTestCase)) + suite.addTests(defaultTestLoader.loadTestsFromTestCase(TestRDFaLibrary)) + return suite + +if __name__ == "__main__": + from unittest2 import main + main(defaultTest="suite")