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