def test_term_entity_comment(_): term_a = TermFactory.create( text="term", part_of_speech="noun", definition="definition", ) assert term_a.entity_comment() == "Noun. Definition." term_b = TermFactory.create( text="term", part_of_speech="noun", definition="definition", usage="usage", ) assert term_b.entity_comment() == "Noun. Definition. E.g. Usage."
def test_term_translation(_, locale_a): term = TermFactory.create(text="term") assert term.translation(locale_a) is None TermTranslationFactory.create( locale=locale_a, term=term, text="translation", ) assert term.translation(locale_a) == "translation" do_not_translate = TermFactory.create(text="term", do_not_translate=True) assert do_not_translate.translation(locale_a) == "term"
def test_term_localizable(_): term_a = TermFactory.create(text="term A") assert term_a.localizable is True term_b = TermFactory.create(text="term B") term_b.do_not_translate = True assert term_b.localizable is False term_c = TermFactory.create(text="term C") term_c.forbidden = True assert term_c.localizable is False term_d = TermFactory.create(text="term D") term_d.definition = "" assert term_d.localizable is False
def test_term_save(handle_term_update_mock, handle_term_create_mock): # If term created and localizable, call handle_term_create() term_a = TermFactory.create() assert handle_term_create_mock.call_count == 1 assert handle_term_update_mock.call_count == 0 # If term updated, call handle_term_create() term_a.definition = "definition" term_a.save() assert handle_term_create_mock.call_count == 1 assert handle_term_update_mock.call_count == 1 # If term created and not localizable, do not call anything TermFactory.create(do_not_translate=True) assert handle_term_create_mock.call_count == 1 assert handle_term_update_mock.call_count == 1
def test_reset_term_translation(locale_a): """ Test if TermTranslation gets properly updated when translation in the "Terminology" project changes. """ project, _ = Project.objects.get_or_create(slug="terminology") entity = EntityFactory.create(resource=project.resources.first()) term = TermFactory.create() entity.term = term # No approved Translations of an Entity: no TermTranslation TranslationFactory.create(locale=locale_a, entity=entity) entity.reset_term_translation(locale_a) assert entity.term.translations.filter(locale=locale_a).count() == 0 # First approved Translation of an Entity added: create TermTranslation to match the Translation translation_approved = TranslationFactory.create(locale=locale_a, entity=entity, approved=True) entity.reset_term_translation(locale_a) assert entity.term.translations.filter(locale=locale_a).count() == 1 assert (entity.term.translations.get( locale=locale_a).text == translation_approved.string) # Another approved Translation of an Entity added: update TermTranslation to match the Translation translation_approved_2 = TranslationFactory.create(locale=locale_a, entity=entity, approved=True) entity.reset_term_translation(locale_a) assert entity.term.translations.filter(locale=locale_a).count() == 1 assert (entity.term.translations.get( locale=locale_a).text == translation_approved_2.string)
def test_term_translation(locale_a): """ Find locale translation of the given term. """ term = TermFactory.create(text="term") assert term.translation(locale_a) is None TermTranslationFactory.create( locale=locale_a, term=term, text="translation", ) assert term.translation(locale_a) == "translation" do_not_translate = TermFactory.create(text="term", do_not_translate=True) assert do_not_translate.translation(locale_a) == "term"
def non_localizable_term(): """ This fixture provides a localizable term. """ return TermFactory.create( text="Non-localizable term", do_not_translate=True, )
def localizable_term(_): """ This fixture provides a localizable term. """ return TermFactory.create(text="Localizable term")
def available_terms(_): """This fixture provides: - 4 generic terms - 6 terms to be used for matching in strings """ for i in range(0, 4): TermFactory.create(text="term%s" % i) TermFactory.create(text="abnormality") TermFactory.create(text="student ambassador") TermFactory.create(text="track") TermFactory.create(text="sensitive") TermFactory.create(text="surf") TermFactory.create(text="Channel", case_sensitive=True)