Update test_retrieve_config to work with factories
authorDiane Trout <diane@ghic.org>
Wed, 21 Jan 2015 01:17:04 +0000 (17:17 -0800)
committerDiane Trout <diane@ghic.org>
Wed, 21 Jan 2015 01:17:04 +0000 (17:17 -0800)
Along the way I slightly altered how the species factory
worked which required tweaking test_samples.
For some reason test_sequencer changed slightly.

bcmagic/fixtures/initial_data.json [deleted file]
bcmagic/fixtures/woldlab.json [deleted file]
experiments/test/test_sequencer.py
htsworkflow/pipelines/test/test_retrieve_config.py
samples/samples_factory.py
samples/test_samples.py

diff --git a/bcmagic/fixtures/initial_data.json b/bcmagic/fixtures/initial_data.json
deleted file mode 100644 (file)
index 99decf2..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-[{"pk": 1,
-  "model": "bcmagic.keywordmap",
-  "fields": {"regex": "(?P<uuid>[A-Fa-f0-9]+)",
-             "url_template": "/samples/freezer/{{ uuid }}/",
-             "keyword": "frzr"}},
- {"pk": 2,
-  "model": "bcmagic.keywordmap",
-  "fields": {"regex": "(?P<uuid>[A-Fa-f0-9]+)",
-             "url_template": "/samples/container/{{ uuid }}/",
-             "keyword": "cntr"}},
- {"pk": 3,
-  "model": "bcmagic.keywordmap",
-  "fields": {"regex": "(?P<sampleid>\\d+)\\|(?P<owner>[A-Za-z0-9_\\- ]+)",
-             "url_template": "/samples/sample/{{ sampleid }}/",
-             "keyword": "s"}},
- {"pk": 4,
-  "model": "bcmagic.keywordmap",
-  "fields": {"regex": "(?P<search>[\\S\\s]+)",
-             "url_template": "http://www.google.com/search?q={{ search }}",
-             "keyword": "gg"}},
- {"pk": 5,
-  "model": "bcmagic.keywordmap",
-  "fields": {"regex": "(?P<search>[\\S\\s]+)",
-             "url_template": "http://www.flickr.com/search/?q={{ search }}",
-             "keyword": "flickr"}},
- {"pk": 6,
-  "model": "bcmagic.keywordmap",
-  "fields": {"regex": "(?P<uuid>[A-Fa-f0-9]+)",
-             "url_template": "/inventory/{{ uuid }}/",
-             "keyword": "invu"}},
- {"pk": 7,
-  "model": "bcmagic.keywordmap",
-  "fields": {"regex": "(?P<barcode_id>.+)",
-             "url_template": "/inventory/{{barcode_id}}/",
-             "keyword": "invb"}}
-]
diff --git a/bcmagic/fixtures/woldlab.json b/bcmagic/fixtures/woldlab.json
deleted file mode 100644 (file)
index 51fdaa2..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-[{"pk": 1,
-  "model": "bcmagic.printer",
-  "fields": {"name": "ZM400 1.25x1",
-             "label_height": 1.0,
-             "notes": "Everyday use labels",
-             "label_width": 1.25,
-             "label_shape": "Square",
-             "model": "Zebra ZM400",
-             "ip_address": "131.215.34.116"}},
- {"pk": 2,
-  "model": "bcmagic.printer",
-  "fields": {"name": "ZM400 3x3",
-             "label_height": 3.0,
-             "notes": "Larger everyday use labels",
-             "label_width": 3.0,
-             "label_shape": "Square",
-             "model": "Zebra ZM400",
-             "ip_address": "131.215.34.117"}}]
index 6f78c4a4e7af89e95a38d602ce6e5bcc767d8d0f..0de4f5a4cdf8858e1bb05b163bff14f35f9cf1b8 100644 (file)
@@ -9,7 +9,7 @@ class SequencerTestCases(TestCase):
         # starting with no default
         s = SequencerFactory()
         s.save()
-        self.assertEqual(s.id, 1)
+        self.assertTrue(s.id)
 
         total = Sequencer.objects.filter(isdefault=True).count()
         self.assertEqual(total, 1)
index fd1c11287ce9934d12060f148728938155b7ffb8..1a24c633b82314ac40ed933a7bfb2698d27d8510 100644 (file)
@@ -10,46 +10,68 @@ except ImportError, e:
 
 from django.test import TestCase
 
+from samples.samples_factory import LibraryFactory, LibraryTypeFactory, \
+    MultiplexIndexFactory
+from experiments.experiments_factory import FlowCellFactory, LaneFactory
+
 from htsworkflow.auth import apidata
 from htsworkflow.pipelines.retrieve_config import \
      format_gerald_config, \
      getCombinedOptions, \
-     save_sample_sheet
+     save_sample_sheet, \
+     format_project_name
 
 class RetrieveTestCases(TestCase):
-    fixtures = ['initial_data.json',
-                'test_flowcells.json']
-
     def setUp(self):
         pass
 
     def test_format_gerald(self):
-        flowcell_request = self.client.get('/experiments/config/FC12150/json', apidata)
+        fc = FlowCellFactory.create(flowcell_id='FC12150')
+        library = LibraryFactory.create()
+        lane = LaneFactory(flowcell=fc, library=library, lane_number=3)
+
+        flowcell_request = self.client.get('/experiments/config/FC12150/json',
+                                           apidata)
         self.failUnlessEqual(flowcell_request.status_code, 200)
