Example #1
0
    def test_search_pagination(self, SQS):
        request = RequestFactory().get('/', data={'q': 'Bank'})
        results = views.search_results(request)
        # page number should default to 1
        self.assertEqual(results.data['page_num'], 1)

        request = RequestFactory().get('/', data={'q': 'Bank', 'page': 3})
        results = views.search_results(request)
        self.assertEqual(results.data['page_num'], 3)
        self.assertEqual(results.data['next_page'], 0)
        self.assertEqual(results.data['prev_page'], 2)

        request = RequestFactory().get('/', data={'q': 'Bank', 'page': 'str'})
        results = views.search_results(request)
        self.assertEqual(results.data['page_num'], 1)
Example #2
0
    def test_search_num_loans(self, SQS):
        SQS = SQS.return_value.models.return_value.load_all.return_value
        result = Mock()
        SQS.filter.return_value = [result]
        result.num_loans = 45
        result.object = Institution(name='Some Bank')

        request = RequestFactory().get('/', data={'q': 'Bank'})
        results = views.search_results(request)
        self.assertEqual(len(results.data['institutions']), 1)
        self.assertEqual(45, results.data['institutions'][0].num_loans)
Example #3
0
    def test_search_num_loans(self, SQS):
        SQS = SQS.return_value.models.return_value.load_all.return_value
        result = Mock()
        SQS.filter.return_value = [result]
        result.num_loans = 45
        result.object = Institution(name='Some Bank')

        request = RequestFactory().get('/', data={'q': 'Bank'})
        results = views.search_results(request)
        self.assertEqual(len(results.data['institutions']), 1)
        self.assertEqual(45, results.data['institutions'][0].num_loans)
Example #4
0
    def test_search_num_results(self, SQS):
        request = RequestFactory().get('/', data={'q': 'Bank'})
        results = views.search_results(request)
        # number of results should default to 25
        self.assertEqual(results.data['num_results'], 25)

        request = RequestFactory().get('/',
                                       data={
                                           'q': 'Bank',
                                           'num_results': 10
                                       })
        results = views.search_results(request)
        self.assertEqual(results.data['num_results'], 10)

        request = RequestFactory().get('/',
                                       data={
                                           'q': 'Bank',
                                           'num_results': 'str'
                                       })
        results = views.search_results(request)
        self.assertEqual(results.data['num_results'], 25)
Example #5
0
    def test_search_sort(self, SQS):
        load_all = SQS.return_value.models.return_value.load_all.return_value

        request = RequestFactory().get('/', data={'q': 'Bank'})
        views.search_results(request)
        self.assertFalse(load_all.order_by.called)

        request = RequestFactory().get('/', data={'q': 'Bank',
                                                  'sort': 'another-sort'})
        views.search_results(request)
        self.assertFalse(load_all.order_by.called)

        for sort in ('assets', '-assets', 'num_loans', '-num_loans'):
            request = RequestFactory().get('/', data={'q': 'Bank',
                                                      'sort': sort})
            views.search_results(request)
            self.assertTrue(load_all.order_by.called)
Example #6
0
    def test_search_sort(self, SQS):
        load_all = SQS.return_value.models.return_value.load_all.return_value

        request = RequestFactory().get('/', data={'q': 'Bank'})
        views.search_results(request)
        self.assertFalse(load_all.order_by.called)

        request = RequestFactory().get('/',
                                       data={
                                           'q': 'Bank',
                                           'sort': 'another-sort'
                                       })
        views.search_results(request)
        self.assertFalse(load_all.order_by.called)

        for sort in ('assets', '-assets', 'num_loans', '-num_loans'):
            request = RequestFactory().get('/',
                                           data={
                                               'q': 'Bank',
                                               'sort': sort
                                           })
            views.search_results(request)
            self.assertTrue(load_all.order_by.called)