-
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 tmp test functions to check how they work
- Loading branch information
Showing
1 changed file
with
106 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
from flask_app.models import User, db | ||
from werkzeug.security import generate_password_hash | ||
from parameters import TEST_NAME, TEST_EMAIL, TEST_PASSWORD, SUPER_ADMIN_EMAIL, SUPER_ADMIN_PASSWORD | ||
|
||
|
||
def test_check_super_admin_exist(client): | ||
# Verify the super admin exists in the database | ||
super_admin_user = User.query.filter_by(email=SUPER_ADMIN_EMAIL).first() | ||
assert super_admin_user is not None | ||
assert super_admin_user.role == 'Super Admin' | ||
|
||
|
||
def test_admin_dashboard_access(super_admin_client): | ||
response = super_admin_client.get('/admin-dashboard') | ||
assert response.status_code == 200 # Check if registration redirects after success | ||
|
@@ -6,19 +18,17 @@ def test_admin_dashboard_access(super_admin_client): | |
|
||
def test_change_user_role(super_admin_client): | ||
# Create a new user manually for testing | ||
from flask_app.models import User, db | ||
from werkzeug.security import generate_password_hash | ||
new_user = User(name='Test User', | ||
email='[email protected]', | ||
password=generate_password_hash('test') | ||
new_user = User(name=TEST_NAME, | ||
email=TEST_EMAIL, | ||
password=generate_password_hash(TEST_PASSWORD) | ||
) | ||
|
||
with super_admin_client.application.app_context(): | ||
db.session.add(new_user) | ||
db.session.commit() | ||
|
||
# Verify the user exists in the database | ||
user = User.query.filter_by(email='[email protected]').first() | ||
user = User.query.filter_by(email=TEST_EMAIL).first() | ||
assert user is not None | ||
assert user.role == 'user' | ||
|
||
|
@@ -33,24 +43,108 @@ def test_change_user_role(super_admin_client): | |
|
||
def test_delete_user(super_admin_client): | ||
# Create a new user manually for testing | ||
from flask_app.models import User, db | ||
new_user = User(name='Test User', | ||
email='[email protected]', | ||
password='test' | ||
new_user = User(name=TEST_NAME, | ||
email=TEST_EMAIL, | ||
password=generate_password_hash(TEST_PASSWORD) | ||
) | ||
|
||
with super_admin_client.application.app_context(): | ||
db.session.add(new_user) | ||
db.session.commit() | ||
|
||
# Verify the user exists in the database | ||
user = User.query.filter_by(email='[email protected]').first() | ||
user = User.query.filter_by(email=TEST_EMAIL).first() | ||
assert user is not None | ||
|
||
# Super admin changes the role of the new user | ||
response = super_admin_client.post(f'/admin/delete-user/{user.id}') | ||
assert response.status_code == 302 | ||
|
||
# Verify the user exists in the database | ||
user = User.query.filter_by(email='[email protected]').first() | ||
user = User.query.filter_by(email=TEST_EMAIL).first() | ||
assert user is None | ||
|
||
|
||
# temp test codes using client | ||
def test_admin_dashboard_access_tmp(client): | ||
# log in as super admin user | ||
login_response = client.post('/login', data={ | ||
'email': SUPER_ADMIN_EMAIL, | ||
'password': SUPER_ADMIN_PASSWORD | ||
}) | ||
assert login_response.status_code == 302 # Expecting a redirect after a successful registration | ||
|
||
response = client.get('/admin-dashboard') | ||
assert response.status_code == 200 # Check if registration redirects after success | ||
assert b'Admin Dashboard' in response.data | ||
|
||
|
||
def test_change_user_role_tmp(client): | ||
# Create a new user manually for testing | ||
new_user = User(name=TEST_NAME, | ||
email=TEST_EMAIL, | ||
password=generate_password_hash(TEST_PASSWORD) | ||
) | ||
|
||
with client.application.app_context(): | ||
db.session.add(new_user) | ||
db.session.commit() | ||
|
||
# Verify the registered user exists in the database | ||
user = User.query.filter_by(email=TEST_EMAIL).first() | ||
assert user is not None | ||
assert user.role == 'user' | ||
|
||
# log in as super admin user | ||
login_response = client.post('/login', data={ | ||
'email': SUPER_ADMIN_EMAIL, | ||
'password': SUPER_ADMIN_PASSWORD | ||
}) | ||
assert login_response.status_code == 302 # Expecting a redirect after a successful registration | ||
|
||
response = client.get('/admin-dashboard') | ||
assert response.status_code == 200 # Check if registration redirects after success | ||
assert b'Admin Dashboard' in response.data | ||
|
||
# Super admin changes the role of the new user | ||
response = client.post(f'/admin/change-role/{user.id}') | ||
assert response.status_code == 302 | ||
|
||
# Verify the role has been changed | ||
user = db.session.get(User, user.id) | ||
assert user.role == 'admin' | ||
|
||
|
||
def test_delete_user_tmp(client): | ||
# Create a new user manually for testing | ||
new_user = User(name='Test User', | ||
email=TEST_EMAIL, | ||
password=generate_password_hash(TEST_PASSWORD) | ||
) | ||
|
||
with client.application.app_context(): | ||
db.session.add(new_user) | ||
db.session.commit() | ||
|
||
# Verify the user exists in the database | ||
user = User.query.filter_by(email=TEST_EMAIL).first() | ||
assert user is not None | ||
|
||
# log in as super admin user | ||
login_response = client.post('/login', data={ | ||
'email': SUPER_ADMIN_EMAIL, | ||
'password': SUPER_ADMIN_PASSWORD | ||
}) | ||
assert login_response.status_code == 302 # Expecting a redirect after a successful registration | ||
|
||
response = client.get('/admin-dashboard') | ||
assert response.status_code == 200 # Check if registration redirects after success | ||
assert b'Admin Dashboard' in response.data | ||
|
||
# Super admin changes the role of the new user | ||
response = client.post(f'/admin/delete-user/{user.id}') | ||
assert response.status_code == 302 | ||
|
||
# Verify the user exists in the database | ||
user = User.query.filter_by(email=TEST_EMAIL).first() | ||
assert user is None |