test_blog.py
This file
Path
examples/tutorial/tests/test_blog.py
83 lines · 2.5 KiB · Python
Last changed by
Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
History of this fileTake it
Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
line 1why, one step back1import pytestMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
line 2why, one step back2Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 3–6why, one step back3from flaskr.db import get_db456def test_index(client, auth):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 7why, one step back7 response = client.get("/")Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 8–11why, one step back8 assert b"Log In" in response.data9 assert b"Register" in response.data1011 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 12–15why, one step back12 response = client.get("/")13 assert b"test title" in response.data14 assert b"by test on 2018-01-01" in response.data15 assert b"test\nbody" in response.dataMerge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 16–18why, one step back16 assert b'href="/1/update"' in response.data1718Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 19why, one step back19@pytest.mark.parametrize("path", ("/create", "/1/update", "/1/delete"))Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 20–21why, one step back20def test_login_required(client, path):21 response = client.post(path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 22why, one step back22 assert response.headers["Location"] == "http://localhost/auth/login"Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 23–28why, one step back232425def test_author_required(app, client, auth):26 # change the post author to another user27 with app.app_context():28 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 29why, one step back29 db.execute("UPDATE post SET author_id = 2 WHERE id = 1")Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 30–33why, one step back30 db.commit()3132 auth.login()33 # current user can't modify other user's postMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 34–35why, one step back34 assert client.post("/1/update").status_code == 40335 assert client.post("/1/delete").status_code == 403Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
line 36why, one step back36 # current user doesn't see edit linkMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 37why, one step back37 assert b'href="/1/update"' not in client.get("/").dataMerge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 38–39why, one step back3839Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 40why, one step back40@pytest.mark.parametrize("path", ("/2/update", "/2/delete"))Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 41–47why, one step back41def test_exists_required(client, auth, path):42 auth.login()43 assert client.post(path).status_code == 404444546def test_create(client, auth, app):47 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 48–49why, one step back48 assert client.get("/create").status_code == 20049 client.post("/create", data={"title": "created", "body": ""})Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 50–52why, one step back5051 with app.app_context():52 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 53why, one step back53 count = db.execute("SELECT COUNT(id) FROM post").fetchone()[0]Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 54–58why, one step back54 assert count == 2555657def test_update(client, auth, app):58 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 59–60why, one step back59 assert client.get("/1/update").status_code == 20060 client.post("/1/update", data={"title": "updated", "body": ""})Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 61–63why, one step back6162 with app.app_context():63 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 64–65why, one step back64 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()65 assert post["title"] == "updated"Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 66–67why, one step back6667Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 68why, one step back68@pytest.mark.parametrize("path", ("/create", "/1/update"))Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 69–70why, one step back69def test_create_update_validate(client, auth, path):70 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 71–72why, one step back71 response = client.post(path, data={"title": "", "body": ""})72 assert b"Title is required." in response.dataMerge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 73–76why, one step back737475def test_delete(client, auth, app):76 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 77–78why, one step back77 response = client.post("/1/delete")78 assert response.headers["Location"] == "http://localhost/"Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 79–81why, one step back7980 with app.app_context():81 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 82why, one step back82 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
line 83why, one step back83 assert post is None