-
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
8 changed files
with
75 additions
and
82 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
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 |
---|---|---|
@@ -1,42 +1,42 @@ | ||
"""Contains the UserPage backend""" | ||
#from pages.login import Login | ||
from pages.login import Login | ||
from dataholders.user import User | ||
from typing import List | ||
from dataholders.apt import Apt | ||
#from app import session | ||
#from decorators import use_database | ||
from decorators import use_database | ||
from pages.login import validate_phone | ||
|
||
class UserPage: | ||
"""UserPage class""" | ||
|
||
def __init__(self) -> None: | ||
def __init__(self, username: str) -> None: | ||
"""Constructor""" | ||
self.username = username | ||
|
||
def get_user(self, username: str) -> User: | ||
user = [] | ||
return user | ||
def get_user(self, username: str): | ||
"""Return User object based on username""" | ||
return True | ||
|
||
def update_password(self, password: str) -> bool: | ||
"""Updates password based on username""" | ||
# can use Flask-Hashing if we want | ||
return True | ||
|
||
def update_email(self, email: str) -> bool: | ||
"""Updates email based on username""" | ||
return True | ||
|
||
def get_liked(self, user_id: int) -> List[Apt]: | ||
"""Gets liked apartments based on username""" | ||
apts = [] | ||
return apts | ||
|
||
#@use_database | ||
@use_database | ||
def update_phone(self, phone: str) -> bool: | ||
"""Update phone number, return true if phone is valid and database is updated""" | ||
'''if not validate_phone(phone): | ||
return False''' | ||
'''if session.get("USERNAME", None) is not None: # checks session object exists | ||
username = session.get("USERNAME") # gets the username from the session object | ||
self.update_phone.cursor.execute( | ||
"UPDATE Users SET phone = ? WHERE (username = ?)", (phone, username), | ||
) | ||
return True''' | ||
return False | ||
"""Updates User's phone number if valid""" | ||
if not validate_phone(phone): | ||
return False | ||
self.update_phone.cursor.execute( | ||
"UPDATE Users SET phone = ? WHERE (username = ?)", (phone, self.username), | ||
) | ||
return True |
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 |
---|---|---|
@@ -1,61 +1,58 @@ | ||
"""Test userpage.py""" | ||
import sqlite3 | ||
from pages.userpage import UserPage | ||
#from decorators import use_test, use_database | ||
#from pages.login import validate_phone | ||
from app import app | ||
from decorators import use_test | ||
from pages.login import validate_phone | ||
|
||
class TestUserPage: | ||
"""Test user page class""" | ||
|
||
userpage = UserPage() | ||
username = "test_username" | ||
alt_username = "alt_username" | ||
userpage = UserPage(username) | ||
phone = "012-345-6789" | ||
invalid_phone = "123-3421-322" | ||
|
||
#@use_database | ||
def set_up(self): | ||
with app.test_client() as c: | ||
with c.session_transaction() as session: | ||
session["SECRET_KEY"] = "VlpJb4lFReaMsVvPZgzMJA" | ||
result = app.test_client.get('/') | ||
|
||
#@use_database | ||
@use_test | ||
def test_update_phone(self): | ||
"""Tests valid and invalid phone numbers""" | ||
#assert validate_phone(self.phone) is True # verify for later tests | ||
#assert validate_phone(self.invalid_phone) is False | ||
#valid = self.test_valid_phone(self.phone) | ||
#invalid = self.test_invalid_phone(self.invalid_phone) | ||
#assert valid is True | ||
#assert invalid is False | ||
assert validate_phone(self.phone) is True # verify for later tests | ||
assert validate_phone(self.invalid_phone) is False | ||
valid = self.test_valid_phone() | ||
invalid = self.test_invalid_phone() | ||
assert valid is True | ||
assert invalid is False | ||
self.cleanup_db() | ||
|
||
#@use_database | ||
@use_test | ||
def test_valid_phone(self) -> bool: | ||
"""Test update_phone returns True and User is logged in""" | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor() | ||
cursor.execute( | ||
"INSERT INTO Users (username, email, password, phone, apt_id) \ | ||
VALUES (?, ?, ?, ?, 0)", | ||
("hello", "hello@gmail.com", "password", "011-899-9013"), | ||
(self.alt_username, "hello@gmail.com", "password", "011-899-9013"), | ||
) | ||
cursor.execute( | ||
"UPDATE Users SET phone = ? WHERE (username = ?)", (self.phone, "hello"), | ||
"UPDATE Users SET phone = ? WHERE (username = ?)", (self.phone, self.alt_username,), | ||
) | ||
result = cursor.execute("SELECT phone FROM Users WHERE (username = ?)", ("hello",)).fetchone() | ||
#update = self.userpage.update_phone(self.valid) | ||
return True | ||
|
||
result = cursor.execute("SELECT phone FROM Users WHERE (username = ?)", (self.alt_username,)).fetchone() | ||
update = self.userpage.update_phone(self.phone) | ||
assert result == update | ||
self.cleanup_db() | ||
return update | ||
|
||
@use_test | ||
def test_invalid_phone(self) -> bool: | ||
"""Test update_phone returns False""" | ||
update = self.userpage.update_phone(self.invalid_phone) | ||
return True | ||
return self.userpage.update_phone(self.invalid_phone) | ||
|
||
@use_test | ||
def cleanup_db(self) -> None: | ||
"""Remove fake data from database""" | ||
connection = sqlite3.connect("database/database_test.db") | ||
cursor = connection.cursor | ||
cursor.execute("DELETE FROM Users WHERE (phone = ?)", (self.phone,)) | ||
cursor.execute("DELETE FROM Users WHERE (phone = ?)", (self.invalid_phone,)) | ||
cursor = connection.cursor() | ||
cursor.execute("DELETE FROM Users WHERE (username = ?)", (self.username, self.alt_username,)) | ||
connection.commit() | ||
connection.close() |
a357b1c
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
a357b1c
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
a357b1c
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