-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test_error.py for the error route
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# utility functions for testing | ||
def register_for_test(client, data): | ||
# Register | ||
response = client.post('/register', data={ | ||
'email': data['email'], | ||
'password': data['password'], | ||
'name': data['name'] | ||
}, follow_redirects=True) | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_500_page(client): | ||
response = client.get('/trigger-500') | ||
assert response.status_code == 500 | ||
assert b"500 - Internal Server Error" in response.data | ||
|
||
|
||
def test_404_page(client): | ||
response = client.get('/nonexistent') | ||
assert response.status_code == 404 | ||
assert b"Page Not Found" in response.data | ||
|
||
|
||
def test_403_page(client): | ||
# Register as an admin | ||
register_for_test(client, data={ | ||
'email': '[email protected]', | ||
'password': 'admin', | ||
'name': 'Super Admin' | ||
}) | ||
|
||
logout_response = client.get('/logout') | ||
assert logout_response.status_code == 302 | ||
|
||
# Register as a test user | ||
register_for_test(client, data={ | ||
'email': '[email protected]', | ||
'password': 'test', | ||
'name': 'Test User' | ||
}) | ||
|
||
# Log in as test user | ||
response = client.post('/login', data={ | ||
'email': '[email protected]', | ||
'password': 'test' | ||
}, follow_redirects=True) | ||
|
||
# Ensure the login was successful | ||
assert response.status_code == 200 | ||
|
||
# Move to /useful_info route, only allowed by admin | ||
response = client.get('/useful_info') | ||
|
||
# Check that the status code is 403 (forbidden) for non-admin users | ||
assert response.status_code == 403 | ||
assert b"Forbidden" in response.data | ||
|