Don't throw an error if library.cell_line is None.
authorDiane Trout <diane@caltech.edu>
Thu, 21 Jan 2010 22:25:09 +0000 (22:25 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 21 Jan 2010 22:25:09 +0000 (22:25 +0000)
The API was having problems where if the cell_line wasn't set it was
trying to do None.cellline_name, which didn't work so well.

In addition there were a few other type conversion issues, such as
unicode(None) != None.

So I added unicode_or_none

htsworkflow/frontend/experiments/tests.py
htsworkflow/frontend/samples/fixtures/test_samples.json
htsworkflow/frontend/samples/tests.py
htsworkflow/frontend/samples/views.py
htsworkflow/util/conversion.py [new file with mode: 0644]

index a27023c3686fe3a75e63794ba9d94d3b620e4c8b..6a3278ac9037a57acf7ebc95c9fc7e6c70eb412e 100644 (file)
@@ -42,7 +42,7 @@ class ExperimentsTestCases(TestCase):
                 self.failUnlessEqual(lane_dict['lane_number'], lane.lane_number)
                 self.failUnlessEqual(lane_dict['library_name'], lane.library.library_name)
                 self.failUnlessEqual(lane_dict['library_id'], lane.library.id)
-                self.failUnlessAlmostEqual(lane_dict['pM'], float(lane.pM))
+                self.failUnlessAlmostEqual(float(lane_dict['pM']), float(lane.pM))
                 self.failUnlessEqual(lane_dict['library_species'],
                                      lane.library.library_species.scientific_name)
                     
@@ -64,7 +64,7 @@ class ExperimentsTestCases(TestCase):
                 self.failUnlessEqual(lane_dict['lane_number'], lane.lane_number)
                 self.failUnlessEqual(lane_dict['library_name'], lane.library.library_name)
                 self.failUnlessEqual(lane_dict['library_id'], lane.library.id)
-                self.failUnlessAlmostEqual(lane_dict['pM'], float(lane.pM))
+                self.failUnlessAlmostEqual(float(lane_dict['pM']), float(lane.pM))
                 self.failUnlessEqual(lane_dict['library_species'],
                                      lane.library.library_species.scientific_name)
 
index edb76e1d5fb89e62a958ce4e428845b21c259509..9a549c5a02dc5d247bde3947706562fcae4b18f6 100644 (file)
             "experiment_type": 8, 
             "antibody": null
         }
+    },
+    {
+        "pk": "11005", 
+        "model": "samples.library", 
+        "fields": {
+            "ten_nM_dilution": false, 
+            "avg_lib_size": 325, 
+            "library_name": "null cell line", 
+            "creation_date": "2009-08-05", 
+            "cell_line": null, 
+            "library_species": 8, 
+            "library_type": 2, 
+            "made_by": "Lorian", 
+            "affiliations": [
+                41
+            ], 
+            "replicate": 1, 
+            "condition": 1, 
+            "hidden": true, 
+            "stopping_point": "1A", 
+            "tags": [], 
+            "made_for": "", 
+            "amplified_from_sample": null, 
+            "notes": "7/31/2009 16:08:22\tColor: Blue", 
+            "undiluted_concentration": null, 
+            "successful_pM": null, 
+            "experiment_type": 8, 
+            "antibody": null
+        }
     }
 ]
index f8eaf0ff0fe11e016df65f0d47586d880fab5979..5f6b7a4638800514ed5d6f46433908ff8736c041 100644 (file)
@@ -19,6 +19,7 @@ from htsworkflow.frontend.samples.views import \
      library_json
 
 from htsworkflow.frontend.auth import apidata
+from htsworkflow.util.conversion import unicode_or_none
 
 # 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
@@ -139,8 +140,8 @@ class SampleWebTestCase(TestCase):
                 #self.failUnlessEqual(d['amplified_from_sample'], lib.amplified_from_sample)
                 self.failUnlessEqual(d['antibody_id'], lib.antibody_id)
                 self.failUnlessEqual(d['avg_lib_size'], lib.avg_lib_size)
-                self.failUnlessEqual(d['cell_line'], lib.cell_line.cellline_name)
                 self.failUnlessEqual(d['cell_line_id'], lib.cell_line_id)
+                self.failUnlessEqual(d['cell_line'], unicode_or_none(lib.cell_line))
                 self.failUnlessEqual(d['experiment_type'], lib.experiment_type.name)
                 self.failUnlessEqual(d['experiment_type_id'], lib.experiment_type_id)
                 self.failUnlessEqual(d['id'], lib.id)
index 9456712da11f3c1998b0591a0bca87e8bec90bf3..dd474a6506b844da3eaaa7d89807769c2975d3e9 100644 (file)
@@ -19,9 +19,11 @@ from htsworkflow.pipelines.runfolder import load_pipeline_run_xml
 from htsworkflow.pipelines import runfolder
 from htsworkflow.pipelines.eland import ResultLane
 from htsworkflow.frontend import settings
+from htsworkflow.util.conversion import unicode_or_none
 from htsworkflow.util import makebed
 from htsworkflow.util import opener
 
+
 from django.core.exceptions import ObjectDoesNotExist
 from django.http import HttpResponse, HttpResponseRedirect, Http404
 from django.shortcuts import render_to_response
@@ -472,8 +474,8 @@ def library_dict(library_id):
         #'antibody_name': lib.antibody_name(), # we have no antibodies.
         'antibody_id': lib.antibody_id,
         'avg_lib_size': lib.avg_lib_size,
-        'cell_line': lib.cell_line.cellline_name,
         'cell_line_id': lib.cell_line_id,
+        'cell_line': unicode_or_none(lib.cell_line),
         'experiment_type': lib.experiment_type.name,
         'experiment_type_id': lib.experiment_type_id,
         'id': lib.id,
@@ -489,8 +491,8 @@ def library_dict(library_id):
         'notes': lib.notes,
         'replicate': lib.replicate,
         'stopping_point': lib.stopping_point,
-        'successful_pM': unicode(lib.successful_pM),
-        'undiluted_concentration': unicode(lib.undiluted_concentration)
+        'successful_pM': unicode_or_none(lib.successful_pM),
+        'undiluted_concentration': unicode_or_none(lib.undiluted_concentration)
         }
     if lib.library_type_id is None:
         info['library_type'] = None
diff --git a/htsworkflow/util/conversion.py b/htsworkflow/util/conversion.py
new file mode 100644 (file)
index 0000000..9246468
--- /dev/null
@@ -0,0 +1,12 @@
+"""
+Miscellaneous, more refined type casting functions
+"""
+
+def unicode_or_none(value):
+    """
+    Convert value to unicode if its not none.
+    """
+    if value is None:
+        return None
+    else:
+        return unicode(value)