Esempio n. 1
0
 def test_all_sorting_options(self):
     """Test all_sorting_options method"""
     self.assertEqual(LoreSortingFields.all_sorting_options(), [
         LoreSortingFields.SORT_BY_NR_VIEWS,
         LoreSortingFields.SORT_BY_NR_ATTEMPTS,
         LoreSortingFields.SORT_BY_AVG_GRADE,
         LoreSortingFields.SORT_BY_TITLE,
     ])
Esempio n. 2
0
 def test_all_sorting_options(self):
     """Test all_sorting_options method"""
     self.assertEqual(
         LoreSortingFields.all_sorting_options(),
         [
             LoreSortingFields.SORT_BY_NR_VIEWS,
             LoreSortingFields.SORT_BY_NR_ATTEMPTS,
             LoreSortingFields.SORT_BY_AVG_GRADE,
             LoreSortingFields.SORT_BY_TITLE,
         ]
     )
Esempio n. 3
0
 def test_listing_with_sorting(self):
     """
     Hit the listing with sorting and test that the current sorting
     changes in the interface.
     The actual sorting of results is tested in search.tests.test_indexing
     """
     url = self.repository_url + "?sortby={0}"
     base_sorting_str = ('<button type="button" '
                         'class="btn btn-default">{0}</button>')
     # test no sort type
     body = self.assert_status_code(
         self.repository_url,
         HTTP_OK,
         return_body=True
     )
     self.assertIn(
         base_sorting_str.format(
             LoreSortingFields.get_sorting_option(
                 LoreSortingFields.DEFAULT_SORTING_FIELD
             )[1]
         ),
         body
     )
     # test all the allowed sort types
     for sort_option in LoreSortingFields.all_sorting_options():
         sort_url = url.format(sort_option[0])
         body = self.assert_status_code(
             sort_url,
             HTTP_OK,
             return_body=True
         )
         self.assertIn(
             base_sorting_str.format(sort_option[1]),
             body
         )
     # test sorting by not allowed sort type
     url_not_allowed_sort_type = url.format('foo_field')
     body = self.assert_status_code(
         url_not_allowed_sort_type,
         HTTP_OK,
         return_body=True
     )
     self.assertIn(
         base_sorting_str.format(
             LoreSortingFields.get_sorting_option(
                 LoreSortingFields.DEFAULT_SORTING_FIELD
             )[1]
         ),
         body
     )
Esempio n. 4
0
    def test_listing_with_sorting(self):
        """
        Hit the listing with sorting and test that the current sorting
        changes in the interface.
        The actual sorting of results is tested in search.tests.test_indexing
        """
        url = self.repository_url + "?sortby={0}"

        def get_sorting_options(resp):
            """Helper function to decode JSON sorting options."""
            return json.loads(resp.context['sorting_options_json'])

        # test no sort type
        resp = self.client.get(self.repository_url, follow=True)
        self.assertEqual(resp.status_code, HTTP_OK)
        self.assertEqual(
            get_sorting_options(resp)['current'],
            list(LoreSortingFields.get_sorting_option(
                LoreSortingFields.DEFAULT_SORTING_FIELD
            ))
        )
        # test all the allowed sort types
        for sort_option in LoreSortingFields.all_sorting_options():
            sort_url = url.format(sort_option[0])
            resp = self.client.get(sort_url, follow=True)
            self.assertEqual(resp.status_code, HTTP_OK)
            self.assertEqual(
                get_sorting_options(resp)['current'],
                list(sort_option)
            )
        # test sorting by not allowed sort type
        url_not_allowed_sort_type = url.format('foo_field')
        resp = self.client.get(url_not_allowed_sort_type, follow=True)
        self.assertEqual(resp.status_code, HTTP_OK)
        self.assertEqual(
            get_sorting_options(resp)['current'],
            list(LoreSortingFields.get_sorting_option(
                LoreSortingFields.DEFAULT_SORTING_FIELD
            ))
        )
Esempio n. 5
0
    def test_listing_with_sorting(self):
        """
        Hit the listing with sorting and test that the current sorting
        changes in the interface.
        The actual sorting of results is tested in search.tests.test_indexing
        """
        url = self.repository_url + "?sortby={0}"

        def get_sorting_options(resp):
            """Helper function to decode JSON sorting options."""
            return json.loads(resp.context['sorting_options_json'])

        # test no sort type
        resp = self.client.get(self.repository_url, follow=True)
        self.assertEqual(resp.status_code, HTTP_OK)
        self.assertEqual(
            get_sorting_options(resp)['current'],
            list(LoreSortingFields.get_sorting_option(
                LoreSortingFields.DEFAULT_SORTING_FIELD
            ))
        )
        # test all the allowed sort types
        for sort_option in LoreSortingFields.all_sorting_options():
            sort_url = url.format(sort_option[0])
            resp = self.client.get(sort_url, follow=True)
            self.assertEqual(resp.status_code, HTTP_OK)
            self.assertEqual(
                get_sorting_options(resp)['current'],
                list(sort_option)
            )
        # test sorting by not allowed sort type
        url_not_allowed_sort_type = url.format('foo_field')
        resp = self.client.get(url_not_allowed_sort_type, follow=True)
        self.assertEqual(resp.status_code, HTTP_OK)
        self.assertEqual(
            get_sorting_options(resp)['current'],
            list(LoreSortingFields.get_sorting_option(
                LoreSortingFields.DEFAULT_SORTING_FIELD
            ))
        )