Exemplo n.º 1
0
    def test_search_pagination(self, SQS):
        request = RequestFactory().get('/', data={'q': 'Bank', 'year': '2013'})
        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,
                                           'year': '2013'
                                       })
        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',
                                           'year': '2013'
                                       })
        results = views.search_results(request)
        self.assertEqual(results.data['page_num'], 1)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def test_search_num_loans(self, SQS):
        SQS = SQS.return_value.models.return_value.load_all.return_value.order_by.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)
Exemplo n.º 6
0
    def test_search_num_loans(self, SQS):
        SQS = SQS.return_value.models.return_value.load_all.return_value.order_by.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', 'year': '2013'})
        results = views.search_results(request)
        self.assertEqual(len(results.data['institutions']), 1)
        self.assertEqual(45, results.data['institutions'][0].num_loans)
Exemplo n.º 7
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.assertTrue(load_all.order_by.called)

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

        for sort in ('assets', '-assets', 'num_loans', '-num_loans'):
            request = RequestFactory().get('/',
                                           data={
                                               'q': 'Bank',
                                               'sort': sort,
                                               'year': '2013'
                                           })
            views.search_results(request)
            self.assertTrue(load_all.order_by.called)
Exemplo n.º 8
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)