浏览代码

test: clear `lang_full_dict` from local cache

(cherry picked from commit 2866721a78)

# Conflicts:
#	frappe/tests/test_translate.py
version-14
Sagar Vora 2 年前
committed by Mergify
父节点
当前提交
c4486246da
共有 2 个文件被更改,包括 22 次插入9 次删除
  1. +13
    -7
      frappe/core/doctype/translation/test_translation.py
  2. +9
    -2
      frappe/tests/test_translate.py

+ 13
- 7
frappe/core/doctype/translation/test_translation.py 查看文件

@@ -12,18 +12,19 @@ class TestTranslation(unittest.TestCase):

def tearDown(self):
frappe.local.lang = "en"
frappe.local.lang_full_dict = None
clear_translation_cache()

def test_doctype(self):
translation_data = get_translation_data()
for key, val in translation_data.items():
frappe.local.lang = key
frappe.local.lang_full_dict = None

clear_translation_cache()
translation = create_translation(key, val)
self.assertEqual(_(val[0]), val[1])

frappe.delete_doc("Translation", translation.name)
frappe.local.lang_full_dict = None
clear_translation_cache()

self.assertEqual(_(val[0]), val[0])

@@ -39,20 +40,20 @@ class TestTranslation(unittest.TestCase):

frappe.local.lang = "es"

frappe.local.lang_full_dict = None
clear_translation_cache()
self.assertTrue(_(data[0][0]), data[0][1])

frappe.local.lang_full_dict = None
clear_translation_cache()
self.assertTrue(_(data[1][0]), data[1][1])

frappe.local.lang = "es-MX"

# different translation for es-MX
frappe.local.lang_full_dict = None
clear_translation_cache()
self.assertTrue(_(data[2][0]), data[2][1])

# from spanish (general)
frappe.local.lang_full_dict = None
clear_translation_cache()
self.assertTrue(_(data[1][0]), data[1][1])

def test_html_content_data_translation(self):
@@ -110,3 +111,8 @@ def create_translation(key, val):
translation.translated_text = val[1]
translation.save()
return translation


def clear_translation_cache():
frappe.local.lang_full_dict = None
frappe.cache().delete_key("lang_full_dict", shared=True)

+ 9
- 2
frappe/tests/test_translate.py 查看文件

@@ -9,6 +9,11 @@ from unittest.mock import patch
import frappe
import frappe.translate
from frappe import _
<<<<<<< HEAD
=======
from frappe.core.doctype.translation.test_translation import clear_translation_cache
from frappe.tests.utils import FrappeTestCase
>>>>>>> 2866721a78 (test: clear `lang_full_dict` from local cache)
from frappe.translate import (
extract_javascript,
extract_messages_from_javascript_code,
@@ -37,13 +42,15 @@ class TestTranslate(unittest.TestCase):
def setUp(self):
if self._testMethodName in self.guest_sessions_required:
frappe.set_user("Guest")
frappe.local.lang_full_dict = None # reset cached translations

clear_translation_cache()

def tearDown(self):
frappe.form_dict.pop("_lang", None)
if self._testMethodName in self.guest_sessions_required:
frappe.set_user("Administrator")
frappe.local.lang_full_dict = None # reset cached translations

clear_translation_cache()

def test_extract_message_from_file(self):
data = frappe.translate.get_messages_from_file(translation_string_file)


正在加载...
取消
保存