mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 09:13:45 +08:00
Added comments to test_login.py (#2035)
* Added comments to test_login.py -Added comments to each test function to provide clear documentation of the test steps. -Comments detail the purpose of each test, the actions taken, and the expected outcomes. -Improved readability and maintainability of the test suite. -No changes in functionality; only added comments for better code understanding. * Removed comments from import file in test_login.py
This commit is contained in:
parent
173ae6a221
commit
5959d40a00
1 changed files with 60 additions and 16 deletions
|
@ -6,16 +6,27 @@ from tests.utils import create_new_user
|
||||||
|
|
||||||
|
|
||||||
def test_unactivated_user_login(flask_client):
|
def test_unactivated_user_login(flask_client):
|
||||||
user = create_new_user()
|
"""
|
||||||
user.activated = False
|
Test function for logging in with an unactivated user.
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Creates a new user.
|
||||||
|
2. Sets the user's activated status to False.
|
||||||
|
3. Sends a POST request to the login route with user credentials.
|
||||||
|
4. Checks the response status code and content for expected messages.
|
||||||
|
"""
|
||||||
|
user = create_new_user() # Creating a new user
|
||||||
|
user.activated = False # Setting the user's activated status to False
|
||||||
|
Session.commit() # Committing the session changes
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with user credentials and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": user.email, "password": "password"},
|
data={"email": user.email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert (
|
assert (
|
||||||
b"Please check your inbox for the activation email. You can also have this email re-sent"
|
b"Please check your inbox for the activation email. You can also have this email re-sent"
|
||||||
|
@ -24,59 +35,92 @@ def test_unactivated_user_login(flask_client):
|
||||||
|
|
||||||
|
|
||||||
def test_non_canonical_login(flask_client):
|
def test_non_canonical_login(flask_client):
|
||||||
email = f"pre.{random_string(10)}@gmail.com"
|
"""
|
||||||
name = f"NAME-{random_string(10)}"
|
Test function for logging in with a non-canonical email.
|
||||||
user = create_new_user(email, name)
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Creates a new user with a non-canonical email.
|
||||||
|
2. Sends a POST request to the login route with user credentials.
|
||||||
|
3. Checks the response status code and content for expected messages.
|
||||||
|
4. Checks the canonicalization of the email.
|
||||||
|
5. Logs out the user.
|
||||||
|
6. Sends a POST request to the login route with the canonicalized email.
|
||||||
|
7. Checks the response status code and content for expected messages.
|
||||||
|
"""
|
||||||
|
email = f"pre.{random_string(10)}@gmail.com" # Generating a non-canonical email
|
||||||
|
name = f"NAME-{random_string(10)}" # Generating a random name
|
||||||
|
user = create_new_user(email, name) # Creating a new user with the generated email and name
|
||||||
|
Session.commit() # Committing the session changes
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with user credentials and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": user.email, "password": "password"},
|
data={"email": user.email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") in r.data
|
assert name.encode("utf-8") in r.data
|
||||||
|
|
||||||
|
# Canonicalizing the email
|
||||||
canonical_email = canonicalize_email(email)
|
canonical_email = canonicalize_email(email)
|
||||||
assert canonical_email != email
|
assert canonical_email != email # Checking if the canonical email is different from the original email
|
||||||
|
|
||||||
flask_client.get(url_for("auth.logout"))
|
flask_client.get(url_for("auth.logout")) # Logging out the user
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with the canonicalized email and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": canonical_email, "password": "password"},
|
data={"email": canonical_email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") not in r.data
|
assert name.encode("utf-8") not in r.data
|
||||||
|
|
||||||
|
|
||||||
def test_canonical_login_with_non_canonical_email(flask_client):
|
def test_canonical_login_with_non_canonical_email(flask_client):
|
||||||
suffix = f"{random_string(10)}@gmail.com"
|
"""
|
||||||
canonical_email = f"pre{suffix}"
|
Test function for logging in with a canonical email and a non-canonical email.
|
||||||
non_canonical_email = f"pre.{suffix}"
|
|
||||||
name = f"NAME-{random_string(10)}"
|
|
||||||
create_new_user(canonical_email, name)
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Generates canonical and non-canonical email addresses.
|
||||||
|
2. Creates a new user with the canonical email.
|
||||||
|
3. Sends a POST request to the login route with the non-canonical email.
|
||||||
|
4. Checks the response status code and content for expected messages.
|
||||||
|
5. Logs out the user.
|
||||||
|
6. Sends a POST request to the login route with the canonical email.
|
||||||
|
7. Checks the response status code and content for expected messages.
|
||||||
|
"""
|
||||||
|
suffix = f"{random_string(10)}@gmail.com" # Generating a random suffix for emails
|
||||||
|
canonical_email = f"pre{suffix}" # Generating a canonical email
|
||||||
|
non_canonical_email = f"pre.{suffix}" # Generating a non-canonical email
|
||||||
|
name = f"NAME-{random_string(10)}" # Generating a random name
|
||||||
|
create_new_user(canonical_email, name) # Creating a new user with the canonical email
|
||||||
|
Session.commit() # Committing the session changes
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with the non-canonical email and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": non_canonical_email, "password": "password"},
|
data={"email": non_canonical_email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") in r.data
|
assert name.encode("utf-8") in r.data
|
||||||
|
|
||||||
flask_client.get(url_for("auth.logout"))
|
flask_client.get(url_for("auth.logout")) # Logging out the user
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with the canonical email and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": canonical_email, "password": "password"},
|
data={"email": canonical_email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") in r.data
|
assert name.encode("utf-8") in r.data
|
||||||
|
|
Loading…
Reference in a new issue