Skip to content

Commit

Permalink
remove register creation bug and enforce foreign key constraint on te…
Browse files Browse the repository at this point in the history
…sting sqlite database
  • Loading branch information
TaiHaDev committed Mar 16, 2024
1 parent 17ce80a commit a42620f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions domain/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
Session = sessionmaker()
if os.environ.get("SQLALCHEMY_DATABASE_URI"):
Engine = create_engine(os.environ.get("SQLALCHEMY_DATABASE_URI"))


def enable_fk_listener(dbapi_connection, connection_record): # enabling foreign key constraint in the test database
dbapi_connection.execute('pragma foreign_keys=ON')


event.listen(Engine, 'connect', enable_fk_listener)

else:
Engine = create_engine('mysql+mysqldb://{0}:{1}@{2}:{3}/{4}'.format(os.environ.get('username'),
os.environ.get('password'),
Expand Down
2 changes: 1 addition & 1 deletion services/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def register(session: Session, email: str, password: str, given_name: str, last_
# Everything seems fine, so we go ahead and create the user & the linked account.
password_hash = passwordService.hash(password)
new_user = User(role=UserType.VOLUNTEER, password=password_hash, first_name=given_name, last_name=last_name,
mobile_number=phone, email=email, preferred_hours={}, experience_years=0, possibleRoles=["Basic"],
mobile_number=phone, email=email, preferred_hours=None, experience_years=0, possibleRoles=["Basic"],
qualifications=[],
availabilities={"Friday": [], "Monday": [], "Sunday": [], "Tuesday": [], "Saturday": [],
"Thursday": [], "Wednesday": []},
Expand Down

0 comments on commit a42620f

Please sign in to comment.