Пример #1
0
    def setUp(self):
        super().setUp()

        self.user_rule = UserRule()
        self.user = self.user_rule.user
        self.db.session.add(self.user)
        self.db.session.commit()

        self.random_origin_word = self.faker.word()
        self.random_origin_language = LanguageRule().random
        self.user_word_rule = UserWordRule(self.random_origin_word,
                                           self.random_origin_language)

        self.text = "This sentence, taken as a reading passage unto itself, is being used to prove a point."
        self.english = LanguageRule().get_or_create_language("en")
Пример #2
0
 def test_importance_level(self):
     random_word_stats = self.__get_random_word_stats()
     random_language = LanguageRule().get_or_create_language(
         random_word_stats[1].language_id)
     user_word = UserWord(random_word_stats[0], random_language)
     assert user_word.importance_level() == int(
         random_word_stats[1].importance)
    def test_english_medium(self):
        lan = LanguageRule().en
        d = FleschKincaidDifficultyEstimator.estimate_difficulty(
            E_MEDIUM_TEXT, lan, self.user
        )

        self.assertEqual(d["discrete"], "MEDIUM")
    def test_english_hard(self):
        lan = LanguageRule().en
        d = FleschKincaidDifficultyEstimator.estimate_difficulty(
            E_HARD_TEXT, lan, self.user
        )

        self.assertEqual(d["discrete"], "HARD")
    def test_german_medium(self):
        lan = LanguageRule().de
        d = FleschKincaidDifficultyEstimator.estimate_difficulty(
            DE_MEDIUM_TEXT, lan, self.user
        )

        self.assertEqual("MEDIUM", d["discrete"])
    def test_german_hard(self):
        lan = LanguageRule().de
        d = FleschKincaidDifficultyEstimator.estimate_difficulty(
            DE_HARD_TEXT, lan, self.user
        )

        self.assertEqual("HARD", d["discrete"])
Пример #7
0
    def _create_model_object(self, *args):
        name = self.faker.word()
        inv_code = self.faker.word()
        max_students = 10
        language = LanguageRule().random
        cohort = Cohort(inv_code, name, language, max_students)

        return cohort
Пример #8
0
    def test_find_or_create(self):
        random_word = self.faker.word()
        random_language = LanguageRule().random
        user_word_not_in_db = UserWord(random_word, random_language)
        user_word_created = UserWord.find_or_create(self.db.session,
                                                    random_word,
                                                    random_language)

        assert user_word_created == user_word_not_in_db
Пример #9
0
    def test_languages_exists(self):
        language_should_be = LanguageRule().random

        try:
            language_to_check = Language.find(language_should_be.code)
        except NoResultFound:
            assert False, "No Language found in database"

        assert language_should_be.code == language_to_check.code \
               and language_should_be.name == language_to_check.name
Пример #10
0
    def _create_model_object(self):
        random_email = self.faker.simple_profile()['mail']
        random_name = self.faker.name()
        random_password = self.faker.password()
        random_learned_language = LanguageRule().random
        random_native_language = LanguageRule().random

        while random_native_language.id == random_learned_language.id:
            random_native_language = LanguageRule().random

        user = User(random_email,
                    random_name,
                    random_password,
                    learned_language=random_learned_language,
                    native_language=random_native_language)

        if self._exists_in_db(user):
            return self._create_model_object()

        return user
    def test_danish(self):
        lan = LanguageRule().da

        d = FleschKincaidDifficultyEstimator.estimate_difficulty(
            DA_TEXT_PORCELAENHUSET, lan, self.user
        )
        self.assertEqual(d["discrete"], "HARD")

        d = FleschKincaidDifficultyEstimator.estimate_difficulty(
            DA_TEXT_YING_MEDIUM, lan, self.user
        )
        self.assertEqual(d["discrete"], "MEDIUM")
Пример #12
0
    def _create_model_object(self, length):
        random_content = self.faker.text(max_nb_chars=length)
        random_language = LanguageRule().random

        random_article = ArticleRule().article
        random_url = random_article.url

        text = Text(random_content, random_language, random_url, random_article )

        if self._exists_in_db(text):
            return self._create_model_object(length)

        return text
Пример #13
0
    def _create_model_object(self):
        title = " ".join(self.faker.text().split()[:(randint(1, 10))])
        description = " ".join(self.faker.text().split()[:(randint(5, 20))])
        language = LanguageRule().random
        url = UrlRule().url
        image_url = UrlRule().url
        icon_name = self.faker.name()

        new_rss_feed = RSSFeed(url, title, description, image_url, icon_name, language)

        if RSSFeed.exists(new_rss_feed):
            return self._create_model_object()

        return new_rss_feed
