update docstring
[htsworkflow.git] / experiments / test_experiments.py
index ba27db4706bb18da6a58639321fd517d897fdbd1..ebbaf40cb24093276eef90ece9fe4d55bbe0e879 100644 (file)
@@ -1,49 +1,54 @@
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 import re
 from lxml.html import fromstring
-try:
-    import json
-except ImportError, e:
-    import simplejson as json
+import json
 import os
 import shutil
-import sys
 import tempfile
-from urlparse import urljoin
+from six.moves.urllib.parse import urljoin
 
 from django.conf import settings
 from django.core import mail
 from django.core.exceptions import ObjectDoesNotExist
+from django.core.urlresolvers import reverse
 from django.test import TestCase
-from django.test.utils import setup_test_environment, teardown_test_environment
-from django.db import connection
-from django.conf import settings
+from django.utils.encoding import smart_text
 
-from .models import ClusterStation, DataRun, Sequencer, FlowCell, FileType, \
-    find_file_type_metadata_from_filename
+from .models import DataRun, Sequencer, FlowCell, FileType
+from samples.models import HTSUser
 from .experiments import flowcell_information, lanes_for
+from .experiments_factory import FlowCellFactory, LaneFactory
+from samples.samples_factory import AffiliationFactory, HTSUserFactory, \
+    LibraryFactory, LibraryTypeFactory, MultiplexIndexFactory
 from htsworkflow.auth import apidata
 from htsworkflow.util.ethelp import validate_xhtml
 
 from htsworkflow.pipelines.test.simulate_runfolder import TESTDATA_DIR
 
-LANE_SET = range(1,9)
-
-NSMAP = {'libns':'http://jumpgate.caltech.edu/wiki/LibraryOntology#'}
+LANE_SET = range(1, 9)
 
-from django.db import connection
+NSMAP = {'libns': 'http://jumpgate.caltech.edu/wiki/LibraryOntology#'}
 
 
 class ExperimentsTestCases(TestCase):
-    fixtures = ['initial_data.json',
-                'test_flowcells.json',
-                ]
-
     def setUp(self):
+        # Generate at least one fleshed out example flowcell
         self.tempdir = tempfile.mkdtemp(prefix='htsw-test-experiments-')
         settings.RESULT_HOME_DIR = self.tempdir
 
+        self.password = 'password'
+        self.user_odd = HTSUserFactory(username='user-odd')
+        self.user_odd.set_password(self.password)
+        self.affiliation_odd = AffiliationFactory(name='affiliation-odd', users=[self.user_odd])
+        self.user_even = HTSUserFactory(username='user-even')
+        self.user_even.set_password(self.password)
+        self.affiliation_even = AffiliationFactory(name='affiliation-even', users=[self.user_even])
+        self.admin = HTSUserFactory.create(username='admin', is_staff=True, is_superuser=True)
+        self.admin.set_password(self.password)
+        self.admin.save()
+
+        self.fc12150 = FlowCellFactory(flowcell_id='FC12150')
         self.fc1_id = 'FC12150'
         self.fc1_root = os.path.join(self.tempdir, self.fc1_id)
         os.mkdir(self.fc1_root)
@@ -52,13 +57,31 @@ class ExperimentsTestCases(TestCase):
         runxml = 'run_FC12150_2007-09-27.xml'
         shutil.copy(os.path.join(TESTDATA_DIR, runxml),
                     os.path.join(self.fc1_dir, runxml))
-        for i in range(1,9):
+        for i in range(1, 9):
+            affiliation = self.affiliation_odd if i % 2 == 1 else self.affiliation_even
+            library = LibraryFactory(id="1215" + str(i))
+            library.affiliations.add(affiliation)
+            lane = LaneFactory(flowcell=self.fc12150, lane_number=i, library=library)
             shutil.copy(
                 os.path.join(TESTDATA_DIR,
                              'woldlab_070829_USI-EAS44_0017_FC11055_1.srf'),
                 os.path.join(self.fc1_dir,
                              'woldlab_070829_SERIAL_FC12150_%d.srf' %(i,))
                 )
