Skip to content

Commit

Permalink
Allow to update learned_language without passing CEFR (backward compa…
Browse files Browse the repository at this point in the history
…tability)

Updated - test to set language.
  • Loading branch information
tfnribeiro committed Jun 20, 2024
1 parent 9e3788c commit bf50dff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 0 additions & 1 deletion zeeguu/api/endpoints/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def user_settings():

submitted_email = data.get("email", None)
if submitted_email:
print("Updating email!")
user.email = submitted_email

zeeguu.core.model.db.session.add(user)
Expand Down
8 changes: 6 additions & 2 deletions zeeguu/core/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def text_difficulty(self, text, language):
def set_native_language(self, code):
self.native_language = Language.find(code)

def set_learned_language(self, language_code: str, cefr_level: int, session=None):
def set_learned_language(
self, language_code: str, cefr_level: int = None, session=None
):
self.learned_language = Language.find(language_code)

from zeeguu.core.model import UserLanguage
Expand All @@ -191,10 +193,12 @@ def set_learned_language(self, language_code: str, cefr_level: int, session=None
language = UserLanguage.find_or_create(session, self, self.learned_language)
language.reading_news = True
language.doing_exercises = True
language.cefr_level = cefr_level
if cefr_level:
language.cefr_level = cefr_level

if session:
session.add(language)


def set_learned_language_level(
self, language_code: str, cefr_level: str, session=None
Expand Down
17 changes: 14 additions & 3 deletions zeeguu/core/test/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,21 @@ def test_get_all_languages(self):
assert LanguageRule.get_or_create_language(lan)

def test_user_set_language(self):
language_should_be = LanguageRule().random
from zeeguu.core.model import UserLanguage

self.user.set_learned_language(language_should_be.code, db_session)
assert self.user.learned_language.id == language_should_be.id
language_should_be = LanguageRule().random
language_level_should_be = 2
self.user.set_learned_language(
language_should_be.code, language_level_should_be, db_session
)
db_session.commit()
user_language = UserLanguage.find_or_create(
db_session, self.user, language_should_be
)
assert (
self.user.learned_language.id == language_should_be.id
and user_language.cefr_level == language_level_should_be
)

def test_native_language(self):
language_should_be = LanguageRule().random
Expand Down

0 comments on commit bf50dff

Please sign in to comment.