Add in test code to verify RDF data being added to the library page.
authorDiane Trout <diane@caltech.edu>
Fri, 27 May 2011 00:56:37 +0000 (17:56 -0700)
committerDiane Trout <diane@caltech.edu>
Fri, 27 May 2011 00:56:37 +0000 (17:56 -0700)
htsworkflow/frontend/samples/fixtures/test_samples.json
htsworkflow/frontend/samples/tests.py
htsworkflow/frontend/templates/samples/library_detail.html

index 4dbf37167fa231ecfdb16ff391c7c59ace5c6293..729f067184863b270ed972b2014b07d2edb515c5 100644 (file)
@@ -1,4 +1,4 @@
-[
+[ 
   {"pk": 5, "model": "auth.user", 
    "fields": {
        "username": "test",
        "date_joined": "2009-01-01 00:01:01"
        }
    },
+   {"pk": 1, "model": "samples.affiliation",
+    "fields": {
+        "users": [5],
+        "name": "Alice",
+        "contact": "Lab Boss",
+        "email": "alice@some.where.else."
+        }
+    },
+    {"pk": 2, "model": "samples.affiliation",
+     "fields": { "name": "Bob",
+                 "contact": "Other Lab Boss",
+                 "email": "bob@some.where.else"
+               }
+    },
  {"pk": 153, "model": "experiments.flowcell", 
   "fields": {
       "paired_end": true, 
@@ -60,7 +74,7 @@
             "library_type": null, 
             "made_by": "Igor", 
             "affiliations": [
-                40
+                2
             ], 
             "replicate": 1, 
             "condition": 1, 
index f4c810c747142ebf44a87d0e5396adb3e4329fe3..18f6e9843872f345e2a25c7263b3f58a36de020b 100644 (file)
@@ -23,6 +23,8 @@ from htsworkflow.util.conversion import unicode_or_none
 
 
 class LibraryTestCase(TestCase):
+    fixtures = ['test_samples.json']
+
     def setUp(self):
         create_db(self)
                
@@ -123,51 +125,11 @@ class SampleWebTestCase(TestCase):
 # so to be more compatible with running via nose we flush the database tables
 # of interest before creating our sample data.
 def create_db(obj):
-    Species.objects.all().delete()
-    obj.species_human = Species(
-        scientific_name = 'Homo Sapeins',
-        common_name = 'human',
-    )
-    obj.species_human.save()
-    obj.species_worm = Species(
-        scientific_name = 'C. Elegans',
-        common_name = 'worm',
-    )
-    obj.species_worm.save()
-    obj.species_phix = Species(
-        scientific_name = 'PhiX',
-        common_name = 'PhiX'
-    )
-    obj.species_phix.save()
-
-    ExperimentType.objects.all().delete()
-    obj.experiment_de_novo = ExperimentType(
-        name = 'De Novo',
-    )
-    obj.experiment_de_novo.save()
-    obj.experiment_chip_seq = ExperimentType(
-        name = 'ChIP-Seq'
-    )
-    obj.experiment_chip_seq.save()
-    obj.experiment_rna_seq = ExperimentType(
-        name = 'RNA-Seq'
-    )
-    obj.experiment_rna_seq.save()
-
-    Affiliation.objects.all().delete()
-    obj.affiliation_alice = Affiliation(
-        name = 'Alice',
-        contact = 'Lab Boss',
-        email = 'alice@some.where.else.'
-    )
-    obj.affiliation_alice.save()
-    obj.affiliation_bob = Affiliation(
-        name = 'Bob',
-        contact = 'Other Lab Boss',
-        email = 'bob@some.where.else',
-    )
-    obj.affiliation_bob.save()
-
+    obj.species_human = Species.objects.get(pk=8)
+    obj.experiment_rna_seq = ExperimentType.objects.get(pk=4)
+    obj.affiliation_alice = Affiliation.objects.get(pk=1)
+    obj.affiliation_bob = Affiliation.objects.get(pk=2)
+    
     Library.objects.all().delete()
     obj.library_10001 = Library(
         id = "10001",
@@ -196,3 +158,69 @@ def create_db(obj):
     )
     obj.library_10002.save()
  
+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
+
index 2c2d90bf793acfb87e34d4be28997444e86705f6..f5c4176855cd071950e2819add3e4f5a3d6693e6 100644 (file)
@@ -80,7 +80,7 @@
     <b>Affiliations</b>:
     <ul>
       {% for individual in lib.affiliations.all %}
-        <li property="libns:affliation" content="{{individual.name}}">
+        <li property="libns:affiliation" content="{{individual.name}}">
           {{ individual.name }} ( {{ individual.contact }} )
         </li>
       {% endfor %}