+        self.fc12150.save()
+
+        self.fc42jtn = FlowCellFactory(flowcell_id='42JTNAAXX')
+        self.fc42jtn_lanes = []
+        for i in range(1, 9):
+            affiliation = self.affiliation_odd if i % 2 == 1 else self.affiliation_even
+            library_type = LibraryTypeFactory(can_multiplex=True)
+            multiplex_index = MultiplexIndexFactory(adapter_type=library_type)
+            library = LibraryFactory(id="1300" + str(i),
+                                     library_type=library_type,
+                                     multiplex_id=multiplex_index.multiplex_id)
+            library.affiliations.add(affiliation)
+            lane = LaneFactory(flowcell=self.fc42jtn, lane_number=(i % 2) + 1, library=library)
+            self.fc42jtn_lanes.append(lane)
 
         self.fc2_dir = os.path.join(self.tempdir, '42JTNAAXX')
         os.mkdir(self.fc2_dir)
@@ -73,7 +96,11 @@ class ExperimentsTestCases(TestCase):
         """
         Check the code that packs the django objects into simple types.
         """
-        for fc_id in [u'FC12150', u"42JTNAAXX", "42JU1AAXX"]:
+        fc12150 = self.fc12150
+        fc42jtn = self.fc42jtn
+        fc42ju1 = FlowCellFactory(flowcell_id='42JU1AAXX')
+
+        for fc_id in ['FC12150', '42JTNAAXX', '42JU1AAXX']:
             fc_dict = flowcell_information(fc_id)
             fc_django = FlowCell.objects.get(flowcell_id=fc_id)
             self.assertEqual(fc_dict['flowcell_id'], fc_id)
@@ -98,7 +125,7 @@ class ExperimentsTestCases(TestCase):
 
             response = self.client.get('/experiments/config/%s/json' % (fc_id,), apidata)
             # strptime isoformat string = '%Y-%m-%dT%H:%M:%S'
-            fc_json = json.loads(response.content)['result']
+            fc_json = json.loads(smart_text(response.content))['result']
             self.assertEqual(fc_json['flowcell_id'], fc_id)
             self.assertEqual(fc_json['sequencer'], fc_django.sequencer.name)
             self.assertEqual(fc_json['read_length'], fc_django.read_length)
@@ -107,7 +134,7 @@ class ExperimentsTestCases(TestCase):
 
 
             for lane in fc_django.lane_set.all():
-                lane_contents = fc_json['lane_set'][unicode(lane.lane_number)]
+                lane_contents = fc_json['lane_set'][str(lane.lane_number)]
                 lane_dict = multi_lane_to_dict(lane_contents)[lane.library_id]
 
                 self.assertEqual(lane_dict['cluster_estimate'], lane.cluster_estimate)
@@ -131,43 +158,43 @@ class ExperimentsTestCases(TestCase):
         """
         Require logging in to retrieve meta data
         """
-        response = self.client.get(u'/experiments/config/FC12150/json')
+        response = self.client.get('/experiments/config/FC12150/json')
         self.assertEqual(response.status_code, 403)
 
     def test_library_id(self):
-        """
-        Library IDs should be flexible, so make sure we can retrive a non-numeric ID
+        """make sure we can retrive a non-numeric library ID
         """
         response = self.client.get('/experiments/config/FC12150/json', apidata)
         self.assertEqual(response.status_code, 200)
-        flowcell = json.loads(response.content)['result']
+        flowcell = json.loads(smart_text(response.content))['result']
 
+        # library id is 12150 + lane number (1-8), so 12153
         lane_contents = flowcell['lane_set']['3']
         lane_library = lane_contents[0]
-        self.assertEqual(lane_library['library_id'], 'SL039')
+        self.assertEqual(lane_library['library_id'], '12153')
 
-        response = self.client.get('/samples/library/SL039/json', apidata)
+        response = self.client.get('/samples/library/12153/json', apidata)
         self.assertEqual(response.status_code, 200)
-        library_sl039 = json.loads(response.content)['result']
+        library_12153 = json.loads(smart_text(response.content))['result']
 
-        self.assertEqual(library_sl039['library_id'], 'SL039')
+        self.assertEqual(library_12153['library_id'], '12153')
 
     def test_raw_id_field(self):
-        """
-        Test ticket:147
+        """Test ticket:147
 
         Library's have IDs, libraries also have primary keys,
-        we eventually had enough libraries that the drop down combo box was too
-        hard to filter through, unfortnately we want a field that uses our library
-        id and not the internal primary key, and raw_id_field uses primary keys.
+        we eventually had enough libraries that the drop down combo
+        box was too hard to filter through, unfortnately we want a
+        field that uses our library id and not the internal
+        primary key, and raw_id_field uses primary keys.
+
+        This tests to make sure that the value entered in the raw
+        library id field matches the library id looked up.
 
-        This tests to make sure that the value entered in the raw library id field matches
-        the library id looked up.
         """
