From: Diane Trout Date: Wed, 21 Jan 2015 01:17:04 +0000 (-0800) Subject: Update test_retrieve_config to work with factories X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=92f91982844341934560f9918d167f20ae66fb59 Update test_retrieve_config to work with factories Along the way I slightly altered how the species factory worked which required tweaking test_samples. For some reason test_sequencer changed slightly. --- diff --git a/bcmagic/fixtures/initial_data.json b/bcmagic/fixtures/initial_data.json deleted file mode 100644 index 99decf2..0000000 --- a/bcmagic/fixtures/initial_data.json +++ /dev/null @@ -1,36 +0,0 @@ -[{"pk": 1, - "model": "bcmagic.keywordmap", - "fields": {"regex": "(?P[A-Fa-f0-9]+)", - "url_template": "/samples/freezer/{{ uuid }}/", - "keyword": "frzr"}}, - {"pk": 2, - "model": "bcmagic.keywordmap", - "fields": {"regex": "(?P[A-Fa-f0-9]+)", - "url_template": "/samples/container/{{ uuid }}/", - "keyword": "cntr"}}, - {"pk": 3, - "model": "bcmagic.keywordmap", - "fields": {"regex": "(?P\\d+)\\|(?P[A-Za-z0-9_\\- ]+)", - "url_template": "/samples/sample/{{ sampleid }}/", - "keyword": "s"}}, - {"pk": 4, - "model": "bcmagic.keywordmap", - "fields": {"regex": "(?P[\\S\\s]+)", - "url_template": "http://www.google.com/search?q={{ search }}", - "keyword": "gg"}}, - {"pk": 5, - "model": "bcmagic.keywordmap", - "fields": {"regex": "(?P[\\S\\s]+)", - "url_template": "http://www.flickr.com/search/?q={{ search }}", - "keyword": "flickr"}}, - {"pk": 6, - "model": "bcmagic.keywordmap", - "fields": {"regex": "(?P[A-Fa-f0-9]+)", - "url_template": "/inventory/{{ uuid }}/", - "keyword": "invu"}}, - {"pk": 7, - "model": "bcmagic.keywordmap", - "fields": {"regex": "(?P.+)", - "url_template": "/inventory/{{barcode_id}}/", - "keyword": "invb"}} -] diff --git a/bcmagic/fixtures/woldlab.json b/bcmagic/fixtures/woldlab.json deleted file mode 100644 index 51fdaa2..0000000 --- a/bcmagic/fixtures/woldlab.json +++ /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"}}] diff --git a/experiments/test/test_sequencer.py b/experiments/test/test_sequencer.py index 6f78c4a..0de4f5a 100644 --- a/experiments/test/test_sequencer.py +++ b/experiments/test/test_sequencer.py @@ -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) diff --git a/htsworkflow/pipelines/test/test_retrieve_config.py b/htsworkflow/pipelines/test/test_retrieve_config.py index fd1c112..1a24c63 100644 --- a/htsworkflow/pipelines/test/test_retrieve_config.py +++ b/htsworkflow/pipelines/test/test_retrieve_config.py @@ -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): diff --git a/samples/samples_factory.py b/samples/samples_factory.py index fe0b210..3dd35f5 100644 --- a/samples/samples_factory.py +++ b/samples/samples_factory.py @@ -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: diff --git a/samples/test_samples.py b/samples/test_samples.py index fb6d1fe..c339619 100644 --- a/samples/test_samples.py +++ b/samples/test_samples.py @@ -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'])