Error while doing Ticket of Paging

client = <FlaskClient <Flask 'mflix.factory'>> @pytest.mark.paging def test_supports_paging_by_text(client): filter = {'text': 'bank robbery'} (movies0, results0) = get_movies(filter, 0, 20) assert len(list(movies0)) == 20 assert results0 == 475 assert movies0[0].get('title') == 'The Bank' last_page = int(475 / 20) (movies2, results2) = get_movies(filter, last_page, 20) assert len(list(movies2)) == 15 > assert movies2[0].get('title') == "Ugetsu" E assert "Operation 'Y...'s Adventures" == 'Ugetsu' E - Operation 'Y' & Other Shurik's Adventures E + Ugetsu tests/test_paging.py:46: AssertionError

Hi @Akmal_61745

Have you reviewed the thread Bug in movies.py - paging as it appears similar to your issue? Can you investigate that thread and specifically the sorting within your code as this is definitely the first aspect to review.

Kindest regards,
Eoin

Hi @Eoin_Brazil

I am running into the same issue as the OP.

client = <FlaskClient <Flask 'mflix.factory'>>

    @pytest.mark.paging
    def test_supports_paging_by_text(client):
        filter = {'text': 'bank robbery'}
        (movies0, results0) = get_movies(filter, 0, 20)
        assert len(list(movies0)) == 20
        assert results0 == 475
        assert movies0[0].get('title') == 'The Bank'
        last_page = int(475 / 20)
        (movies2, results2) = get_movies(filter, last_page, 20)
        assert len(list(movies2)) == 15
>       assert movies2[0].get('title') == "Ugetsu"
E       assert "Operation 'Y...'s Adventures" == 'Ugetsu'
E         - Operation 'Y' & Other Shurik's Adventures
E         + Ugetsu

tests/test_paging.py:46: AssertionError

I have read through the thread Bug in movies.py - paging but the suggested fix for api/movies.py seems to be related to filters in the UI not being passed to the URL when scrolling and appears separate from the issue described where the unit test fails in v4.4 but passes in v4.2

I am using an Atlas cluster v4.4.4

I have included the complete function below:

def get_movies(filters, page, movies_per_page):
    """
    Returns a cursor to a list of movie documents.

    Based on the page number and the number of movies per page, the result may
    be skipped and limited.

    The `filters` from the API are passed to the `build_query_sort_project`
    method, which constructs a query, sort, and projection, and then that query
    is executed by this method (`get_movies`).

    Returns 2 elements in a tuple: (movies, total_num_movies)
    """

    query, sort, project = build_query_sort_project(filters)
    if project:
        cursor = db.movies.find(query, project).sort(sort)
    else:
        cursor = db.movies.find(query).sort(sort)

    total_num_movies = 0
    if page == 0:
        total_num_movies = db.movies.count_documents(query)

    """
    Ticket: Paging

    Before this method returns back to the API, use the "movies_per_page"
    argument to decide how many movies get displayed per page. The "page"
    argument will decide which page

    Paging can be implemented by using the skip() and limit() methods against
    the Pymongo cursor.
    """

    # TODO: Paging
    # Use the cursor to only return the movies that belong on the current page.
    movies = cursor.skip(movies_per_page * page).limit(movies_per_page)

    return (list(movies), total_num_movies)

After having read several other threads on this particular ticket, my understanding is that the above is the correct solution. Can you confirm this?

thank you, the error is resolved now.

Hi @Akmal_61745

Can you share how you resolved this issue as it may be of help to @Felix_Stubner?

Thanks in advance and kindest regards,
Eoin

2 Likes

Hello! I’m having this same issue. How did you end up resolving this? Thanks so much!

Hi Serissa,

I ended up creating a new thread as I wasn’t getting responses here. Please see Ticket: Paging - AssertionError for the solution.

1 Like