-        expected_ids = [u'10981',u'11016',u'SL039',u'11060',
-                        u'11061',u'11062',u'11063',u'11064']
-        self.client.login(username='supertest', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/admin/experiments/flowcell/153/')
+        expected_ids = [ '1215{}'.format(i) for i in range(1,9) ]
+        self.assertTrue(self.client.login(username=self.admin.username, password=self.password))
+        response = self.client.get('/admin/experiments/flowcell/{}/'.format(self.fc12150.id))
 
         tree = fromstring(response.content)
         for i in range(0,8):
@@ -185,8 +212,8 @@ class ExperimentsTestCases(TestCase):
         Make sure the library page includes links to the flowcell pages.
         That work with flowcell IDs that have parenthetical comments.
         """
-        self.client.login(username='supertest', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/library/11070/')
+        self.assertTrue(self.client.login(username=self.admin.username, password=self.password))
+        response = self.client.get('/library/12151/')
         self.assertEqual(response.status_code, 200)
         status = validate_xhtml(response.content)
         if status is not None: self.assertTrue(status)
@@ -194,48 +221,73 @@ class ExperimentsTestCases(TestCase):
         tree = fromstring(response.content)
         flowcell_spans = tree.xpath('//span[@property="libns:flowcell_id"]',
                                     namespaces=NSMAP)
-        self.assertEqual(flowcell_spans[1].text, '30012AAXX (failed)')
+        self.assertEqual(flowcell_spans[1].text, 'FC12150')
         failed_fc_span = flowcell_spans[1]
         failed_fc_a = failed_fc_span.getparent()
         # make sure some of our RDF made it.
         self.assertEqual(failed_fc_a.get('typeof'), 'libns:IlluminaFlowcell')
-        self.assertEqual(failed_fc_a.get('href'), '/flowcell/30012AAXX/')
+        self.assertEqual(failed_fc_a.get('href'), '/flowcell/FC12150/')
         fc_response = self.client.get(failed_fc_a.get('href'))
         self.assertEqual(fc_response.status_code, 200)
         status = validate_xhtml(response.content)
         if status is not None: self.assertTrue(status)
 
-        fc_lane_response = self.client.get('/flowcell/30012AAXX/8/')
+        fc_lane_response = self.client.get('/flowcell/FC12150/8/')
         self.assertEqual(fc_lane_response.status_code, 200)
         status = validate_xhtml(response.content)
         if status is not None: self.assertTrue(status)
 
-
     def test_pooled_multiplex_id(self):
-        fc_dict = flowcell_information('42JU1AAXX')
-        lane_contents = fc_dict['lane_set'][3]
-        self.assertEqual(len(lane_contents), 2)
+        fc_dict = flowcell_information(self.fc42jtn.flowcell_id)
+
+        lane_contents = fc_dict['lane_set'][2]
+        self.assertEqual(len(lane_contents), len(self.fc42jtn_lanes) / 2)
         lane_dict = multi_lane_to_dict(lane_contents)
 
-        self.assertEqual(lane_dict['12044']['index_sequence'],
-                         {u'1': u'ATCACG',
-                          u'2': u'CGATGT',
-                          u'3': u'TTAGGC'})
-        self.assertEqual(lane_dict['11045']['index_sequence'],
-                         {u'1': u'ATCACG'})
+        self.assertTrue(self.fc42jtn_lanes[0].library.multiplex_id in \
+                        lane_dict['13001']['index_sequence'])
+        self.assertTrue(self.fc42jtn_lanes[2].library.multiplex_id in \
+                        lane_dict['13003']['index_sequence'])
 
 
+    def test_lanes_for_view_user_odd(self):
+        """Make sure lanes_for HTML UI works.
+        """
+        user = self.user_odd.username
+        lanes = lanes_for(user)
+        self.assertEqual(len(lanes), 8)
 
-    def test_lanes_for(self):
+        response = self.client.get(
+            reverse('experiments.views.lanes_for',
+                    args=[user]))
+        self.assertEqual(response.status_code, 200)
+        tree = fromstring(response.content)
+        lane_trs = tree.xpath('//div[@id="changelist"]/table/tbody/tr')
+        self.assertEqual(len(lane_trs), len(lanes))
+        # lanes is in db order
+        # lane_trs is in newest to oldest order
+        for lane_tr, lane_db in zip(lane_trs, reversed(lanes)):
+            library_id = lane_tr.xpath('td[6]/a')[0].text
+            self.assertEqual(library_id, lane_db['library'])
+
+    def test_lanes_for_view_invalid_user(self):
+        """Make sure we don't find anything with an invalid user
+        """
+        response = self.client.get(
+            reverse('experiments.views.lanes_for',
+                    args=["doesntexist"]))
+        self.assertEqual(response.status_code, 404)
+
+    def test_lanes_for_json(self):
         """
         Check the code that packs the django objects into simple types.
         """
-        user = 'test'
+        user = self.user_odd.username
         lanes = lanes_for(user)
-        self.assertEqual(len(lanes), 5)
+        self.assertEqual(len(lanes), 8)
 
         response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata)
-        lanes_json = json.loads(response.content)['result']
+        lanes_json = json.loads(smart_text(response.content))['result']
         self.assertEqual(len(lanes), len(lanes_json))
         for i in range(len(lanes)):
             self.assertEqual(lanes[i]['comment'], lanes_json[i]['comment'])
@@ -247,12 +299,12 @@ class ExperimentsTestCases(TestCase):
         """
         Do we get something meaningful back when the user isn't attached to anything?
         """
-        user = 'supertest'
-        lanes = lanes_for(user)
+        user = HTSUserFactory.create(username='supertest')
+        lanes = lanes_for(user.username)
         self.assertEqual(len(lanes), 0)
 
         response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata)
-        lanes_json = json.loads(response.content)
+        self.assertEqual(response.status_code, 404)
 
     def test_lanes_for_no_user(self):
         """
@@ -264,7 +316,6 @@ class ExperimentsTestCases(TestCase):
         response = self.client.get('/experiments/lanes_for/%s/json' % (user,), apidata)
         self.assertEqual(response.status_code, 404)
 
-
     def test_raw_data_dir(self):
         """Raw data path generator check"""
         flowcell_id = self.fc1_id
@@ -276,7 +327,6 @@ class ExperimentsTestCases(TestCase):
         fc.flowcell_id = flowcell_id + " (failed)"
         self.assertEqual(fc.get_raw_data_directory(), raw_dir)
 
-
     def test_data_run_import(self):
         srf_file_type = FileType.objects.get(name='SRF')
         runxml_file_type = FileType.objects.get(name='run_xml')
@@ -291,11 +341,11 @@ class ExperimentsTestCases(TestCase):
 
         srf4 = result_dict['FC12150/C1-37/woldlab_070829_SERIAL_FC12150_4.srf']
         self.assertEqual(srf4.file_type, srf_file_type)
-        self.assertEqual(srf4.library_id, '11060')
+        self.assertEqual(srf4.library_id, '12154')
         self.assertEqual(srf4.data_run.flowcell.flowcell_id, 'FC12150')
         self.assertEqual(
             srf4.data_run.flowcell.lane_set.get(lane_number=4).library_id,
-            '11060')
+            '12154')
         self.assertEqual(
             srf4.pathname,
             os.path.join(settings.RESULT_HOME_DIR, srf4.relative_pathname))
