示例#1
0
def filter(course_id=None):
    """
    Display a filtered and paginated list of students in the course.

    :param course_id:
    :type: int
    :rtype: str
    :returns: A list of students in the course using the template
        user_list.html.
    """

    query = request.args.get('query', '').lower()
    page = int(request.args.get('page', 1))
    per_page = int(request.args.get('per_page', config.DEFAULT_PER_PAGE))

    user_list, max_pages = search_students(
        course_id,
        per_page=per_page,
        page=page,
        search_term=query
    )

    if not user_list or max_pages < 1:
        user_list = []
        max_pages = 1

    return render_template(
        'user_list.html',
        users=user_list,
        current_page_number=page,
        max_pages=max_pages
    )
示例#2
0
    def test_search_students(self, m):
        from utils import search_students

        m.register_uri(
            'GET',
            '/api/v1/courses/1/search_users',
            json=[{
                'id': 1,
                'name': 'John Smith'
            }, {
                'id': 2,
                'name': 'Jane Doe'
            }],
            headers={
                "Link":
                "<http://example.com/api/v1/courses/1/search_users?page=99>; rel=\"last\""
            })

        response = search_students(1)

        self.assertIsInstance(response, tuple)

        self.assertIsInstance(response[0], list)
        self.assertEqual(len(response[0]), 2)

        self.assertIsInstance(response[1], int)
        self.assertEqual(response[1], 99)
示例#3
0
    def test_search_students_malformed_response(self, m):
        from utils import search_students

        m.register_uri(
            'GET',
            '/api/v1/courses/1/search_users',
        )
        response = search_students(1)

        self.assertIsInstance(response, tuple)

        self.assertIsInstance(response[0], list)
        self.assertEqual(len(response[0]), 0)

        self.assertIsInstance(response[1], int)
        self.assertEqual(response[1], 0)
示例#4
0
    def test_search_students_no_last_link(self, m):
        from utils import search_students

        m.register_uri(
            'GET',
            '/api/v1/courses/1/search_users',
            json=[{'id': 1, 'name': 'John Smith'}],
        )

        response = search_students(1)

        self.assertIsInstance(response, tuple)

        self.assertIsInstance(response[0], list)
        self.assertEqual(len(response[0]), 1)

        self.assertIsInstance(response[1], int)
        self.assertEqual(response[1], 0)
示例#5
0
    def test_search_students_error(self, m):
        from utils import search_students

        m.register_uri(
            'GET',
            '/api/v1/courses/1/search_users',
            json={"errors": {"message": "An error occurred."}}
        )

        response = search_students(1)

        self.assertIsInstance(response, tuple)

        self.assertIsInstance(response[0], list)
        self.assertEqual(len(response[0]), 0)

        self.assertIsInstance(response[1], int)
        self.assertEqual(response[1], 0)