Skip to content

Commit

Permalink
fix return errors and type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akrakman committed Nov 26, 2022
1 parent 1e12232 commit 8cecab2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
22 changes: 11 additions & 11 deletions src/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,38 @@ def userpage():
"""Handles userpage requests"""
if session.get("username", None) is None:
return "user does not exist", 404
username = session.get("username")
username = session.get("username") or ""
page = UserPage(username)
if request.method == "POST":
json_form = request.get_json(force=True) # deserialize data
json_form = request.get_json(force=True) or {} # deserialize data
# see which field was True and therefore should be changed
is_password = json_form.get("is_password", False)
is_email = json_form.get("is_email", False)
is_phone = json_form.get("is_phone", False)
is_get_liked = json_form.get("is_get_liked", False)
result = False
if is_password:
result = page.update_password(json_form.get("password"))
result = page.update_password(json_form.get("password") or "")
elif is_email:
result = page.update_email(json_form.get("email"))
result = page.update_email(json_form.get("email") or "")
elif is_phone:
result = page.update_phone(json_form.get("phone"))
result = page.update_phone(json_form.get("phone") or "")
elif is_get_liked:
liked_apts = page.get_liked(json_form.get("user_id"))
liked_apts = page.get_liked(json_form.get("user_id") or 0)
return dataclasses_into_json(liked_apts), 201
if not result:
return result, 400
return result, 201
return "invalid request", 400
return "success", 201
user = page.get_user(username) # request.method == "GET"
data_dict = dataclasses.asdict(user)
return json.dumps(data_dict), username, 201
return json.dumps(data_dict), 201


@app.route("/logout")
def logout():
"""Removes session object"""
res = session.pop("username", None) # session object is None if pop fails
return res, 201
session.pop("username", None) # remove session object
return "", 201


@app.route("/", methods=["GET", "POST"])
Expand Down
2 changes: 1 addition & 1 deletion src/backend/pages/userpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_user(self, username: str) -> User:
(query_sql,),
).fetchone()
if user_query is None:
return None
return User("", "", "", "", "")
user_id, password, email, phone = user_query
return User(user_id, username, password, email, phone)

Expand Down
24 changes: 14 additions & 10 deletions src/backend/tests/test_userpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestUserPage:
phone = "012-345-6789"
password = "newpassword1234"
email = "[email protected]"
userpage = None
userpage = UserPage(username)
main_page_staging = MainPageStaging()

@use_database
Expand Down Expand Up @@ -48,14 +48,18 @@ def test_invalid_input(self):

@use_test
def test_get_user(self):
"""get_user returns correct Use"""
"""get_user returns correct User"""
self.initialize()
res = self.userpage.get_user(self.username)
print(res)
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
assert (
self.userpage.get_user("sd").email == ""
and self.userpage.get_user("sd").user_id == ""
)
self.test_cleanup_db()

@use_test
Expand Down Expand Up @@ -116,18 +120,18 @@ def test_get_liked(self):
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')"
big_finger_id = cursor.execute(
"SELECT user_id FROM Users WHERE (username = 'Big_finger')"
).fetchone()[0]
sherman_id = cursor.execute(
"SELECT apt_id FROM Apartments WHERE (apt_name = 'Sherman')"
far_id = cursor.execute(
"SELECT apt_id FROM Apartments WHERE (apt_name = 'FAR')"
).fetchone()[0]
res = self.userpage.get_liked(minh_phan_id)
res = self.userpage.get_liked(big_finger_id)
liked = []
liked.append(Apt(sherman_id, "Sherman", "909 S 5th St", 0.333, 5500, 6500))
liked.append(Apt(far_id, "FAR", "901 W College Ct", 1, 6000, 7000))
self.main_page_staging.clean_all()
self.test_cleanup_db()
assert res == liked
assert res[1] == liked[0]

@use_test
def test_cleanup_db(self):
Expand Down

3 comments on commit 8cecab2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py1320100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
   user.py80100%
pages
   login.py290100%
   mainpage.py1000100%
   userpage.py540100%
TOTAL3820100%

Tests Skipped Failures Errors Time
48 0 💤 1 ❌ 0 🔥 0.821s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py1320100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
   user.py80100%
pages
   login.py290100%
   mainpage.py1000100%
   userpage.py540100%
TOTAL3820100%

Tests Skipped Failures Errors Time
48 0 💤 1 ❌ 0 🔥 0.767s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py1320100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
   user.py80100%
pages
   login.py290100%
   mainpage.py1000100%
   userpage.py540100%
TOTAL3820100%

Tests Skipped Failures Errors Time
48 0 💤 1 ❌ 0 🔥 1.231s ⏱️

Please sign in to comment.