@@ -346,22 +396,22 @@ class ExperimentsTestCases(TestCase):
 
         model = get_model()
 
-        expected = {'1': ['11034'],
-                    '2': ['11036'],
-                    '3': ['12044','11045'],
-                    '4': ['11047','13044'],
-                    '5': ['11055'],
-                    '6': ['11067'],
-                    '7': ['11069'],
-                    '8': ['11070']}
-        url = '/flowcell/42JU1AAXX/'
+        expected = {'1': ['12151'],
+                    '2': ['12152'],
+                    '3': ['12153'],
+                    '4': ['12154'],
+                    '5': ['12155'],
+                    '6': ['12156'],
+                    '7': ['12157'],
+                    '8': ['12158']}
+        url = '/flowcell/{}/'.format(self.fc12150.flowcell_id)
         response = self.client.get(url)
         self.assertEqual(response.status_code, 200)
         status = validate_xhtml(response.content)
         if status is not None: self.assertTrue(status)
 
         ns = urljoin('http://localhost', url)
-        load_string_into_model(model, 'rdfa', response.content, ns=ns)
+        load_string_into_model(model, 'rdfa', smart_text(response.content), ns=ns)
         body = """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
         prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#>
 
@@ -378,104 +428,63 @@ class ExperimentsTestCases(TestCase):
         count = 0
         for r in query.execute(model):
             count += 1
-            self.assertEqual(fromTypedNode(r['flowcell_id']), u'42JU1AAXX')
+            self.assertEqual(fromTypedNode(r['flowcell_id']), 'FC12150')
             lane_id = fromTypedNode(r['lane_id'])
             library_id = fromTypedNode(r['library_id'])
             self.assertTrue(library_id in expected[lane_id])
-        self.assertEqual(count, 10)
-
-
-class TestFileType(TestCase):
-    fixtures = ['initial_data.json',
-                'test_flowcells.json',
-                ]
-
-    def test_file_type_unicode(self):
-        file_type_objects = FileType.objects
-        name = 'QSEQ tarfile'
-        file_type_object = file_type_objects.get(name=name)
-        self.assertEqual(u"QSEQ tarfile",
-                             unicode(file_type_object))
-
-    def test_find_file_type(self):
-        file_type_objects = FileType.objects
-        cases = [('woldlab_090921_HWUSI-EAS627_0009_42FC3AAXX_l7_r1.tar.bz2',
-                  'QSEQ tarfile', 7, 1),
-                 ('woldlab_091005_HWUSI-EAS627_0010_42JT2AAXX_1.srf',
-                  'SRF', 1, None),
-                 ('s_1_eland_extended.txt.bz2','ELAND Extended', 1, None),
-                 ('s_7_eland_multi.txt.bz2', 'ELAND Multi', 7, None),
-                 ('s_3_eland_result.txt.bz2','ELAND Result', 3, None),
-                 ('s_1_export.txt.bz2','ELAND Export', 1, None),
-                 ('s_1_percent_call.png', 'IVC Percent Call', 1, None),
-                 ('s_2_percent_base.png', 'IVC Percent Base', 2, None),
-                 ('s_3_percent_all.png', 'IVC Percent All', 3, None),
-                 ('s_4_call.png', 'IVC Call', 4, None),
-                 ('s_5_all.png', 'IVC All', 5, None),
-                 ('Summary.htm', 'Summary.htm', None, None),
-                 ('run_42JT2AAXX_2009-10-07.xml', 'run_xml', None, None),
-         ]
-        for filename, typename, lane, end in cases:
-            ft = find_file_type_metadata_from_filename(filename)
-            self.assertEqual(ft['file_type'],
-                                 file_type_objects.get(name=typename))
-            self.assertEqual(ft.get('lane', None), lane)
-            self.assertEqual(ft.get('end', None), end)
-
-    def test_assign_file_type_complex_path(self):
-        file_type_objects = FileType.objects
-        cases = [('/a/b/c/woldlab_090921_HWUSI-EAS627_0009_42FC3AAXX_l7_r1.tar.bz2',
-                  'QSEQ tarfile', 7, 1),
-                 ('foo/woldlab_091005_HWUSI-EAS627_0010_42JT2AAXX_1.srf',
-                  'SRF', 1, None),
-                 ('../s_1_eland_extended.txt.bz2','ELAND Extended', 1, None),
-                 ('/bleem/s_7_eland_multi.txt.bz2', 'ELAND Multi', 7, None),
-                 ('/qwer/s_3_eland_result.txt.bz2','ELAND Result', 3, None),
-                 ('/ty///1/s_1_export.txt.bz2','ELAND Export', 1, None),
-                 ('/help/s_1_percent_call.png', 'IVC Percent Call', 1, None),
-                 ('/bored/s_2_percent_base.png', 'IVC Percent Base', 2, None),
-                 ('/example1/s_3_percent_all.png', 'IVC Percent All', 3, None),
-                 ('amonkey/s_4_call.png', 'IVC Call', 4, None),
-                 ('fishie/s_5_all.png', 'IVC All', 5, None),
-                 ('/random/Summary.htm', 'Summary.htm', None, None),
-                 ('/notrandom/run_42JT2AAXX_2009-10-07.xml', 'run_xml', None, None),
-         ]
-        for filename, typename, lane, end in cases:
-            result = find_file_type_metadata_from_filename(filename)
-            self.assertEqual(result['file_type'],
-                                 file_type_objects.get(name=typename))
-            self.assertEqual(result.get('lane',None), lane)
-            self.assertEqual(result.get('end', None), end)
+        self.assertEqual(count, 8)
 
 class TestEmailNotify(TestCase):
-    fixtures = ['initial_data.json',
-                'test_flowcells.json']
+    def setUp(self):
+        self.password = 'foo27'
+        self.user = HTSUserFactory.create(username='test')
+        self.user.set_password(self.password)
+        self.user.save()
+        self.admin = HTSUserFactory.create(username='admintest', is_staff=True)
+        self.admin.set_password(self.password)
+        self.admin.save()
+        self.super = HTSUserFactory.create(username='supertest', is_staff=True, is_superuser=True)
+        self.super.set_password(self.password)
+        self.super.save()
+
+        self.library = LibraryFactory.create()
+        self.affiliation = AffiliationFactory()
+        self.affiliation.users.add(self.user)
+        self.library.affiliations.add(self.affiliation)
+        self.fc = FlowCellFactory.create()
+        self.lane = LaneFactory(flowcell=self.fc, lane_number=1, library=self.library)
+
+        self.url = '/experiments/started/{}/'.format(self.fc.id)
 
     def test_started_email_not_logged_in(self):
-        response = self.client.get('/experiments/started/153/')
+        response = self.client.get(self.url)
         self.assertEqual(response.status_code, 302)
 
     def test_started_email_logged_in_user(self):
-        self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/experiments/started/153/')
+        self.assertTrue(self.client.login(username=self.user.username, password=self.password))
+        response = self.client.get(self.url)
         self.assertEqual(response.status_code, 302)
 
     def test_started_email_logged_in_staff(self):
-        self.client.login(username='admintest', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/experiments/started/153/')
+        self.assertTrue(self.admin.is_staff)
+        admin = HTSUser.objects.get(username=self.admin.username)
+        self.assertTrue(admin.is_staff)
+        self.assertTrue(admin.check_password(self.password))
+        self.assertTrue(self.client.login(username=self.admin.username, password=self.password))
+        response = self.client.get(self.url)
         self.assertEqual(response.status_code, 200)
 
     def test_started_email_send(self):
-        self.client.login(username='admintest', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/experiments/started/153/')
+        self.assertTrue(self.client.login(username=self.admin.username, password=self.password))
+        response = self.client.get(self.url)
         self.assertEqual(response.status_code, 200)
 
-        self.assertTrue('pk1@example.com' in response.content)
-        self.assertTrue('Lane #8 : (11064) Paired ends 104' in response.content)
+        self.assertTrue(self.affiliation.email in smart_text(response.content))
+        self.assertTrue(self.library.library_name in smart_text(response.content))
 
-        response = self.client.get('/experiments/started/153/', {'send':'1','bcc':'on'})
+        response = self.client.get(self.url, {'send':'1','bcc':'on'})
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(len(mail.outbox), 4)
+        self.assertEqual(len(mail.outbox), 2)
         bcc = set(settings.NOTIFICATION_BCC).copy()
         bcc.update(set(settings.MANAGERS))
         for m in mail.outbox:
@@ -486,12 +495,15 @@ class TestEmailNotify(TestCase):
         """
         Can we navigate between the flowcell and email forms properly?
         """
-        self.client.login(username='supertest', password='BJOKL5kAj6aFZ6A5')
-        response = self.client.get('/experiments/started/153/')
+        admin_url = '/admin/experiments/flowcell/{}/'.format(self.fc.id)
+        self.client.login(username=self.admin.username, password=self.password)
+        response = self.client.get(self.url)
         self.assertEqual(response.status_code, 200)
-        self.assertTrue(re.search('Flowcell FC12150', response.content))
+        #print("email navigation content:", response.content)
+        self.assertTrue(re.search(self.fc.flowcell_id, smart_text(response.content)))
         # require that navigation back to the admin page exists
-        self.assertTrue(re.search('<a href="/admin/experiments/flowcell/153/">[^<]+</a>', response.content))
+        self.assertTrue(re.search('<a href="{}">[^<]+</a>'.format(admin_url),
+                                  smart_text(response.content)))
 
 def multi_lane_to_dict(lane):
     """Convert a list of lane entries into a dictionary indexed by library ID
