Example #1
0
 def test_search_words_matches_by_word(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('sabuda', [])) \
             .given_a_word(WordMeanings('assaumanyat', [])) \
             .given_everythin_is_indexed() \
             .when_search_word('sabuda') \
             .then_should_return(['sabuda'])
Example #2
0
 def test_search_by_first_letter_with_no_matches(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('baaa', [])) \
             .given_a_word(WordMeanings('xyz', [])) \
             .given_everythin_is_indexed() \
             .when_search_by_first_letter('a') \
             .then_should_return([])
Example #3
0
 def test_get_random_word_returns_a_word(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('baaa', [])) \
             .given_a_word(WordMeanings('xyz', [])) \
             .given_everythin_is_indexed() \
             .when_get_random_word() \
             .then_should_return_one_of(['baaa', 'xyz'])
Example #4
0
 def test_search_words_boosts_word_over_meaning(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('cadell', [Meaning('', '', '', '', ['gosset'], [])])) \
             .given_a_word(WordMeanings('gosset', [Meaning('', '', '', '', ['cadell'], [])])) \
             .given_everythin_is_indexed() \
             .when_search_word('gosset') \
             .then_should_return(['gosset', 'cadell'])
Example #5
0
 def test_two_meanings_should_be_returned_sorted_by_semantic_group(self):
     WordRepoTestCase.TestScenario() \
             .given_a_definition(word="piece", phonetic="ph2", scientific="lorem2", type="noun2",
                                 meaning="A small part2", extra_info="Typical word2",
                                 private_notes="secret2", synonyms="taste2, specimen2",
                                 related="data2, analysis2", origin="england2",
                                 semantic_field="statistics2", semantic_group=2,
                                 source="test data", reviewed=True, public=True) \
             .given_a_definition(word="piece", phonetic="ph", scientific="lorem", type="noun",
                                 meaning="A small part", extra_info="Typical word",
                                 private_notes="secret", synonyms="taste, specimen",
                                 related="data, analysis", origin="england",
                                 semantic_field="statistics", semantic_group=1,
                                 source="test data", reviewed=True, public=True) \
             .given_a_definition(word="loft", phonetic="ph2", scientific="lorem2", type="noun2",
                                 meaning="A small part2", extra_info="Typical word2",
                                 private_notes="secret2", synonyms="taste2, specimen2",
                                 related="data2, analysis2", origin="england2",
                                 semantic_field="statistics2", semantic_group=2,
                                 source="test data", reviewed=True, public=True) \
             .given_a_definition(word="loft", phonetic="ph", scientific="lorem", type="noun",
                                 meaning="A small part", extra_info="Typical word",
                                 private_notes="secret", synonyms="taste, specimen",
                                 related="data, analysis", origin="england",
                                 semantic_field="statistics", semantic_group=1,
                                 source="test data", reviewed=True, public=True) \
             .when_get_words_meanings(["piece", "loft"]) \
             .then_should_return([
                                  WordMeanings(word="piece",
                                               meanings=[Meaning(scientific="lorem", type="noun",
                                                                 description="A small part",
                                                                 extra_info="Typical word",
                                                                 synonym_words=["taste", "specimen"],
                                                                 related_words=["data", "analysis"]),
                                                         Meaning(scientific="lorem2", type="noun2",
                                                                 description="A small part2",
                                                                 extra_info="Typical word2",
                                                                 synonym_words=["taste2", "specimen2"],
                                                                 related_words=["data2", "analysis2"])]),
                                  WordMeanings(word="loft",
                                               meanings=[Meaning(scientific="lorem", type="noun",
                                                                 description="A small part",
                                                                 extra_info="Typical word",
                                                                 synonym_words=["taste", "specimen"],
                                                                 related_words=["data", "analysis"]),
                                                         Meaning(scientific="lorem2", type="noun2",
                                                                 description="A small part2",
                                                                 extra_info="Typical word2",
                                                                 synonym_words=["taste2", "specimen2"],
                                                                 related_words=["data2", "analysis2"])]),
                                                         ])
Example #6
0
 def test_returns_list_of_word_with_uri_and_200(self):
     TestAllWordsView.TestScenario() \
             .given_a_word_repo_that_returns([
                 WordMeanings(word='word_a', meanings=[
                     Meaning('s', 't', 'one', 'x', ['a', 'b 2'], ['c 1', 'b 2']),
                     Meaning('r', 'u', 'two', 'y', ['x', 'b2'], ['c1', 'w2'])
                 ]),
                 WordMeanings(word='word_b', meanings=[
                     Meaning('s', 'q', 'new', 'o', ['x', 'b2'], ['c1', 'w2'])
                 ]),
             ]) \
             .when_get_all_words_view() \
             .then_should_call_repo_get_all_words_meanings() \
             .then_should_response(200, [
                 {
                     'word': 'word_a',
                     'meanings': [
                         {
                             'scientific': 's',
                             'type': 't',
                             'description': 'one',
                             'extra_info': 'x',
                             'synonym_words': ['a', 'b 2'],
                             'related_words': ['c 1', 'b 2']
                         },
                         {
                             'scientific': 'r',
                             'type': 'u',
                             'description': 'two',
                             'extra_info': 'y',
                             'synonym_words': ['x', 'b2'],
                             'related_words': ['c1', 'w2']
                         }
                     ]
                 },
                 {
                     'word': 'word_b',
                     'meanings': [
                         {
                             'scientific': 's',
                             'type': 'q',
                             'description': 'new',
                             'extra_info': 'o',
                             'synonym_words': ['x', 'b2'],
                             'related_words': ['c1', 'w2']
                         },
                     ]
                 },
             ])
