Created
March 27, 2025 13:59
-
-
Save jlumbroso/dd36fe4805afc8db45a91fd575cdc6ca to your computer and use it in GitHub Desktop.
Sample pytest file for https://github.com/CIS-3500/my-password-validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test_main.py | |
# for https://github.com/CIS-3500/my-password-validator | |
import pytest | |
from main import app | |
@pytest.fixture | |
def client(): | |
""" | |
Pytest fixture that creates a Flask test client from the 'app' in main.py. | |
""" | |
with app.test_client() as client: | |
yield client | |
def test_root_endpoint(client): | |
""" | |
Test the GET '/' endpoint to ensure it returns | |
the greeting and a 200 status code. | |
""" | |
resp = client.get("/") | |
assert resp.status_code == 200 | |
assert b"Hello from my Password Validator!" in resp.data | |
def test_check_password_not_implemented(client): | |
""" | |
Test the POST '/v1/checkPassword' endpoint to ensure | |
it returns HTTP 501 (Not Implemented) in the starter code. | |
""" | |
resp = client.post("/v1/checkPassword", json={"password": "whatever"}) | |
assert resp.status_code == 501 | |
data = resp.get_json() | |
assert data.get("reason") == "Not implemented" | |
assert data.get("valid") is False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment