Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than c5c8bbc point at it.

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 1why, one step back
1import pytest

Merge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697

line 2why, one step back
2

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 3–6why, one step back
3from flaskr.db import get_db
456def test_index(client, auth):

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 7why, one step back
7 response = client.get("/")

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 8–11why, one step back
8 assert b"Log In" in response.data
9 assert b"Register" in response.data1011 auth.login()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 12–15why, one step back
12 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.data

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 16–18why, one step back
16 assert b'href="/1/update"' in response.data
1718

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 19why, one step back
19@pytest.mark.parametrize("path", ("/create", "/1/update", "/1/delete"))

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 20–21why, one step back
20def test_login_required(client, path):
21 response = client.post(path)

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 22why, one step back
22 assert response.headers["Location"] == "http://localhost/auth/login"

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 23–28why, one step back
23
2425def 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 back
29 db.execute("UPDATE post SET author_id = 2 WHERE id = 1")

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 30–33why, one step back
30 db.commit()
3132 auth.login()33 # current user can't modify other user's post

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 34–35why, one step back
34 assert client.post("/1/update").status_code == 403
35 assert client.post("/1/delete").status_code == 403

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 36why, one step back
36 # current user doesn't see edit link

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 37why, one step back
37 assert b'href="/1/update"' not in client.get("/").data

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 38–39why, one step back
38
39

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 40why, one step back
40@pytest.mark.parametrize("path", ("/2/update", "/2/delete"))

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 41–47why, one step back
41def 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 back
48 assert client.get("/create").status_code == 200
49 client.post("/create", data={"title": "created", "body": ""})

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 50–52why, one step back
50
51 with app.app_context():52 db = get_db()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 53why, one step back
53 count = db.execute("SELECT COUNT(id) FROM post").fetchone()[0]

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 54–58why, one step back
54 assert count == 2
555657def test_update(client, auth, app):58 auth.login()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 59–60why, one step back
59 assert client.get("/1/update").status_code == 200
60 client.post("/1/update", data={"title": "updated", "body": ""})

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 61–63why, one step back
61
62 with app.app_context():63 db = get_db()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 64–65why, one step back
64 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()
65 assert post["title"] == "updated"

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 66–67why, one step back
66
67

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 68why, one step back
68@pytest.mark.parametrize("path", ("/create", "/1/update"))

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 69–70why, one step back
69def 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 back
71 response = client.post(path, data={"title": "", "body": ""})
72 assert b"Title is required." in response.data

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 73–76why, one step back
73
7475def test_delete(client, auth, app):76 auth.login()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 77–78why, one step back
77 response = client.post("/1/delete")
78 assert response.headers["Location"] == "http://localhost/"

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

lines 79–81why, one step back
79
80 with app.app_context():81 db = get_db()

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 82why, one step back
82 post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()

Merge pull request #3155 from zabbal/masterDavid Lordbefore adoptionc5c8bbc

line 83why, one step back
83 assert post is None