-
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.
defined user data as constant in parameters.py
- Loading branch information
Showing
3 changed files
with
36 additions
and
30 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 |
---|---|---|
|
@@ -2,10 +2,7 @@ | |
from flask_app import create_app | ||
from flask_app.models import db, User | ||
from werkzeug.security import generate_password_hash | ||
|
||
|
||
SUPER_ADMIN_EMAIL = '[email protected]' | ||
SUPER_ADMIN_PASSWORD = 'admin' | ||
from parameters import SUPER_ADMIN_EMAIL, SUPER_ADMIN_PASSWORD, SUPER_ADMIN_NAME | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -18,8 +15,8 @@ def app(): | |
# Create a super admin user | ||
super_admin = User(email=SUPER_ADMIN_EMAIL, | ||
password=generate_password_hash(SUPER_ADMIN_PASSWORD), | ||
name='Super Admin', | ||
role='super_admin' | ||
name=SUPER_ADMIN_NAME, | ||
role='Super Admin' | ||
) | ||
db.session.add(super_admin) | ||
db.session.commit() | ||
|
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,7 @@ | ||
SUPER_ADMIN_EMAIL = '[email protected]' | ||
SUPER_ADMIN_PASSWORD = 'admin' | ||
SUPER_ADMIN_NAME = 'Super Admin' | ||
|
||
TEST_EMAIL = '[email protected]' | ||
TEST_PASSWORD = 'test' | ||
TEST_NAME = 'Test User' |
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,8 @@ | ||
from flask_app.models import User, db | ||
from werkzeug.security import generate_password_hash | ||
from parameters import TEST_NAME, TEST_EMAIL, TEST_PASSWORD | ||
|
||
|
||
def test_register_page(client): | ||
response = client.get('/register') | ||
assert response.status_code == 200 | ||
|
@@ -6,36 +11,33 @@ def test_register_page(client): | |
|
||
def test_register_form(client): | ||
response = client.post('/register', data={ | ||
'email': '[email protected]', | ||
'password': 'test', | ||
'name': 'Test User' | ||
'email': TEST_EMAIL, | ||
'password': TEST_PASSWORD, | ||
'name': TEST_NAME | ||
}) | ||
assert response.status_code == 302 # Expecting a redirect after a successful registration | ||
|
||
|
||
def test_duplicated_email_register(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 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 | ||
|
||
# Register the same user | ||
response = client.post('/register', data={ | ||
'email': '[email protected]', | ||
'password': 'test', | ||
'name': 'Test User' | ||
'email': TEST_EMAIL, | ||
'password': TEST_PASSWORD, | ||
'name': TEST_NAME | ||
}, follow_redirects=True) | ||
|
||
# Check if the application redirects from registration page to log in page with a status code 200 | ||
|
@@ -52,25 +54,25 @@ def test_login_page(client): | |
def test_login_form(client): | ||
# Register first | ||
client.post('/register', data={ | ||
'email': '[email protected]', | ||
'password': 'test', | ||
'name': 'Test User' | ||
'email': TEST_EMAIL, | ||
'password': TEST_PASSWORD, | ||
'name': TEST_NAME | ||
}) | ||
|
||
# Test for login | ||
response = client.post('/login', data={ | ||
'email': '[email protected]', | ||
'password': 'test' | ||
'email': TEST_EMAIL, | ||
'password': TEST_PASSWORD | ||
}) | ||
assert response.status_code == 302 # Expecting a redirect after a successful registration | ||
|
||
|
||
def test_logout(client): | ||
# Register | ||
register_response = client.post('/register', data={ | ||
'email': '[email protected]', | ||
'password': 'test', | ||
'name': 'Test User' | ||
'email': TEST_EMAIL, | ||
'password': TEST_PASSWORD, | ||
'name': TEST_NAME | ||
}) | ||
|
||
assert register_response.status_code == 302 # Check if registration redirects after success | ||
|
@@ -81,9 +83,9 @@ def test_logout(client): | |
|
||
# Log in | ||
login_response = client.post('/login', data={ | ||
'email': '[email protected]', | ||
'password': 'test', | ||
'name': 'Test User' | ||
'email': TEST_EMAIL, | ||
'password': TEST_PASSWORD, | ||
'name': TEST_NAME | ||
}) | ||
assert login_response.status_code == 302 # Check if login redirects after success | ||
|
||
|