Example #7
0
    def get_all_words_meanings(self):
        definitions = Definition.objects.filter(public=True).order_by('word')

        words = []
        for key, group in itertools.groupby(definitions, key=lambda x:x.word):
            words.append(WordMeanings(key, [self.parse_meaning(definition) for definition in group]))

        return words
Example #8
0
 def test_get_all_words_meanings(self):
     WordRepoTestCase.TestScenario() \
             .given_a_definition(word='word_a', scientific='s', type='t', meaning='one',
                                 extra_info='x', synonyms="a, b 2", related="c 1, b 2", public=True) \
             .given_a_definition(word='word_a', scientific='r', type='u', meaning='two',
                                 extra_info='y', synonyms="x, b2", related="c1, w2", public=True) \
             .given_a_definition(word='word_b', scientific='s', type='q', meaning='new',
                                 extra_info='o', synonyms="x, b2", related="c1, w2", public=True) \
             .when_get_all_words() \
             .then_should_return([
                 WordMeanings(word='word_a', meanings=[
                     Meaning('s', 't', 'one', 'x', ['a', 'b 2'], ['c 1', 'b 2']),
                     Meaning('r', 'u', 'two', 'y', ['x', 'b2'], ['c1', 'w2'])
                 ]),
                 WordMeanings(word='word_b', meanings=[
                     Meaning('s', 'q', 'new', 'o', ['x', 'b2'], ['c1', 'w2'])
                 ]),
             ])
Example #9
0
    def get_word_meanings(self, word):
        orm_definitions = Definition.objects.filter(word=word) \
                                            .filter(public=True) \
                                            .filter(reviewed=True) \
                                            .order_by('semantic_group')

        if not orm_definitions:
            raise EntityNotFoundException()

        meanings = [self.parse_meaning(orm_definition) for orm_definition in orm_definitions]

        return WordMeanings(word, meanings)
Example #10
0
 def test_get_word_meanings_random(self):
     WordRepoTestCase.TestScenario() \
             .given_a_definition(word='a_word', scientific='s', type='t', meaning='one',
                                 extra_info='x', synonyms="a, b 2", related="c 1, b 2", public=True) \
             .given_a_definition(word='a_word', scientific='r', type='u', meaning='two',
                                 extra_info='y', synonyms="x, b2", related="c1, w2", public=True) \
             .given_a_definition(word='word_b', scientific='s', type='q', meaning='new',
                                 extra_info='o', synonyms="x, b2", related="c1, w2", public=True) \
             .given_a_definition(word='word_b', scientific='p', type='m', meaning='old',
                                 extra_info='u', synonyms="w, b3", related="c8, w9", public=True) \
             .given_everything_is_indexed() \
             .when_get_random_word_meanings() \
             .then_should_return_one_of([
                 WordMeanings(word='a_word', meanings=[
                     Meaning('s', 't', 'one', 'x', ['a', 'b 2'], ['c 1', 'b 2']),
                     Meaning('r', 'u', 'two', 'y', ['x', 'b2'], ['c1', 'w2'])
                 ]),
                 WordMeanings(word='word_b', meanings=[
                     Meaning('s', 'q', 'new', 'o', ['x', 'b2'], ['c1', 'w2']),
                     Meaning('p', 'm', 'old', 'u', ['w', 'b3'], ['c8', 'w9'])
                 ]),
             ])
Example #11
0
    def get_words_meanings(self, words):
        preserved = Case(*[When(word=pk, then=pos) for pos, pk in enumerate(words)])
        orm_definitions = Definition.objects.filter(word__in=words) \
                                            .filter(public=True) \
                                            .filter(reviewed=True) \
                                            .order_by(preserved)

        words_meanings = []
        for key, group in itertools.groupby(orm_definitions, key=lambda x:x.word):
            meanings = [self.parse_meaning(definition) for definition in sorted(list(group), key=lambda x:x.semantic_group)]
            words_meanings.append(WordMeanings(key, meanings))

        return words_meanings
