test_blog.py
This file
Path
examples/tutorial/tests/test_blog.py
82 lines · 2.5 KiB · Python
Last changed by
Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
History of this fileTake it
Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 1–5why, one step back1import pytest2from flaskr.db import get_db345def test_index(client, auth):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 6why, one step back6 response = client.get("/")Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 7–10why, one step back7 assert b"Log In" in response.data8 assert b"Register" in response.data910 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 11–14why, one step back11 response = client.get("/")12 assert b"test title" in response.data13 assert b"by test on 2018-01-01" in response.data14 assert b"test\nbody" in response.dataMerge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 15–17why, one step back15 assert b'href="/1/update"' in response.data1617Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 18why, one step back18@pytest.mark.parametrize("path", ("/create", "/1/update", "/1/delete"))Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 19–20why, one step back19def test_login_required(client, path):20 response = client.post(path)Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 21why, one step back21 assert response.headers["Location"] == "http://localhost/auth/login"Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 22–27why, one step back222324def test_author_required(app, client, auth):25 # change the post author to another user26 with app.app_context():27 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 28why, one step back28 db.execute("UPDATE post SET author_id = 2 WHERE id = 1")Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 29–32why, one step back29 db.commit()3031 auth.login()32 # current user can't modify other user's postMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 33–34why, one step back33 assert client.post("/1/update").status_code == 40334 assert client.post("/1/delete").status_code == 403Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
line 35why, one step back35 # current user doesn't see edit linkMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 36why, one step back36 assert b'href="/1/update"' not in client.get("/").dataMerge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 37–38why, one step back3738Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 39why, one step back39@pytest.mark.parametrize("path", ("/2/update", "/2/delete"))Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 40–46why, one step back40def test_exists_required(client, auth, path):41 auth.login()42 assert client.post(path).status_code == 404434445def test_create(client, auth, app):46 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 47–48why, one step back47 assert client.get("/create").status_code == 20048 client.post("/create", data={"title": "created", "body": ""})Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 49–51why, one step back4950 with app.app_context():51 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 52why, one step back52 count = db.execute("SELECT COUNT(id) FROM post").fetchone()[0]Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 53–57why, one step back53 assert count == 2545556def test_update(client, auth, app):57 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 58–59why, one step back58 assert client.get("/1/update").status_code == 20059 client.post("/1/update", data={"title": "updated", "body": ""})Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 60–62why, one step back6061 with app.app_context():62 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 63–64why, one step back63 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()64 assert post["title"] == "updated"Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 65–66why, one step back6566Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 67why, one step back67@pytest.mark.parametrize("path", ("/create", "/1/update"))Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 68–69why, one step back68def test_create_update_validate(client, auth, path):69 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 70–71why, one step back70 response = client.post(path, data={"title": "", "body": ""})71 assert b"Title is required." in response.dataMerge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 72–75why, one step back727374def test_delete(client, auth, app):75 auth.login()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 76–77why, one step back76 response = client.post("/1/delete")77 assert response.headers["Location"] == "http://localhost/"Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
lines 78–80why, one step back7879 with app.app_context():80 db = get_db()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 81why, one step back81 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2
line 82why, one step back82 assert post is None