-        flowcell_info = json.loads(flowcell_request.content)
+        flowcell_info = json.loads(flowcell_request.content)['result']
 
         options = getCombinedOptions(['-f','FC12150','-g',os.getcwd()])
-        genome_map = {u'Homo sapiens': '/tmp/hg18' }
+        genome_map = {library.library_species.scientific_name: '/tmp/build' }
 
         config = format_gerald_config(options, flowcell_info, genome_map)
         config_lines = config.split('\n')
         lane3 = [ line for line in config_lines if re.search('Lane3', line) ]
         self.failUnlessEqual(len(lane3), 1)
-        self.failUnlessEqual(lane3[0], '# Lane3: SL039 | Paired ends 99 GM12892')
-        human = [ line for line in config_lines if re.search('hg18', line) ]
+        expected = '# Lane3: {} | {}'.format(library.id, library.library_name)
+        self.failUnlessEqual(lane3[0], expected)
+        human = [ line for line in config_lines if re.search('build', line) ]
         self.failUnlessEqual(len(human), 1)
-        self.failUnlessEqual(human[0], '345678:ELAND_GENOME /tmp/hg18')
-        # we changed the api to force unknown genomes to be sequencing
-        sequencing = [ line for line in config_lines if re.search('sequence_pair', line) ]
-        self.failUnlessEqual(len(sequencing), 2)
+        self.failUnlessEqual(human[0], '3:ELAND_GENOME /tmp/build')
 
 
     def test_format_sample_sheet(self):
         fcid = '42JU1AAXX'
+        fc = FlowCellFactory.create(flowcell_id=fcid)
+        library_type = LibraryTypeFactory(can_multiplex=True)
+        multiplex_index1 = MultiplexIndexFactory(adapter_type=library_type)
+        multiplex_index2 = MultiplexIndexFactory(adapter_type=library_type)
+
+        library1 = LibraryFactory.create(
+            library_type=library_type,
+            multiplex_id=multiplex_index1.multiplex_id)
+        library2 = LibraryFactory.create(
+            library_type=library_type,
+            multiplex_id=multiplex_index2.multiplex_id)
+
+        lane1l1 = LaneFactory(flowcell=fc, library=library1, lane_number=1)
+        lane1l2 = LaneFactory(flowcell=fc, library=library2, lane_number=1)
+        lane2l1 = LaneFactory(flowcell=fc, library=library1, lane_number=2)
+        lane2l2 = LaneFactory(flowcell=fc, library=library2, lane_number=2)
+
         url = '/experiments/config/%s/json' % (fcid,)
         flowcell_request = self.client.get(url, apidata)
         self.failUnlessEqual(flowcell_request.status_code, 200)
-        flowcell_info = json.loads(flowcell_request.content)
+        flowcell_info = json.loads(flowcell_request.content)['result']
 
         options = getCombinedOptions(['-f',fcid,'-g',os.getcwd(),])
 
@@ -58,26 +80,24 @@ class RetrieveTestCases(TestCase):
 
         output.seek(0)
         sheet = list(csv.DictReader(output))
-        expected = [{'SampleProject': '12044_index1',
-                     'Index': 'ATCACG',
-                     'Lane': '3',
+        name1 = library1.id + '_index' + library1.index_sequences().keys()[0]
+        name2 = library2.id + '_index' + library2.index_sequences().keys()[0]
+        expected = [{'SampleProject': name1,
+                     'Index': library1.index_sequences().values()[0],
+                     'Lane': '1',
                      },
-                    {'SampleProject': '12044_index2',
-                     'Index': 'CGATGT',
-                     'Lane': '3',
+                    {'SampleProject': name2,
+                     'Index': library2.index_sequences().values()[0],
+                     'Lane': '1',
                      },
-                    {'SampleProject': '12044_index3',
-                     'Index': 'TTAGGC',
-                     'Lane': '3',
+                    {'SampleProject': name1,
+                     'Index': library1.index_sequences().values()[0],
+                     'Lane': '2',
                      },
-                    {'SampleProject': '11045_index1',
-                     'Index': 'ATCACG',
-                     'Lane': '3',
+                    {'SampleProject': name2,
+                     'Index': library2.index_sequences().values()[0],
+                     'Lane': '2',
                      },
-                    {'SampleProject': '13044_indexN701-N501',
-                     'Index': 'TAAGGCGA-TAGATCGC',
-                     'Lane': '4',
-                     }
                     ]
         self.failUnlessEqual(len(sheet), len(expected))
         for s, e in zip(sheet, expected):
index fe0b210680a87c0708fa5d9ce4d5aabab9927b84..3dd35f5b13f6b9ac8b3467b9fe7b3bd9b57faad0 100644 (file)
@@ -76,8 +76,8 @@ class SpeciesFactory(DjangoModelFactory):
     class Meta:
         model = models.Species
 
-    scientific_name = 'test sapiens'
-    common_name = 'test human'
+    scientific_name = FuzzyText(prefix='scientific name ')
+    common_name = FuzzyText(prefix='common name ')
 
 class LibraryTypeFactory(DjangoModelFactory):
     class Meta:
index fb6d1fee93fe8b73f41adf5ef1fa9d343bc7a8f0..c339619eb0309ce9dfed96142010309891a7971f 100644 (file)
@@ -321,7 +321,7 @@ class TestRDFaLibrary(TestCase):
                                   [lib_object.library_name],
                                   p=libNS['name'])
         self.check_literal_object(model,
-                                  ['test sapiens'],
+                                  [lib_object.library_species.scientific_name],
                                   p=libNS['species_name'])