Example #12
0
 def test_search_words_meanings(self):
     WordRepoTestCase.TestScenario() \
             .given_a_definition(word='a_word', scientific='s', type='t', meaning='one target',
                                 extra_info='x', synonyms="a, b 2", related="c 1, b 2", public=True) \
             .given_a_definition(word='a_word', scientific='r', type='u', meaning='two',
                                 extra_info='y', synonyms="x, b2", related="c1, w2", public=True) \
             .given_a_definition(word='target', scientific='r', type='w', meaning='first',
                                 extra_info='q', synonyms="o, b9", related="c4, t2", public=True) \
             .given_a_definition(word='word_b', scientific='s', type='q', meaning='new',
                                 extra_info='o', synonyms="x, b2", related="c1, w2", public=True) \
             .given_a_definition(word='b_word', scientific='s', type='q', meaning='new',
                                 extra_info='o', synonyms="x, b2", related="c1, w2", public=True) \
             .given_everything_is_indexed() \
             .when_search_words_meanings('target') \
             .then_should_return([
                 WordMeanings(word='target', meanings=[
                     Meaning('r', 'w', 'first', 'q', ['o', 'b9'], ['c4', 't2'])
                 ]),
                 WordMeanings(word='a_word', meanings=[
                     Meaning('s', 't', 'one target', 'x', ['a', 'b 2'], ['c 1', 'b 2']),
                     Meaning('r', 'u', 'two', 'y', ['x', 'b2'], ['c1', 'w2'])
                 ]),
             ])
Example #13
0
 def test_a_definition_returns_word_with_that_meaning(self):
     WordRepoTestCase.TestScenario() \
             .given_a_definition(word="piece", phonetic="ph", scientific="lorem", type="noun",
                                 meaning="A small part", extra_info="Typical word",
                                 private_notes="secret", synonyms="taste, specimen",
                                 related="data, analysis", origin="england",
                                 semantic_field="statistics", semantic_group=1,
                                 source="test data", reviewed=True, public=True) \
             .when_get_word_meanings("piece") \
             .then_should_return(WordMeanings(word="piece",
                                              meanings=[Meaning(scientific="lorem", type="noun",
                                                                description="A small part",
                                                                extra_info="Typical word",
                                                                synonym_words=["taste", "specimen"],
                                                                related_words=["data", "analysis"])]))
Example #14
0
    def test_if_word_daily_retrieves_and_returns_random_word_meanings_with_seed(
            self):
        meaning_a = Meaning(scientific='sc',
                            type='ty',
                            description='desc',
                            extra_info='e_i',
                            synonym_words=['a', 'b'],
                            related_words=['c', 'd'])
        meaning_b = Meaning(scientific='lorem',
                            type='noun',
                            description='word meaning',
                            extra_info='none',
                            synonym_words=[],
                            related_words=[])

        TestWordView.TestScenario() \
                .given_a_word_repo_that_returns_on_random(WordMeanings("Test", [meaning_a, meaning_b])) \
                .when_get_word_view("daily", seed=4) \
                .then_should_call_repo_get_random_word_meanings(seed=4) \
                .then_should_response(200, {'word': 'Test',
                    'meanings': [
                           {
                               'scientific': 'sc',
                               'type': 'ty',
                               'description': 'desc',
                               'extra_info': 'e_i',
                               'synonym_words': ['a', 'b'],
                               'related_words': ['c', 'd']
                           },
                           {
                               'scientific': 'lorem',
                               'type': 'noun',
                               'description': 'word meaning',
                               'extra_info': 'none',
                               'synonym_words': [],
                               'related_words': [],
                           },
                       ]})
Example #15
0
 def test_search_words_matches_with_hyphen(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('avenar-se', [])) \
             .given_everythin_is_indexed() \
             .when_search_word('avenar-se') \
             .then_should_return(['avenar-se'])
Example #16
0
 def test_search_words_matches_with_accent(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('després', [])) \
             .given_everythin_is_indexed() \
             .when_search_word('després') \
             .then_should_return(['després'])
Example #17
0
 def test_search_words_matches_femenine_gender(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('encalamunat -da', [])) \
             .given_everythin_is_indexed() \
             .when_search_word('encalamunada') \
             .then_should_return(['encalamunat -da'])
Example #18
0
 def test_search_words_matches_by_root_word(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('mallar', [])) \
             .given_everythin_is_indexed() \
             .when_search_word('mallem') \
             .then_should_return(['mallar'])
Example #19
0
 def test_search_words_matches_by_related(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('lliri blanc', [Meaning('', '', '', '', [], ['assutzena'])])) \
             .given_everythin_is_indexed() \
             .when_search_word('assutzena') \
             .then_should_return(['lliri blanc'])
Example #20
0
 def test_search_words_matches_by_synonyms(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('corna', [Meaning('', '', '', '', ['bana'], [])])) \
             .given_everythin_is_indexed() \
             .when_search_word('bana') \
             .then_should_return(['corna'])
Example #21
0
 def test_search_words_matches_by_scientific(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('sègol', [Meaning('secale cereale', '', '', '', [], [])])) \
             .given_everythin_is_indexed() \
             .when_search_word('secale') \
             .then_should_return(['sègol'])
Example #22
0
 def test_search_words_matches_by_description(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('mallorquer', [Meaning('', '', 'la planta del blat de moro', '', [], [])])) \
             .given_everythin_is_indexed() \
             .when_search_word('blat') \
             .then_should_return(['mallorquer'])
Example #23
0
 def test_search_words_matches_with_typo(self):
     WordSearchRepoTestCase.TestScenario() \
             .given_a_word(WordMeanings('panasca', [])) \
             .given_everythin_is_indexed() \
             .when_search_word('panaso') \
             .then_should_return(['panasca'])