-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
195 additions
and
81 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
Binary file not shown.
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,31 @@ | ||
============================= test session starts ============================== | ||
platform darwin -- Python 3.10.5, pytest-7.1.3, pluggy-1.0.0 | ||
rootdir: /Users/adenkrakman/Desktop/course-project-group-5/src/backend | ||
plugins: cov-4.0.0 | ||
collected 47 items | ||
|
||
tests/test_app.py .................. [ 38%] | ||
tests/test_decorators.py . [ 40%] | ||
tests/test_login.py ........ [ 57%] | ||
tests/test_mainpage.py .............. [ 87%] | ||
tests/test_userpage.py ...... [100%] | ||
|
||
- generated xml file: /Users/adenkrakman/Desktop/course-project-group-5/src/backend/pytest.xml - | ||
|
||
---------- coverage: platform darwin, python 3.10.5-final-0 ---------- | ||
Name Stmts Miss Cover Missing | ||
----------------------------------------------------------- | ||
app.py 132 0 100% | ||
config.py 1 0 100% | ||
dataholders/apt.py 9 0 100% | ||
dataholders/mainpage_get.py 15 0 100% | ||
dataholders/review.py 7 0 100% | ||
dataholders/user.py 8 0 100% | ||
decorators.py 27 0 100% | ||
pages/login.py 37 0 100% | ||
pages/mainpage.py 100 0 100% | ||
pages/userpage.py 54 0 100% | ||
----------------------------------------------------------- | ||
TOTAL 390 0 100% | ||
|
||
============================== 47 passed in 0.32s ============================== |
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
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 |
---|---|---|
|
@@ -25,10 +25,10 @@ def insert_apartments(self, cursor: sqlite3.Cursor, connection: sqlite3.Connecti | |
def insert_users(self, cursor: sqlite3.Cursor, connection: sqlite3.Connection): | ||
"""Initialize users for use by test methods""" | ||
args = [ | ||
("Minh Phan", "", "", ""), | ||
("Minh", "", "", ""), | ||
("Big_finger", "", "", ""), | ||
("Fig_binger", "", "", ""), | ||
("Minh Phan", "phan_password1", "[email protected]", "111-111-1111"), | ||
("Minh", "minh_password1", "[email protected]", "222-222-2222"), | ||
("Big_finger", "big_password1", "[email protected]", "333-333-3333"), | ||
("Fig_binger", "fig_password1", "[email protected]", "444-444-4444"), | ||
] | ||
cursor.executemany( | ||
"INSERT INTO Users (username, password, email, phone) \ | ||
|
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,60 +1,140 @@ | ||
"""Test userpage.py""" | ||
import sqlite3 | ||
from decorators import use_test | ||
from decorators import use_test, use_database | ||
from tests.mainpage_staging import MainPageStaging | ||
from pages.userpage import UserPage | ||
from pages.login import validate_phone | ||
from dataholders.apt import Apt | ||
|
||
|
||
class TestUserPage: | ||
"""Test user page class""" | ||
|
||
username = "test_username" | ||
alt_username = "alt_username" | ||
userpage = UserPage(username) | ||
phone = "012-345-6789" | ||
invalid_phone = "123-3421-322" | ||
password = "newpassword1234" | ||
invalid_password = "inv2341" | ||
email = "[email protected]" | ||
invalid_email = "testemail@" | ||
userpage = None | ||
main_page_staging = MainPageStaging() | ||
|
||
@use_test | ||
def test_valid_phone(self) -> bool: | ||
"""Test update_phone returns True and db entry is the same""" | ||
assert validate_phone(self.phone) is True | ||
assert self.userpage.update_phone(self.phone) is True | ||
@use_database | ||
def initialize(self): | ||
"""Set up tests by inserting a user into the db""" | ||
connection = self.initialize.connection | ||
cursor = self.initialize.cursor | ||
self.insert_users(cursor, connection) | ||
self.userpage = UserPage(self.username) | ||
|
||
# mimics update_phone | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor() | ||
cursor.execute( | ||
"INSERT INTO Users (username, email, password, phone) \ | ||
VALUES (?, ?, ?, ?)", | ||
(self.alt_username, "[email protected]", "password", "011-899-9013"), | ||
) | ||
connection.commit() | ||
def insert_users(self, cursor: sqlite3.Cursor, connection: sqlite3.Connection): | ||
"""Initialize users for testing""" | ||
cursor.execute( | ||
"UPDATE Users SET phone = ? WHERE (username = ?)", | ||
"INSERT INTO Users (username, password, email, phone) \ | ||
VALUES (?, ?, ?, ?)", | ||
( | ||
self.phone, | ||
self.alt_username, | ||
self.username, | ||
"beginpassword", | ||
"[email protected]", | ||
"111-555-0022", | ||
), | ||
) | ||
connection.commit() | ||
|
||
@use_test | ||
def test_get_user(self): | ||
"""get_user returns correct Use""" | ||
self.initialize() | ||
res = self.userpage.get_user(self.username) | ||
assert res.username == self.username | ||
assert res.password == "beginpassword" | ||
assert res.email == "[email protected]" | ||
assert res.phone == "111-555-0022" | ||
assert self.userpage.get_user("sd") is None | ||
|
||
@use_test | ||
def test_valid_password(self): | ||
"""update_password returns True and db entry is correct""" | ||
self.initialize() | ||
res = self.userpage.update_password(self.password) | ||
assert res is True | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor() | ||
test_result = cursor.execute( | ||
"SELECT phone FROM Users WHERE (username = ?)", (self.alt_username,) | ||
"SELECT password FROM Users WHERE (username = ?)", (self.username,) | ||
).fetchone()[0] | ||
connection.close() | ||
same_password = self.userpage.update_password(self.password) | ||
assert same_password is True | ||
self.cleanup_db() | ||
assert test_result == self.phone | ||
assert test_result == self.password | ||
|
||
@use_test | ||
def test_invalid_phone(self) -> bool: | ||
"""Test update_phone returns False""" | ||
assert validate_phone(self.invalid_phone) is False | ||
def test_valid_email(self): | ||
"""update_email returns True and db entry is correct""" | ||
self.initialize() | ||
res = self.userpage.update_email(self.email) | ||
assert res is True | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor() | ||
test_result = cursor.execute( | ||
"SELECT email FROM Users WHERE (username = ?)", (self.username,) | ||
).fetchone()[0] | ||
connection.close() | ||
same_email = self.userpage.update_email(self.email) | ||
assert same_email is True | ||
self.cleanup_db() | ||
assert test_result == self.email | ||
|
||
@use_test | ||
def test_invalid_input(self): | ||
"""invalid input returns False""" | ||
self.initialize() | ||
assert self.userpage.update_password(self.invalid_password) is False | ||
assert self.userpage.update_email(self.invalid_email) is False | ||
assert self.userpage.update_phone(self.invalid_phone) is False | ||
|
||
@use_test | ||
def cleanup_db(self) -> None: | ||
def test_valid_phone(self): | ||
"""update_phone returns True and db entry is correct""" | ||
self.initialize() | ||
res = self.userpage.update_phone(self.phone) | ||
assert res is True | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor() | ||
test_result = cursor.execute( | ||
"SELECT phone FROM Users WHERE (username = ?)", (self.username,) | ||
).fetchone()[0] | ||
connection.close() | ||
same_phone = self.userpage.update_phone(self.phone) | ||
assert same_phone is True | ||
self.cleanup_db() | ||
assert test_result == self.phone | ||
|
||
@use_test | ||
def cleanup_db(self): | ||
"""Remove fake data from database""" | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor() | ||
cursor.execute("DELETE FROM Users WHERE (username = ?)", (self.username,)) | ||
cursor.execute("DELETE FROM Users WHERE (username = ?)", (self.alt_username,)) | ||
connection.commit() | ||
connection.close() | ||
|
||
@use_test | ||
def test_get_liked(self): | ||
"""returns correct List""" | ||
self.initialize() | ||
self.main_page_staging.initialize_all() | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor() | ||
minh_phan_id = cursor.execute( | ||
"SELECT user_id FROM Users WHERE (username = 'Minh Phan')" | ||
).fetchone()[0] | ||
sherman_id = cursor.execute( | ||
"SELECT apt_id FROM Apartments WHERE (apt_name = 'Sherman')" | ||
).fetchone()[0] | ||
res = self.userpage.get_liked(minh_phan_id) | ||
liked = [] | ||
liked.append(Apt(sherman_id, "Sherman", "909 S 5th St", 0.333, 5500, 6500)) | ||
self.main_page_staging.clean_all() | ||
assert res == liked |
65a31bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
65a31bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
65a31bd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report