Пример #14
0
    def _create_model_object(self, word=None, language=None):
        tmp_word = word
        tmp_language = language

        if tmp_word is None:
            tmp_word = self.faker.word()

        if tmp_language is None:
            tmp_language = LanguageRule().random

        user_word = UserWord(tmp_word, tmp_language)

        if self._exists_in_db(user_word):
            return self._create_model_object(word, language)

        return user_word
Пример #15
0
    def _create_model_object(self):
        title = " ".join(self.faker.text().split()[:4])
        authors = self.faker.name()
        content = self.faker.text()
        summary = self.faker.text()
        published = datetime.now() - timedelta(minutes=randint(0, 7200))
        rss_feed = RSSFeedRule().feed
        language = LanguageRule().random
        url = UrlRule().url

        article = Article(url, title, authors, content, summary, published,
                          rss_feed, language)

        if self._exists_in_db(article):
            return self._create_model_object()

        return article
Пример #16
0
 def __get_random_word_stats(self):
     random_language = LanguageRule().random
     language_stats = load_language_from_hermit(random_language.code)
     return random.choice(list(language_stats.word_info_dict.items()))
Пример #17
0
    def _create_model_object(self, user, force_quality=True, **kwargs):
        """
        Creates a Bookmark object with random data.

        Behind the random words, a random number is added since the Faker library does not have too many RANDOM words
        and random words get repeated whenever many random bookmarks are created. To overcome the problem of bookmarks
        with duplicate words in the database, a random number is added.

        Also, if force_quality is set (default) and the bookmark is not .quality_bookmark() the process is
        reiterated till this is true. This simplifies some of the tests

        :param user: User Object, to which the bookmark is assigned.
        :param kwargs: Holds any of the 'props' as key if a field should not be random
        :return:
        """

        bookmark = None

        while not bookmark:

            from zeeguu.core.test.rules.text_rule import TextRule

            random_text = TextRule().text

            random_origin_word = self.faker.word() + str(random.random())
            random_origin_language = user.learned_language

            random_translation_word = self.faker.word() + str(random.random())
            random_translation_language = LanguageRule().random

            if UserWord.exists(
                random_origin_word, random_origin_language
            ) or UserWord.exists(random_translation_word, random_translation_language):
                return self._create_model_object(user)

            random_origin = UserWordRule(
                random_origin_word, random_origin_language
            ).user_word
            random_translation = UserWordRule(
                random_translation_word, random_translation_language
            ).user_word
            random_date = self.faker.date_time_this_month()

            from zeeguu.core.test.rules.article_rule import ArticleRule

            random_article = ArticleRule(real=True).article

            bookmark = Bookmark(
                random_origin, random_translation, user, random_text, random_date
            )
            if force_quality and bad_quality_bookmark(bookmark):
                print("random bookmark was of low quality. retrying...")
                bookmark = False

        for k in kwargs:
            if k in self.props:
                setattr(bookmark, k, kwargs.get(k))

        if self._exists_in_db(bookmark):
            return self._create_model_object(user)

        return bookmark
 def test_german_constants(self):
     lan = LanguageRule().de
     constants = FleschKincaidDifficultyEstimator.get_constants_for_language(lan)
     self.assertEqual(180, constants["start"])
     self.assertEqual(1, constants["sentence"])
     self.assertEqual(58.5, constants["word"])
 def test_english_constants(self):
     lan = LanguageRule().en
     constants = FleschKincaidDifficultyEstimator.get_constants_for_language(lan)
     self.assertEqual(206.835, constants["start"])
     self.assertEqual(1.015, constants["sentence"])
     self.assertEqual(84.6, constants["word"])
Пример #20
0
    def test_native_language(self):
        language_should_be = LanguageRule().random

        self.user.set_native_language(language_should_be.code)
        assert self.user.native_language.id == language_should_be.id
Пример #21
0
    def test_user_set_language(self):
        language_should_be = LanguageRule().random

        self.user.set_learned_language(language_should_be.code, session)
        assert self.user.learned_language.id == language_should_be.id
Пример #22
0
    def test_get_all_languages(self):
        languages = LanguageRule.languages

        for lan in languages:
            assert LanguageRule.get_or_create_language(lan)
Пример #23
0
 def setUp(self):
     super().setUp()
     self.lan = LanguageRule().de
     self.user = UserRule().user
Пример #24
0
 def setUp(self):
     super().setUp()
     self.article1 = ArticleRule().article
     self.article2 = ArticleRule().article
     self.language = LanguageRule.get_or_create_language("en")