def test_cached_home_page(client):
response1 = client.get("/")
assert response1.status_code == 200
# insert a tweet into the database
user = User(username="bob_ross")
user.save()
tweet = Tweet(content="happy little trees", creator=user)
tweet.save()
# check the homepage again -- it should *not* be updated,
# due to the cache
response2 = client.get("/")
assert response2.status_code == 200
assert "happy little trees" not in response2.content
# flush the cache, and the tweet should appear!
cache.clear()
response3 = client.get("/")
assert response3.status_code == 200
assert "happy little trees" in response3.content
评论列表
文章目录