def test_text_difficulty_with_preference(self): # with the default estimator (Frequency) the difficulty is EASY difficulty = self.user.text_difficulty(self.text, self.english) assert difficulty['discrete'] == 'MEDIUM' # setting a preference for this user p = UserPreference.set_difficulty_estimator(self.db.session, self.user, "frequency") # with fk difficulty for the example text is MEDIUM difficulty = self.user.text_difficulty(self.text, self.english) assert difficulty['discrete'] == 'EASY'
def preferred_difficulty_estimator(self): """ :return: Difficulty estimator from preferences, otherwise the default one which is FrequencyDifficultyEstimator """ from zeeguu_core.model.user_preference import UserPreference # Must have this import here to avoid circular dependency preference = UserPreference.get_difficulty_estimator( self) or "FleschKincaidDifficultyEstimator" logger.debug(f"Difficulty estimator for user {self.id}: {preference}") return preference
def test_setting_preference(self): UserPreference.set_difficulty_estimator(self.db.session, self.user, "fk") assert UserPreference.get_difficulty_estimator(self.user) == "fk"
def test_no_preference_at_first(self): assert not UserPreference.get_difficulty_estimator(self.user)