def test_tp_tool_move(language0, project0, templates, no_templates_tps): tp = project0.translationproject_set.get(language=language0) original_stores = list(tp.stores.all()) TPTool(project0).move(tp, templates) assert tp.language == templates assert ( tp.pootle_path == tp.directory.pootle_path == "/%s/%s/" % (templates.code, project0.code)) assert tp.directory.parent == templates.directory # all of the stores and their directories are updated for store in original_stores: store = Store.objects.get(pk=store.pk) assert store.pootle_path.startswith(tp.pootle_path) assert store.parent.pootle_path.startswith(tp.pootle_path) assert not Store.objects.filter( pootle_path__startswith="/%s/%s/" % (language0.code, project0.code)) assert not Directory.objects.filter( pootle_path__startswith="/%s/%s/" % (language0.code, project0.code)) # calling with already set language does nothing assert TPTool(project0).move(tp, templates) is None
def test_tp_tool_update(po_directory, tp0, templates): new_lang = LanguageDBFactory() tp0_tool = TPTool(tp0.project) new_tp = tp0.project.translationproject_set.create( language=new_lang) # this will clone stores/directories as new_tp is empty tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp, update=True) tp0_tool.update_from_tp(tp0, new_tp) tp0.stores.first().delete() tp0.stores.first().units.first().delete() unit = tp0.stores.first().units.first() unit.source = multistring(["NEW TARGET", "NEW TARGETS"]) unit.target = "NEW TARGET" unit.context = "something-else" unit.save() newunit = unit.__class__() newunit.source = multistring(["OTHER NEW TARGET", "OTHER NEW TARGETS"]) newunit.target = "OTHER NEW TARGET" newunit.context = "something-else-again" unit.store.addunit(newunit) tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp, update=True) # doing another update does nothing tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp, update=True)
def test_tp_tool_update(po_directory, tp0, templates): new_lang = LanguageDBFactory() tp0_tool = TPTool(tp0.project) new_tp = tp0.project.translationproject_set.create( language=new_lang) # this will clone stores/directories as new_tp is empty tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp) tp0_tool.update_from_tp(tp0, new_tp) tp0.stores.first().delete() tp0.stores.first().units.first().delete() unit = tp0.stores.first().units.first() unit.source = multistring(["NEW TARGET", "NEW TARGETS"]) unit.target = "NEW TARGET" unit.context = "something-else" unit.save() newunit = unit.__class__() newunit.source = multistring(["OTHER NEW TARGET", "OTHER NEW TARGETS"]) newunit.target = "OTHER NEW TARGET" newunit.context = "something-else-again" unit.store.addunit(newunit) tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp) # doing another update does nothing tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp)
def test_tp_tool_bad(po_directory, tp0, templates, english, no_templates_tps): other_project = ProjectDBFactory(source_language=english) other_tp = TranslationProjectFactory( project=other_project, language=LanguageDBFactory()) tp_tool = TPTool(tp0.project) with pytest.raises(ValueError): tp_tool.check_tp(other_tp) with pytest.raises(ValueError): tp_tool.set_parents(tp0.directory, other_tp.directory) with pytest.raises(ValueError): tp_tool.set_parents(other_tp.directory, tp0.directory) with pytest.raises(ValueError): tp_tool.move(other_tp, templates) with pytest.raises(ValueError): tp_tool.clone(other_tp, templates) with pytest.raises(ValueError): # cant set tp to a language if a tp already exists tp_tool.move( tp0, Language.objects.get(code="language1")) with pytest.raises(ValueError): # cant clone tp to a language if a tp already exists tp_tool.clone( tp0, Language.objects.get(code="language1"))
def test_tp_tool_clone_project_same_lang(tp0, english): new_proj = ProjectDBFactory(source_language=english) tp_tool = TPTool(tp0.project) _test_tp_match( tp0, tp_tool.clone(tp0, tp0.language, new_proj), new_proj)
def test_tp_tool_clone_project(tp0, project1, member): new_lang = LanguageDBFactory() tp_tool = TPTool(tp0.project) _test_tp_match( tp0, tp_tool.clone(tp0, new_lang, project1), project1)
def test_tp_tool_move_project(language0, project0, project1, templates, no_templates_tps): tp = project0.translationproject_set.get(language=language0) original_stores = list(tp.stores.all()) TPTool(project0).move(tp, templates, project1) assert tp.language == templates assert ( tp.pootle_path == tp.directory.pootle_path == "/%s/%s/" % (templates.code, project1.code)) assert tp.directory.parent == templates.directory # all of the stores and their directories are updated for store in original_stores: store.refresh_from_db() assert store.pootle_path.startswith(tp.pootle_path) assert store.parent.pootle_path.startswith(tp.pootle_path) assert not Store.objects.filter( pootle_path__startswith="/%s/%s" % (language0.code, project0.code)) assert not Directory.objects.filter( pootle_path__startswith="/%s/%s/" % (language0.code, project0.code))
def test_tp_tool_update(po_directory, tp0, templates): new_lang = LanguageDBFactory() tp0_tool = TPTool(tp0.project) new_tp = tp0.project.translationproject_set.create(language=new_lang) # this will clone stores/directories as new_tp is empty tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp) tp0_tool.update_from_tp(tp0, new_tp) tp0.stores.first().delete() tp0.stores.first().units.first().delete() unit = tp0.stores.first().units.first() unit.target = "NEW TARGET" unit.save() tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp) # doing another update does nothing tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp)
def test_tp_tool_update(tp0, templates): new_lang = LanguageDBFactory() tp0_tool = TPTool(tp0.project) new_tp = tp0.project.translationproject_set.create( language=new_lang) # this will clone stores/directories as new_tp is empty tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp) tp0_tool.update_from_tp(tp0, new_tp) tp0.stores.first().delete() tp0.stores.first().units.first().delete() unit = tp0.stores.first().units.first() unit.target = "NEW TARGET" unit.save() tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp) # doing another update does nothing tp0_tool.update_from_tp(tp0, new_tp) _test_tp_match(tp0, new_tp)
def test_tp_tool_clone(po_directory, tp0, templates): new_lang = LanguageDBFactory() tp_tool = TPTool(tp0.project) _test_tp_match(tp0, tp_tool.clone(tp0, new_lang))
def test_tp_tool_clone_project(tp0, project1, member): new_lang = LanguageDBFactory() tp_tool = TPTool(tp0.project) Unit.objects.filter(store__translation_project=tp0).update( created_by=member) _test_tp_match(tp0, tp_tool.clone(tp0, new_lang, project1), project1)