Exemplo n.º 1
0
    def test_all_clonotypes_view_can_be_sorted_by_copy_freq_or_norm_freq_norm_copy(self):
        sample = Sample.objects.get()

        # sort by freq ascending
        self.request.GET = {'sort': 'freq'}
        mock_response = all(self.request, sample.id)
        sorted_clonotypes = Clonotype.objects.filter(sample=sample).order_by('frequency')
        self.assertEqual(list(sorted_clonotypes),
                         list(mock_response.get('clonotypes')))

        # sort by freq descending
        self.request.GET = {'sort': 'freqd'}
        mock_response = all(self.request, sample.id)
        sorted_clonotypes = Clonotype.objects.filter(sample=sample).order_by('-frequency')
        self.assertEqual(list(sorted_clonotypes),
                         list(mock_response.get('clonotypes')))

        # sort by count ascending
        self.request.GET = {'sort': 'count'}
        mock_response = all(self.request, sample.id)
        sorted_clonotypes = Clonotype.objects.filter(sample=sample).order_by('count')
        self.assertEqual(list(sorted_clonotypes),
                         list(mock_response.get('clonotypes')))

        # sort by count descending
        self.request.GET = {'sort': 'countd'}
        mock_response = all(self.request, sample.id)
        sorted_clonotypes = Clonotype.objects.filter(sample=sample).order_by('-count')
        self.assertEqual(list(sorted_clonotypes),
                         list(mock_response.get('clonotypes')))
Exemplo n.º 2
0
 def test_clonotypes_all_view_calls_paginator_on_clonotypes(self):
     # Patch with a mock and then track the calls on the mock
     fake_sample = Sample.objects.get()
     mock = MagicMock()
     with patch('clonotypes.views.Paginator', return_value=mock):
         all(self.request, fake_sample.id)
         mock.page.assert_called_with(None)
Exemplo n.º 3
0
    def test_clonotypes_all_view_passes_clonotypes_to_template(self):
        fake_sample = Sample.objects.get()
        fake_clonotypes = Clonotype.objects.filter(sample=fake_sample)

        mock_response = all(self.request, fake_sample.id)
        clonotypes_in_context = mock_response.get('clonotypes')

        self.assertQuerysetEqual(fake_clonotypes,
                                 map(repr, clonotypes_in_context),
                                 ordered=False)
Exemplo n.º 4
0
 def test_clonotypes_all_view_returns_first_page_if_PageNotAnInteger_is_thrown(self):
     from django.core.paginator import Paginator
     fake_request = FakeRequestFactory(GET={'page': 'notAnInt'})
     fake_sample = Sample.objects.get()
     clonotypes = Clonotype.objects.filter(sample=fake_sample)
     paginator = Paginator(clonotypes, 2)
     mock_response = all(fake_request, fake_sample.id)
     self.assertQuerysetEqual(paginator.page(1).object_list,
                              map(repr,
                                  mock_response.get(
                                      'clonotypes').object_list),
                              ordered=False)
Exemplo n.º 5
0
 def test_clonotypes_all_view_passes_sample_to_template(self):
     fake_sample = Sample.objects.get()
     mock_response = all(self.request, fake_sample.id)
     sample_in_context = mock_response.get('sample')
     self.assertEqual(sample_in_context, fake_sample)
Exemplo n.º 6
0
 def test_clonotypes_all_view_uses_all_template(self):
     fake_sample = Sample.objects.get()
     mock_response = all(self.request, fake_sample.id)
     self.assertEqual(mock_response.get('template'), 'all.html')
Exemplo n.º 7
0
 def test_clonotypes_all_view_returns_paginator_object(self):
     fake_sample = Sample.objects.get()
     mock_response = all(self.request, fake_sample.id)
     self.assertEqual('Page',
                      mock_response.get('clonotypes').__class__.__name__)
Exemplo n.º 8
0
 def test_all_clonotypes_view_is_sorted_by_count_by_default(self):
     sample = Sample.objects.get()
     mock_response = all(self.request, sample.id)
     sorted_clonotypes = Clonotype.objects.filter(sample=sample).order_by('-count')
     self.assertEqual(list(sorted_clonotypes),
                      list(mock_response.get('clonotypes')))
Exemplo n.º 9
0
 def test_all_clonotypes_passes_valid_sorts_to_template(self):
     valid_sorts = ['freq', 'freqd', 'countd', 'count']
     sample = Sample.objects.get()
     mock_response = all(self.request, sample.id)
     self.assertEqual(set(valid_sorts), set(mock_response.get('valid_sorts')))
Exemplo n.º 10
0
 def test_all_clonotypes_passes_page_number_to_template(self):
     sample = Sample.objects.get()
     self.request.GET={'page': 1}
     mock_response = all(self.request, sample.id)
     self.assertEqual(1, mock_response.get('page'))