from the_works.models import Genre import pytest def test_genre_all(client, mocker): """Test view all() from genre.py.""" # mock database function # Note: The original method returns an sqlalchemy.engine.Result.ScalarResult, not a list, but the template code # uses the return value in a way that works for both ScalarResult and list # mocker.patch("the_works.database.db.session.scalars", return_value=[ mocker.patch("flask_sqlalchemy.SQLAlchemy.session.scalars", return_value=[ Genre(ID=4, Genre="bla"), Genre(ID=26, Genre="blubb") ]) # test case: get request response = client.get("/genre") assert response.status_code == 200 assert response.data.count(b'