Skip to content

Commit

Permalink
Fix UserData failing with unset name
Browse files Browse the repository at this point in the history
This fixes a bug where the UserData class would fail when first_name or
last_name would be accessed without being set first.
  • Loading branch information
rbaltrusch committed Nov 12, 2023
1 parent f7710dd commit e07828c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion desktop_shop/gui/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def sign_out():
"""
gui.app.data = {
"session_id": None,
"user_data": user.UserSignUpData(),
"user_data": None,
"pw_hash": "",
"cart": [],
}
Expand Down
4 changes: 2 additions & 2 deletions desktop_shop/gui/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import tkinter as tk
from typing import Dict

from desktop_shop import gui, user
from desktop_shop import gui
from desktop_shop.gui import components, config
from desktop_shop.gui.components import Builder, Component, EntryFactory, Factory, Frame
from desktop_shop.gui.views import views
Expand Down Expand Up @@ -62,7 +62,7 @@ def init():
gui.app.views_dict = init_views(gui.root, gui.app.builder)
gui.app.data = {
"session_id": None,
"user_data": user.UserSignUpData(),
"user_data": None,
"pw_hash": "",
"cart": [],
}
Expand Down
9 changes: 3 additions & 6 deletions desktop_shop/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
# pylint: disable=function-redefined
@dataclass
class UserData:
"""Stores user data
"""Stores user data"""

FIXME: crashes when first_name or last_name are accessed without being set.
"""

first_name: str = ""
last_name: str = ""
first_name: str
last_name: str
gender: str = ""
dob: str = "" # date of birth
email: str = ""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/gui/callbacks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_store_user_data_error():
@pytest.mark.parametrize(
"user_data, expected_message_start, expected",
[
(UserSignUpData(), "Email", False),
(UserSignUpData(first_name="a", last_name="b"), "Email", False),
(UserSignUpData(email="[email protected]", first_name="1eer3", last_name="2aa4"), "First", False),
(UserSignUpData(email="[email protected]", first_name="john", last_name="2bbere4 "), "Last", False),
(UserSignUpData(email="[email protected]", first_name="john", last_name="doe"), "", True),
Expand Down

0 comments on commit e07828c

Please sign in to comment.