Python: Paging: Did not receive the proper response when paging by text

What is going on? How does a student debug when http://localhost:5000/status errors like that?

After some testing i could repeatably pass and fail the status page tests, after finding weird logic in the code and fixing it.

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

My fix
total_num_movies = db.movies.count_documents(query)
My fix is to not make it conditional. Why must it be conditional on page? Physically, total_num_movies implies number of documents in query result, and should have nothing to do with which page the user is querying.

Why doesn’t catch the error
assert results0 (returned from total_num_movies) was only written for page 0 cases. For other non page 0 tests, it wasn’t asserted, so tests pass

Why are the files in a zip instead of on github where everyone can fix things like these?

Also, why does this test have 2 acceptable titles in the last assert?
Shouldn’t the output be deterministic, given a certain set of data, and a certain page, page 15’s first result should only be one of the 2 titles?
Querying it direct through the url using http://localhost:5000/api/v1/movies/search?text=bank%20robbery&page=23 i get Operation 'Y' & Other Shurik's Adventures, so why is Skippy included in the assert too?

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") == "Skippy"
        or movies2[0].get("title") == "Operation 'Y' & Other Shurik's Adventures"

Hey @Han_N_A,

Thanks for pointing this out and for suggesting fixes. We’ll surely take a look at the issues and your suggestions. :smile:

Please feel free to reach out for anything else as well.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.