quinone / password-manager

Password management application developed as a group project for college.
0 stars 0 forks source link

TESTS test_folder_route and test_unauthenticated_route_access(client, test_path) failing #44

Closed Pitoche closed 3 months ago

Pitoche commented 3 months ago

I am struggling with these 2 tests. test_folder_route test_unauthenticated_route_access(client, test_path)

short test summary info


FAILED tests/test_folder.py::test_folder_route - assert 404 == 200
FAILED tests/test_vault.py::test_unauthenticated_route_access[check example folder] - assert 404 == 200

2 failed, 24 passed in 4.71s 

I initially though this was because we need to apply the @login_required decorator to the /vault and /folder routes in the vault.py However, I am sure I have them set

@bp.route("/")
@login_required
def vault():
    try:
        conn = get_db()
        cursor = conn.cursor()

...

@bp.route("/folder/<int:folder_id>/<string:folder_name>")
@login_required
def view_folder(folder_id, folder_name):

So, I am confused. For the vault test the purpose is """This test should redirect to /auth/login""" for anauthenticated users . I think is working as it should this is the current def

def test_unauthenticated_route_access(client, test_path):
    """This test should redirect to /auth/login"""

    response = client.get(test_path, follow_redirects=True)
    # Print response to help debug
    print("Post response status code:", response.status_code)
    print("Post response headers:", response.headers)
    print("Post response data:", response.data)
    # Status code for redirect should be 200 after redirect
    assert response.status_code == 200
    # Flash message of 'You are not logged in.'
    assert b"You are not logged in." in response.data
    assert response.request.path == "/auth/login"

The extended error is : ----------------------------------------------------------------------------------------- Captured stdout call ----------------------------------

Post response status code: 404
Post response headers: Content-Type: text/html; charset=utf-8
Content-Length: 207
Vary: Cookie
Post response data: b'<!doctype html>\n<html lang=en>\n<title>404 Not Found</title>\n<h1>Not Found</h1>\n<p>The requested URL was not found on the server. If you entered the URL manually please check yo
ur spelling and try again.</p>\n'

So, I am not sure what exactly is needed here

For the folder test, I have tried to modify this test as I ausing a differnt signature instead to go from vault to folder "/vault/FOLDER_ID/Folder_NAME/Passing Folder" This is my best guess

def test_folder_route(client, auth):
    # Simulate a login
    response = auth.login()
    with client:
        folder_name = "Passing Folder"  # Replace with the actual folder name
        with client.application.app_context():  # Ensure we are within the application context
            folder_id = get_folder_id_from_database(folder_name)  # Retrieve folder_id

        # response = client.get("/vault/FOLDER_ID/Passing Folder")
        response = client.get(f"/vault/{folder_id}/{folder_name}")
        print(response)
        assert response.status_code == 200
        assert b"Fake Name" in response.data
        assert b"Fake Username" in response.data
        assert b"asdf1234" in response.data
        assert b"www.google.com" in response.data
        assert b"note" in response.data

But, I am still getting nowhere

quinone commented 3 months ago

I think these are all fixed @Pitoche . Happy to close this?

Pitoche commented 3 months ago

Absolutelly . thanks @quinone