@@ -499,9 +511,10 @@ def multi_lane_to_dict(lane):
     return dict( ((x['library_id'],x) for x in lane) )
 
 class TestSequencer(TestCase):
-    fixtures = ['initial_data.json',
-                'test_flowcells.json',
-                ]
+    def setUp(self):
+        self.fc12150 = FlowCellFactory(flowcell_id='FC12150')
+        self.library = LibraryFactory(id="12150")
+        self.lane = LaneFactory(flowcell=self.fc12150, lane_number=1, library=self.library)
 
     def test_name_generation(self):
         seq = Sequencer()
@@ -509,14 +522,12 @@ class TestSequencer(TestCase):
         seq.instrument_name = "HWI-SEQ1"
         seq.model = "Imaginary 5000"
 
-        self.assertEqual(unicode(seq), "Seq1 (HWI-SEQ1)")
+        self.assertEqual(str(seq), "Seq1 (HWI-SEQ1)")
 
     def test_lookup(self):
-        fc = FlowCell.objects.get(pk=153)
-        self.assertEqual(fc.sequencer.model,
-                             "Illumina Genome Analyzer IIx")
-        self.assertEqual(fc.sequencer.instrument_name,
-                             "ILLUMINA-EC5D15")
+        fc = self.fc12150
+        self.assertEqual(fc.sequencer.model, 'HiSeq 1')
+        self.assertTrue(fc.sequencer.instrument_name.startswith('instrument name')),
         # well actually we let the browser tack on the host name
         url = fc.get_absolute_url()
         self.assertEqual(url, '/flowcell/FC12150/')
