from the_works.models import Genre class TestUnitGenreRead: """Test view all() from genre.py.""" def test_get_request(self, client, mocker): """test GET request""" # mock database function # Note: scalars() should return 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") ]) response = client.get("/genre/", follow_redirects=True) # assert good HTTP response assert response.status_code == 200 # assert two records read assert response.data.count(b'