Пример #1
0
    def test_get_info_text_no_search_term_single(self):
        """
            Test getting the info text without a search term for a single row on a page.

            Expected result: The search term is not included, the first row on the page is given.
        """

        self.request_context.request.args = {'page': 3}
        pagination = RolePagination(Role.query)

        text = pagination.get_info_text()
        self.assertIn(f'role {pagination.first_row} of {pagination.total_rows}', text)
        self.assertNotIn(f'matching “', text)
Пример #2
0
    def test_get_info_text_no_search_term_no_rows(self):
        """
            Test getting the info text without a search term for no rows on the page.

            Expected result: The search term is not included, the info that no rows were found is given.
        """

        # Filter the results to achieve zero rows.
        self.request_context.request.args = {'page': 1}
        pagination = RolePagination(Role.query.filter(Role.id > 42))

        text = pagination.get_info_text()
        self.assertIn('No roles', text)
        self.assertNotIn(f'matching “', text)
Пример #3
0
    def test_get_info_text_search_term_multiple(self):
        """
            Test getting the info text with a search term for multiple rows on a page.

            Expected result: The search term is included, the first and last row on the page are given.
        """

        self.request_context.request.args = {'page': 1}
        search_term = 'Aerarium'
        pagination = RolePagination(Role.query)

        text = pagination.get_info_text(search_term)
        self.assertIn(f'roles {pagination.first_row} to {pagination.last_row} of {pagination.total_rows}', text)
        self.assertIn(f'matching “{search_term}”', text)
Пример #4
0
    def test_get_info_text_no_search_term_no_rows(self):
        """
            Test getting the info text without a search term for no rows on the page.

            Expected result: The search term is not included, the info that no rows were found is given.
        """

        # Filter the results to achieve zero rows.
        self.request_context.request.args = {'page': 1}
        pagination = RolePagination(Role.query.filter(Role.id > 42))

        text = pagination.get_info_text()
        self.assertIn('No roles', text)
        self.assertNotIn('matching “', text)
Пример #5
0
    def test_get_info_text_no_search_term_single(self):
        """
            Test getting the info text without a search term for a single row on a page.

            Expected result: The search term is not included, the first row on the page is given.
        """

        self.request_context.request.args = {'page': 3}
        pagination = RolePagination(Role.query)

        text = pagination.get_info_text()
        self.assertIn(
            f'role {pagination.first_row} of {pagination.total_rows}', text)
        self.assertNotIn('matching “', text)
Пример #6
0
    def test_get_info_text_search_term_no_rows(self):
        """
            Test getting the info text with a search term for no rows on the page.

            Expected result: The search term is included, the info that no rows were found is given.
        """

        # Filter by some dummy value not related to the search term.
        self.request_context.request.args = {'page': 1}
        search_term = 'Aerarium'
        pagination = RolePagination(Role.query.filter(Role.id > 42))

        text = pagination.get_info_text(search_term)
        self.assertIn('No roles', text)
        self.assertIn(f'matching “{search_term}”', text)
Пример #7
0
    def test_get_info_text_search_term_no_rows(self):
        """
            Test getting the info text with a search term for no rows on the page.

            Expected result: The search term is included, the info that no rows were found is given.
        """

        # Filter by some dummy value not related to the search term.
        self.request_context.request.args = {'page': 1}
        search_term = 'Aerarium'
        pagination = RolePagination(Role.query.filter(Role.id > 42))

        text = pagination.get_info_text(search_term)
        self.assertIn('No roles', text)
        self.assertIn(f'matching “{search_term}”', text)
Пример #8
0
    def test_get_info_text_search_term_multiple(self):
        """
            Test getting the info text with a search term for multiple rows on a page.

            Expected result: The search term is included, the first and last row on the page are given.
        """

        self.request_context.request.args = {'page': 1}
        search_term = 'Aerarium'
        pagination = RolePagination(Role.query)

        text = pagination.get_info_text(search_term)
        self.assertIn(
            f'roles {pagination.first_row} to {pagination.last_row} of {pagination.total_rows}',
            text)
        self.assertIn(f'matching “{search_term}”', text)
Пример #9
0
def roles_list() -> ResponseType:
    """
         Show a list of all roles.

         :return: The response for this view.
    """

    # Get a search term and the resulting query. If no search term is given, all roles will by returned.
    search_form = SearchForm()
    role_query = Role.get_search_query(search_term=search_form.search_term)
    # noinspection PyProtectedMember
    pagination = RolePagination(role_query.order_by(Role._name))

    title = _('Roles')
    return render_template('administration/roles.html', title=title, pagination=pagination, search_form=search_form)