@@ -530,20 +541,21 @@ class TestSequencer(TestCase):
         self.assertEqual(seq_by[0].attrib['rel'], 'libns:sequenced_by')
         seq = seq_by[0].getchildren()
         self.assertEqual(len(seq), 1)
-        self.assertEqual(seq[0].attrib['about'], '/sequencer/2')
+        sequencer = '/sequencer/' + str(self.fc12150.sequencer.id)
+        self.assertEqual(seq[0].attrib['about'], sequencer)
         self.assertEqual(seq[0].attrib['typeof'], 'libns:Sequencer')
 
         name = seq[0].xpath('./span[@property="libns:sequencer_name"]')
         self.assertEqual(len(name), 1)
-        self.assertEqual(name[0].text, 'Tardigrade')
+        self.assertTrue(name[0].text.startswith('sequencer '))
         instrument = seq[0].xpath(
             './span[@property="libns:sequencer_instrument"]')
         self.assertEqual(len(instrument), 1)
-        self.assertEqual(instrument[0].text, 'ILLUMINA-EC5D15')
+        self.assertTrue(instrument[0].text.startswith('instrument name'))
         model = seq[0].xpath(
             './span[@property="libns:sequencer_model"]')
         self.assertEqual(len(model), 1)
-        self.assertEqual(model[0].text, 'Illumina Genome Analyzer IIx')
+        self.assertEqual(model[0].text, 'HiSeq 1')
 
     def test_flowcell_with_rdf_validation(self):
         from htsworkflow.util.rdfhelp import add_default_schemas, \
