Turn the library_id back into the primary key for samples_library (SCHEMA CHANGE!)
[htsworkflow.git] / htsworkflow / frontend / samples / tests.py
index 595727e13510c0eaa369e668056cef5c005b988d..f8eaf0ff0fe11e016df65f0d47586d880fab5979 100644 (file)
@@ -18,6 +18,8 @@ from htsworkflow.frontend.samples.views import \
      library_dict, \
      library_json
 
+from htsworkflow.frontend.auth import apidata
+
 # 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 +71,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,
@@ -81,7 +83,7 @@ def create_db(obj):
     )
     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,
@@ -122,16 +124,15 @@ 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
@@ -143,7 +144,6 @@ class SampleWebTestCase(TestCase):
                 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)
-                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)
@@ -164,17 +164,15 @@ class SampleWebTestCase(TestCase):
         """
         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)