def test_search_filter_with_analysis_id(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) pixel_set = models.PixelSet.objects.all()[4] analysis_id = pixel_set.analysis.id # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=8) data = { # search by short uuid 'search': str(analysis_id.hex[:7]) } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1) self.assertContains( response, ('<td class="filename">' '<a' f' href="{pixel_set.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(pixel_set.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, )
def test_species_filter(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) # Create our special ones species = factories.SpeciesFactory() strain = factories.StrainFactory(species=species) n_new_pixel_sets = 2 pixel_sets = factories.PixelSetFactory.create_batch(n_new_pixel_sets) omics_units = factories.OmicsUnitFactory.create_batch(n_new_pixel_sets, strain=strain) for omics_unit, pixel_set in zip(omics_units, pixel_sets): factories.PixelFactory( omics_unit=omics_unit, pixel_set=pixel_set, ) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=10) # species filter data = { 'species': [ species.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=n_new_pixel_sets)
def test_filters_with_no_match(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) # Create a new species species = factories.SpeciesFactory() # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=8) # filter with no possible result data = { 'species': [ species.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=0) self.assertContains( response, ('<td colspan="8" class="empty">' 'No Pixel Set matches your query' '</td>'), count=1, html=True, )
def test_search_filter_with_omics_unit_reference(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) pixel_set = models.PixelSet.objects.all()[4] reference = pixel_set.pixels.get().omics_unit.reference.identifier # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=8) # filter with Omics Unit reference identifier search data = {'search': reference} response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1) self.assertContains( response, ('<td class="filename">' '<a' f' href="{pixel_set.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(pixel_set.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, )
def test_omics_unit_types_filter(self): # We generate one pixel per pixelset so that half of Pixel Sets # contains pixels with 'mRNA' omics unit type and the other half # 'protein' omics unit type n_pixel_sets = 8 make_development_fixtures(n_pixel_sets=n_pixel_sets, n_pixels_per_set=1) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=n_pixel_sets) # omics_unit_types filter omics_unit_type = models.OmicsUnitType.objects.first() data = { 'omics_unit_types': [ omics_unit_type.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=(n_pixel_sets // 2))
def test_unexpected_filter_value(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=8) self.assertNotContains( response, '<small class="error">\'fakeid\' is not a valid UUID.</small>', html=True, ) # odd filter query data = { 'species': [ 'fakeid', ], } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=8) self.assertContains( response, ('<small class="error">' ''fakeid' is not a valid UUID.' '</small>'), html=True, )
def test_renders_pixelset_list(self): make_development_fixtures(n_pixel_sets=12) response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=10) self.assertContains( response, '<button type="submit" class="button">', )
def test_all_filters(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) # Create a special Pixel Set which will match all filters species = factories.SpeciesFactory() strain = factories.StrainFactory(species=species) omics_unit_type = factories.OmicsUnitTypeFactory() omics_unit = factories.OmicsUnitFactory( strain=strain, type=omics_unit_type, ) omics_area = factories.OmicsAreaFactory() experiment = factories.ExperimentFactory(omics_area=omics_area) experiment_tag = 'candida' experiment.tags = experiment_tag experiment.save() analysis = factories.AnalysisFactory(experiments=[ experiment, ]) pixel_set = factories.PixelSetFactory(analysis=analysis) factories.PixelFactory( omics_unit=omics_unit, pixel_set=pixel_set, ) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=9) # all filters tag = models.Tag.objects.get(name=experiment_tag) data = { 'species': [ species.id, ], 'omics_unit_types': [ omics_unit_type.id, ], 'omics_area': [ omics_area.id, ], 'tags': [ tag.id, ], } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1)
def test_tags_filter(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) omics_area = factories.OmicsAreaFactory() experiment = factories.ExperimentFactory(omics_area=omics_area) experiment_tag = 'candida' experiment.tags = experiment_tag experiment.save() analysis = factories.AnalysisFactory(experiments=[ experiment, ]) analysis_tag = 'msms/time' analysis.tags = analysis_tag analysis.save() factories.PixelSetFactory(analysis=analysis) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=9) # tags filter tag = models.Tag.objects.get(name=experiment_tag) data = { 'tags': [ tag.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1) tag = models.Tag.objects.get(name=analysis_tag) data = { 'tags': [ tag.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1)
def test_search_is_case_insensitive(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) first_pixel_set = models.PixelSet.objects.all().first() second_pixel_set = models.PixelSet.objects.all().last() # Add custom descriptions written in Klingon so that we are pretty # sure nothing will match our query 🤓 # # Lorem ipsum source: # http://shooshee.tumblr.com/post/212964026/klingon-lorem-ipsum first_analysis = factories.AnalysisFactory(description=( 'Qapla. Dah tlhingan hol mu ghom a dalegh. Qawhaqvam ' 'chenmohlu di wiqipe diya ohvad ponglu. Ach jinmolvamvad ' 'Saghbe law tlhingan hol, dis, oh mevmohlu.')) first_pixel_set.analysis = first_analysis first_pixel_set.save() experiment = factories.ExperimentFactory(description=( 'Qapla. Dah tlhingan hol mu ghom a dalegh. Qawhaqvam ' 'chenmohlu di wiqipe diya ohvad ponglu. Ach jinmolvamvad ' 'Saghbe law tlhingan hol, dis, oh mevmohlu.')) second_analysis = factories.AnalysisFactory(experiments=[ experiment, ]) second_pixel_set.analysis = second_analysis second_pixel_set.save() # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=8) # filter with keyword search data = {'search': 'JINMOLVAMVAD'} response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=2)
def test_renders_completion_dates(self): make_development_fixtures(n_pixel_sets=1) response = self.client.get(self.url) expected = ('<span class="completed-at">' 'Completion date: {}' '</span>') pixelset = models.PixelSet.objects.get() self.assertContains(response, expected.format( date_filter(pixelset.analysis.completed_at)), count=1, html=True) self.assertContains( response, expected.format( date_filter(pixelset.analysis.experiments.get().completed_at)), count=1, html=True)
def test_omics_areas_filter(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) omics_area = factories.OmicsAreaFactory() experiment = factories.ExperimentFactory(omics_area=omics_area) analysis = factories.AnalysisFactory(experiments=[ experiment, ]) factories.PixelSetFactory(analysis=analysis) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=9) # omics_areas filter data = { 'omics_areas': [ omics_area.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1)
def test_search_filter_with_keywords(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) first_pixel_set = models.PixelSet.objects.all().first() second_pixel_set = models.PixelSet.objects.all().last() # Add custom descriptions written in Klingon so that we are pretty # sure nothing will match our query 🤓 # # Lorem ipsum source: # http://shooshee.tumblr.com/post/212964026/klingon-lorem-ipsum first_analysis = factories.AnalysisFactory(description=( 'Qapla. Dah tlhingan hol mu ghom a dalegh. Qawhaqvam ' 'chenmohlu di wiqipe diya ohvad ponglu. Ach jinmolvamvad ' 'Saghbe law tlhingan hol, dis, oh mevmohlu.')) first_pixel_set.analysis = first_analysis first_pixel_set.save() experiment = factories.ExperimentFactory(description=( 'Qapla. Dah tlhingan hol mu ghom a dalegh. Qawhaqvam ' 'chenmohlu di wiqipe diya ohvad ponglu. Ach jinmolvamvad ' 'Saghbe law tlhingan hol, dis, oh mevmohlu.')) second_analysis = factories.AnalysisFactory(experiments=[ experiment, ]) second_pixel_set.analysis = second_analysis second_pixel_set.save() # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=8) # filter with keyword search data = {'search': 'jinmolvamvad'} response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=2) self.assertContains( response, ('<td class="filename">' '<a' f' href="{first_pixel_set.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(first_pixel_set.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, ) self.assertContains( response, ('<td class="filename">' '<a' f' href="{second_pixel_set.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(second_pixel_set.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, )
def test_tags_tree_filter(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) # Create two pixelsets with tags omics_area = factories.OmicsAreaFactory() experiment = factories.ExperimentFactory(omics_area=omics_area) first_analysis = factories.AnalysisFactory(experiments=[ experiment, ]) first_analysis_tags = 'candida/glabrata/cbs138' first_analysis.tags = first_analysis_tags first_analysis.save() first_pixelset = factories.PixelSetFactory(analysis=first_analysis) second_analysis = factories.AnalysisFactory(experiments=[ experiment, ]) second_analysis_tags = 'candida' second_analysis.tags = second_analysis_tags second_analysis.save() second_pixelset = factories.PixelSetFactory(analysis=second_analysis) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=10) # tags filter tag = models.Tag.objects.get(name=first_analysis_tags) data = { 'tags': [ tag.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1) self.assertContains( response, ('<td class="filename">' '<a' f' href="{first_pixelset.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(first_pixelset.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, ) tag = models.Tag.objects.get(name=second_analysis_tags) data = { 'tags': [ tag.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=2) self.assertContains( response, ('<td class="filename">' '<a' f' href="{first_pixelset.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(first_pixelset.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, ) self.assertContains( response, ('<td class="filename">' '<a' f' href="{second_pixelset.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(second_pixelset.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, )
def test_omics_areas_tree_filter(self): # Create 8 pixelset make_development_fixtures(n_pixel_sets=8, n_pixels_per_set=1) # Create a parent omics area and link it to a Pixel Set parent_omics_area = factories.OmicsAreaFactory() first_experiment = factories.ExperimentFactory( omics_area=parent_omics_area) first_analysis = factories.AnalysisFactory(experiments=[ first_experiment, ]) first_pixelset = factories.PixelSetFactory(analysis=first_analysis) # Create a child omics are and link it to a Pixel Set child_omics_area = factories.OmicsAreaFactory(parent=parent_omics_area) second_experiment = factories.ExperimentFactory( omics_area=child_omics_area) second_analysis = factories.AnalysisFactory(experiments=[ second_experiment, ]) second_pixelset = factories.PixelSetFactory(analysis=second_analysis) # no filter response = self.client.get(self.url) self.assertContains(response, '<tr class="pixelset">', count=10) # omics_areas filter data = { 'omics_areas': [ child_omics_area.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=1) self.assertContains( response, ('<td class="filename">' '<a' f' href="{second_pixelset.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(second_pixelset.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, ) data = { 'omics_areas': [ parent_omics_area.id, ] } response = self.client.get(self.url, data) self.assertContains(response, '<tr class="pixelset">', count=2) self.assertContains( response, ('<td class="filename">' '<a' f' href="{first_pixelset.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(first_pixelset.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, ) self.assertContains( response, ('<td class="filename">' '<a' f' href="{second_pixelset.get_absolute_url()}"' ' title="More information about this Pixel Set"' '>' '<!-- Pixel Set file name -->' f'{filename(second_pixelset.pixels_file.name)}' '</a>' '</td>'), count=1, html=True, )