test_auth.py — flask Source File
Architecture documentation for test_auth.py, a python file in the flask codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR f150d57d_79dc_267c_54f5_64b159a4b522["test_auth.py"] da94d511_b8b8_a450_f67f_fc28ea9b648a["pytest"] f150d57d_79dc_267c_54f5_64b159a4b522 --> da94d511_b8b8_a450_f67f_fc28ea9b648a 8c762fc5_c0b6_0d4d_3889_896d80fbf225["flask"] f150d57d_79dc_267c_54f5_64b159a4b522 --> 8c762fc5_c0b6_0d4d_3889_896d80fbf225 2908b311_ad9c_2dc9_c8a1_842d263dcf86["flaskr.db"] f150d57d_79dc_267c_54f5_64b159a4b522 --> 2908b311_ad9c_2dc9_c8a1_842d263dcf86 style f150d57d_79dc_267c_54f5_64b159a4b522 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import pytest
from flask import g
from flask import session
from flaskr.db import get_db
def test_register(client, app):
# test that viewing the page renders without template errors
assert client.get("/auth/register").status_code == 200
# test that successful registration redirects to the login page
response = client.post("/auth/register", data={"username": "a", "password": "a"})
assert response.headers["Location"] == "/auth/login"
# test that the user was inserted into the database
with app.app_context():
assert (
get_db().execute("SELECT * FROM user WHERE username = 'a'").fetchone()
is not None
)
@pytest.mark.parametrize(
("username", "password", "message"),
(
("", "", b"Username is required."),
("a", "", b"Password is required."),
("test", "test", b"already registered"),
),
)
def test_register_validate_input(client, username, password, message):
response = client.post(
"/auth/register", data={"username": username, "password": password}
)
assert message in response.data
def test_login(client, auth):
# test that viewing the page renders without template errors
assert client.get("/auth/login").status_code == 200
# test that successful login redirects to the index page
response = auth.login()
assert response.headers["Location"] == "/"
# login request set the user_id in the session
# check that the user is loaded from the session
with client:
client.get("/")
assert session["user_id"] == 1
assert g.user["username"] == "test"
@pytest.mark.parametrize(
("username", "password", "message"),
(("a", "test", b"Incorrect username."), ("test", "a", b"Incorrect password.")),
)
def test_login_validate_input(auth, username, password, message):
response = auth.login(username, password)
assert message in response.data
def test_logout(client, auth):
auth.login()
with client:
auth.logout()
assert "user_id" not in session
Domain
Subdomains
Functions
Dependencies
- flask
- flaskr.db
- pytest
Source
Frequently Asked Questions
What does test_auth.py do?
test_auth.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_auth.py?
test_auth.py defines 5 function(s): test_login, test_login_validate_input, test_logout, test_register, test_register_validate_input.
What does test_auth.py depend on?
test_auth.py imports 3 module(s): flask, flaskr.db, pytest.
Where is test_auth.py in the architecture?
test_auth.py is located at examples/tutorial/tests/test_auth.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