Invalid library IDs should 404, not return a useless error message
authorDiane Trout <diane@caltech.edu>
Mon, 23 Jan 2012 19:49:50 +0000 (11:49 -0800)
committerDiane Trout <diane@caltech.edu>
Mon, 23 Jan 2012 19:49:50 +0000 (11:49 -0800)
htsworkflow/frontend/samples/tests.py
htsworkflow/frontend/samples/views.py

index 93f46d017041642a733edc15d2c0324534f7d62f..476ede36ebd9c697172650404dd496f34f66e5cb 100644 (file)
@@ -5,7 +5,7 @@ try:
     import json
 except ImportError, e:
     import simplejson as json
-    
+
 from django.test import TestCase
 
 from htsworkflow.frontend.samples.models import \
@@ -27,14 +27,14 @@ class LibraryTestCase(TestCase):
 
     def setUp(self):
         create_db(self)
-               
+
     def testOrganism(self):
         self.assertEquals(self.library_10001.organism(), 'human')
 
     def testAffiliations(self):
         self.library_10001.affiliations.add(self.affiliation_alice)
         self.library_10002.affiliations.add(
-                self.affiliation_alice, 
+                self.affiliation_alice,
                 self.affiliation_bob
         )
         self.failUnless(len(self.library_10001.affiliations.all()), 1)
@@ -104,14 +104,20 @@ class SampleWebTestCase(TestCase):
                     self.failUnlessEqual(len(d['lane_set']), 1)
                     self.failUnlessEqual(d['lane_set'][0], lane_set)
 
-    def test_invalid_library(self):
+
+    def test_invalid_library_json(self):
         """
         Make sure we get a 404 if we request an invalid library id
         """
         response = self.client.get('/samples/library/nottheone/json', apidata)
         self.failUnlessEqual(response.status_code, 404)
 
-            
+
+    def test_invalid_library(self):
+        response = self.client.get('/library/nottheone/')
+        self.failUnlessEqual(response.status_code, 404)
+
+
     def test_library_no_key(self):
         """
         Make sure we get a 302 if we're not logged in
@@ -121,6 +127,7 @@ class SampleWebTestCase(TestCase):
         response = self.client.get('/samples/library/10981/json', apidata)
         self.failUnlessEqual(response.status_code, 200)
 
+
 # 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.
@@ -129,7 +136,7 @@ def create_db(obj):
     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",
@@ -157,7 +164,7 @@ def create_db(obj):
         hidden = False,
     )
     obj.library_10002.save()
+
 try:
     import RDF
     HAVE_RDF = True
@@ -168,7 +175,7 @@ try:
 except ImportError,e:
     HAVE_RDF = False
 
-    
+
 class TestRDFaLibrary(TestCase):
     fixtures = ['test_samples.json']
 
@@ -178,7 +185,7 @@ class TestRDFaLibrary(TestCase):
         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)
@@ -197,7 +204,7 @@ class TestRDFaLibrary(TestCase):
         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)))
index 0159a9a73a5f53db10abcd0d93456e824e5118f2..2a8014b6cb1b75ead4f9985baf9c530969085c15 100644 (file)
@@ -116,11 +116,10 @@ def library_to_flowcells(request, lib_id):
     """
     Display information about all the flowcells a library has been run on.
     """
-
     try:
-      lib = Library.objects.get(id=lib_id)
+        lib = Library.objects.get(id=lib_id)
     except:
-      return HttpResponse("Library %s does not exist" % (lib_id))
+        raise Http404('Library %s does not exist' % (lib_id,))
 
     flowcell_list = []
     flowcell_run_results = {} # aka flowcells we're looking at