diff --git a/zeeguu/api/endpoints/user.py b/zeeguu/api/endpoints/user.py index 7b89b56a..c906c861 100644 --- a/zeeguu/api/endpoints/user.py +++ b/zeeguu/api/endpoints/user.py @@ -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) diff --git a/zeeguu/core/model/user.py b/zeeguu/core/model/user.py index 912e66e6..49b70469 100644 --- a/zeeguu/core/model/user.py +++ b/zeeguu/core/model/user.py @@ -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 @@ -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 diff --git a/zeeguu/core/test/test_language.py b/zeeguu/core/test/test_language.py index 7383a0a2..95680566 100644 --- a/zeeguu/core/test/test_language.py +++ b/zeeguu/core/test/test_language.py @@ -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