Home / File/ test_blog.py — flask Source File

test_blog.py — flask Source File

Architecture documentation for test_blog.py, a python file in the flask codebase. 2 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  149f981e_3440_10a6_431d_dff3407a335c["test_blog.py"]
  da94d511_b8b8_a450_f67f_fc28ea9b648a["pytest"]
  149f981e_3440_10a6_431d_dff3407a335c --> da94d511_b8b8_a450_f67f_fc28ea9b648a
  2908b311_ad9c_2dc9_c8a1_842d263dcf86["flaskr.db"]
  149f981e_3440_10a6_431d_dff3407a335c --> 2908b311_ad9c_2dc9_c8a1_842d263dcf86
  style 149f981e_3440_10a6_431d_dff3407a335c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import pytest

from flaskr.db import get_db


def test_index(client, auth):
    response = client.get("/")
    assert b"Log In" in response.data
    assert b"Register" in response.data

    auth.login()
    response = client.get("/")
    assert b"test title" in response.data
    assert b"by test on 2018-01-01" in response.data
    assert b"test\nbody" in response.data
    assert b'href="/1/update"' in response.data


@pytest.mark.parametrize("path", ("/create", "/1/update", "/1/delete"))
def test_login_required(client, path):
    response = client.post(path)
    assert response.headers["Location"] == "/auth/login"


def test_author_required(app, client, auth):
    # change the post author to another user
    with app.app_context():
        db = get_db()
        db.execute("UPDATE post SET author_id = 2 WHERE id = 1")
        db.commit()

    auth.login()
    # current user can't modify other user's post
    assert client.post("/1/update").status_code == 403
    assert client.post("/1/delete").status_code == 403
    # current user doesn't see edit link
    assert b'href="/1/update"' not in client.get("/").data


@pytest.mark.parametrize("path", ("/2/update", "/2/delete"))
def test_exists_required(client, auth, path):
    auth.login()
    assert client.post(path).status_code == 404


def test_create(client, auth, app):
    auth.login()
    assert client.get("/create").status_code == 200
    client.post("/create", data={"title": "created", "body": ""})

    with app.app_context():
        db = get_db()
        count = db.execute("SELECT COUNT(id) FROM post").fetchone()[0]
        assert count == 2


def test_update(client, auth, app):
    auth.login()
    assert client.get("/1/update").status_code == 200
    client.post("/1/update", data={"title": "updated", "body": ""})

    with app.app_context():
        db = get_db()
        post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()
        assert post["title"] == "updated"


@pytest.mark.parametrize("path", ("/create", "/1/update"))
def test_create_update_validate(client, auth, path):
    auth.login()
    response = client.post(path, data={"title": "", "body": ""})
    assert b"Title is required." in response.data


def test_delete(client, auth, app):
    auth.login()
    response = client.post("/1/delete")
    assert response.headers["Location"] == "/"

    with app.app_context():
        db = get_db()
        post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()
        assert post is None

Subdomains

Dependencies

  • flaskr.db
  • pytest

Frequently Asked Questions

What does test_blog.py do?
test_blog.py is a source file in the flask codebase, written in python. It belongs to the ApplicationCore domain, ExtensionRegistry subdomain.
What functions are defined in test_blog.py?
test_blog.py defines 8 function(s): test_author_required, test_create, test_create_update_validate, test_delete, test_exists_required, test_index, test_login_required, test_update.
What does test_blog.py depend on?
test_blog.py imports 2 module(s): flaskr.db, pytest.
Where is test_blog.py in the architecture?
test_blog.py is located at examples/tutorial/tests/test_blog.py (domain: ApplicationCore, subdomain: ExtensionRegistry, directory: examples/tutorial/tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free