Report hidden field in the library API
[htsworkflow.git] / htsworkflow / frontend / samples / tests.py
index 595727e13510c0eaa369e668056cef5c005b988d..d1689f1968700aa5a00b85474dc4643075c3de2d 100644 (file)
@@ -18,6 +18,9 @@ from htsworkflow.frontend.samples.views import \
      library_dict, \
      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
 # of interest before creating our sample data.
@@ -69,7 +72,7 @@ def create_db(obj):
 
     Library.objects.all().delete()
     obj.library_10001 = Library(
-        library_id = 10001,
+        id = "10001",
         library_name = 'C2C12 named poorly',
         library_species = obj.species_human,
         experiment_type = obj.experiment_rna_seq,
@@ -78,10 +81,11 @@ def create_db(obj):
         made_by = 'microfludics system 7321',
         stopping_point = '2A',
         undiluted_concentration = '5.01',
+        hidden = False,
     )
     obj.library_10001.save()
     obj.library_10002 = Library(
-        library_id = 10002,
+        id = "10002",
         library_name = 'Worm named poorly',
         library_species = obj.species_human,
         experiment_type = obj.experiment_rna_seq,
@@ -90,6 +94,7 @@ def create_db(obj):
         made_by = 'microfludics system 7321',
         stopping_point = '2A',
         undiluted_concentration = '5.01',
+        hidden = False,
     )
     obj.library_10002.save()
  
@@ -122,28 +127,27 @@ class SampleWebTestCase(TestCase):
     def test_library_info(self):
 
         for lib in Library.objects.all():
-            lib_dict = library_dict(lib.library_id)
-            self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
-            url = '/samples/library/%s/json' % (lib.library_id,)
-            lib_response = self.client.get(url)
+            lib_dict = library_dict(lib.id)
+            url = '/samples/library/%s/json' % (lib.id,)
+            lib_response = self.client.get(url, apidata)
             self.failUnlessEqual(lib_response.status_code, 200)
             lib_json = json.loads(lib_response.content)
 
             for d in [lib_dict, lib_json]:
                 # amplified_from_sample is a link to the library table,
-                # I want to use the "library_id" for the data lookups not
+                # I want to use the "id" for the data lookups not
                 # the embedded primary key.
                 # It gets slightly confusing on how to implement sending the right id
                 # since amplified_from_sample can be null
                 #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['hidden'], lib.hidden)
                 self.failUnlessEqual(d['id'], lib.id)
-                self.failUnlessEqual(d['library_id'], lib.library_id)
                 self.failUnlessEqual(d['library_name'], lib.library_name)
                 self.failUnlessEqual(d['library_species'], lib.library_species.scientific_name)
                 self.failUnlessEqual(d['library_species_id'], lib.library_species_id)
@@ -159,22 +163,21 @@ class SampleWebTestCase(TestCase):
                     self.failUnlessEqual(d['stopping_point'], lib.stopping_point)
                     self.failUnlessEqual(d['successful_pM'], lib.successful_pM)
                     self.failUnlessEqual(d['undiluted_concentration'],
-                                         unicode(lib.undiluted_concentration))                                 
+                                         unicode(lib.undiluted_concentration))
+
     def test_invalid_library(self):
         """
         Make sure we get a 404 if we request an invalid library id
         """
-        self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/samples/library/nottheone/json')
+        response = self.client.get('/samples/library/nottheone/json', apidata)
         self.failUnlessEqual(response.status_code, 404)
 
             
-    def test_library_not_logged_in(self):
+    def test_library_no_key(self):
         """
         Make sure we get a 302 if we're not logged in
         """
         response = self.client.get('/samples/library/10981/json')
-        self.failUnlessEqual(response.status_code, 302)
-        self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/samples/library/10981/json')
+        self.failUnlessEqual(response.status_code, 403)
+        response = self.client.get('/samples/library/10981/json', apidata)
         self.failUnlessEqual(response.status_code, 200)