@@ -562,7 +574,7 @@ class TestSequencer(TestCase):
         status = validate_xhtml(response.content)
         if status is not None: self.assertTrue(status)
 
-        load_string_into_model(model, 'rdfa', response.content)
+        load_string_into_model(model, 'rdfa', smart_text(response.content))
 
         errmsgs = list(inference.run_validation())
         self.assertEqual(len(errmsgs), 0)
@@ -578,13 +590,14 @@ class TestSequencer(TestCase):
         add_default_schemas(model)
         inference = Infer(model)
 
-        url = '/lane/1193'
+        url = '/lane/{}'.format(self.lane.id)
         response = self.client.get(url)
+        rdfbody = smart_text(response.content)
         self.assertEqual(response.status_code, 200)
-        status = validate_xhtml(response.content)
+        status = validate_xhtml(rdfbody)
         if status is not None: self.assertTrue(status)
 
-        load_string_into_model(model, 'rdfa', response.content)
+        load_string_into_model(model, 'rdfa', rdfbody)
 
         errmsgs = list(inference.run_validation())
         self.assertEqual(len(errmsgs), 0)
@@ -592,10 +605,7 @@ class TestSequencer(TestCase):
 def suite():
     from unittest import TestSuite, defaultTestLoader
     suite = TestSuite()
-    for testcase in [ClusterStationTestCases,
-                     SequencerTestCases,
-                     ExerimentsTestCases,
-                     TestFileType,
+    for testcase in [ExerimentsTestCases,
                      TestEmailNotify,
                      TestSequencer]:
         suite.addTests(defaultTestLoader.loadTestsFromTestCase(testcase))