diff --git a/test_pytest/test_database.py b/test_pytest/test_database.py index 837a163..eb23a21 100644 --- a/test_pytest/test_database.py +++ b/test_pytest/test_database.py @@ -1,5 +1,4 @@ ### testing database via Pytests - from website.models import User from website import db from main import app @@ -33,29 +32,29 @@ def test_database_duplicate_usernames(): def test_non_existing_username_in_db(): with app.app_context(): non_existing_username = 'thisisanonexistentuser' - users_with_username = User.query.filter_by(username=non_existing_username) - assert len(users_with_username) == 0 + users_with_username = User.query.filter_by(username=non_existing_username).first() + assert users_with_username == None def test_incorrect_password_in_db(): with app.app_context(): username='Testing' incorrect_password = 'thisisanincorrectpassword' - users_with_password = User.query.filter_by(username=username) - assert check_password_hash(users_with_password.password, incorrect_password) == False + user = User.query.filter_by(username=username).first() + assert check_password_hash(user.password, incorrect_password) == False # Check for values existing in database def test_existing_username(): with app.app_context(): existing_username = 'Testing' - existing_user = User.query.filter_by(username=existing_username) + existing_user = User.query.filter_by(username=existing_username).first() assert existing_user def test_correct_password(): with app.app_context(): username='Testing' correct_password = 'testing' - user = User.query.filter_by(username=username) + user = User.query.filter_by(username=username).first() password_matched = check_password_hash(user.password, correct_password) assert password_matched @@ -63,7 +62,7 @@ def test_correct_password(): def test_retrieve_password_by_username(): with app.app_context(): existing_username = 'Testing' - user = User.query.filter_by(username=existing_username) + user = User.query.filter_by(username=existing_username).first() retrieved_password = user.password assert retrieved_password @@ -72,6 +71,18 @@ def test_retrieve_username_and_password_by_id(): existing_user_id = 3 user = User.query.get(existing_user_id) retrieved_username = user.username - retrieved_password = user.password - assert retrieved_username and retrieved_password + assert retrieved_username + + +# Inserting new values into database +def test_insert_new_user(): + with app.app_context(): + new_username = 'testing5' + new_password = 'testing5' + new_user_role = 'user' + new_user = User(username=new_username, password=new_password, role=new_user_role) + db.session.add(new_user) + db.session.commit() + inserted_user = User.query.filter_by(username=new_username).first() + assert (inserted_user.username == new_username) and (inserted_user.password == new_password) \ No newline at end of file diff --git a/test_robotFramework/login_account.robot b/test_robotFramework/login_account.robot index 93e9bb0..420768a 100644 --- a/test_robotFramework/login_account.robot +++ b/test_robotFramework/login_account.robot @@ -6,8 +6,8 @@ Library SeleniumLibrary ${website_url} http://127.0.0.1:5000 ${login_admin_username} Admin ${login_admin_password} password -${login_user_username} Testing9 -${login_user_password} Testing9 +${login_user_username} test8 +${login_user_password} test8 ${login_btn} xpath=//button[contains(text(),'Login')] ${login_anchor} xpath=//a[contains(text(),'Login')] ${logout_btn} xpath=//a[contains(text(),'Logout')]