[fix] [test] [translation]

This commit is contained in:
Rushabh Mehta 2016-08-24 14:37:52 +05:30
parent 3cd030df2a
commit cdac8794b9
4 changed files with 61 additions and 64 deletions

View file

@ -9,6 +9,9 @@ import unittest
from frappe import _
class TestTranslation(unittest.TestCase):
def setUp(self):
frappe.db.sql('delete from tabTranslation')
def tearDown(self):
frappe.local.lang = 'en'
frappe.local.lang_full_dict=None
@ -19,11 +22,40 @@ class TestTranslation(unittest.TestCase):
frappe.local.lang = key
frappe.local.lang_full_dict=None
translation = create_translation(key, val)
self.assertEquals(_(translation.source_name), val[1])
self.assertEquals(_(val[0]), val[1])
frappe.delete_doc('Translation', translation.name)
frappe.local.lang_full_dict=None
self.assertEquals(_(translation.source_name), val[0])
self.assertEquals(_(val[0]), val[0])
def test_parent_language(self):
data = [
['es', ['Test Data', 'datos de prueba']],
['es', ['Test Spanish', 'prueba de español']],
['es-MX', ['Test Data', 'pruebas de datos']]
]
for key, val in data:
create_translation(key, val)
frappe.local.lang = 'es'
frappe.local.lang_full_dict=None
self.assertTrue(_(data[0][0]), data[0][1])
frappe.local.lang_full_dict=None
self.assertTrue(_(data[1][0]), data[1][1])
frappe.local.lang = 'es-MX'
# different translation for es-MX
frappe.local.lang_full_dict=None
self.assertTrue(_(data[2][0]), data[2][1])
# from spanish (general)
frappe.local.lang_full_dict=None
self.assertTrue(_(data[1][0]), data[1][1])
def get_translation_data():
html_source_data = """ <font color="#848484" face="arial, tahoma, verdana, sans-serif">
@ -34,6 +66,7 @@ def get_translation_data():
return {'hr': ['Test data', 'Testdaten'],
'ms': ['Test Data','ujian Data'],
'et': ['Test Data', 'testandmed'],
'es': ['Test Data', 'datos de prueba'],
'en': ['Quotation', 'Tax Invoice'],
'fi': [html_source_data, html_translated_data]}

View file

@ -3,70 +3,22 @@
"allow_import": 1,
"allow_rename": 0,
"autoname": "",
"beta": 0,
"creation": "2016-02-17 12:21:16.175465",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "Setup",
"editable_grid": 0,
"fields": [
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"default": "",
"fieldname": "language",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Language",
"length": 0,
"no_copy": 0,
"options": "",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_3",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "en",
"fieldname": "language_code",
"fieldtype": "Data",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@ -75,6 +27,7 @@
"label": "Language Code",
"length": 0,
"no_copy": 0,
"options": "Language",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -90,6 +43,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "section_break_4",
"fieldtype": "Section Break",
"hidden": 0,
@ -114,6 +68,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"description": "If your data is in HTML, please copy paste the exact HTML code with the tags.",
"fieldname": "source_name",
"fieldtype": "Code",
@ -140,6 +95,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_6",
"fieldtype": "Column Break",
"hidden": 0,
@ -164,13 +120,14 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "target_name",
"fieldtype": "Code",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_list_view": 1,
"label": "Translated",
"length": 0,
"no_copy": 0,
@ -189,13 +146,14 @@
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-03-04 15:42:07.020950",
"modified": "2016-08-24 03:48:55.525143",
"modified_by": "Administrator",
"module": "Core",
"name": "Translation",
@ -223,9 +181,11 @@
"write": 1
}
],
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "language_code"
"title_field": "source_name",
"track_seen": 0
}

View file

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
import unittest, json
import unittest, json, sys
import xmlrunner
import importlib
from frappe.modules import load_doctype_module, get_module_name
@ -31,8 +31,8 @@ def main(app=None, module=None, doctype=None, verbose=False, tests=(), force=Fal
unittest_runner = xmlrunner_wrapper(xmloutput_fh)
else:
unittest_runner = unittest.TextTestRunner
try:
try:
frappe.flags.print_messages = verbose
frappe.flags.in_test = True
@ -116,6 +116,10 @@ def run_all_tests(app=None, verbose=False, profile=False):
def run_tests_for_doctype(doctype, verbose=False, tests=(), force=False, profile=False):
module = frappe.db.get_value("DocType", doctype, "module")
if not module:
print 'Invalid doctype {0}'.format(doctype)
sys.exit(1)
test_module = get_module_name(doctype, module, "test_")
if force:
for name in frappe.db.sql_list("select name from `tab%s`" % doctype):
@ -160,7 +164,7 @@ def _run_unittest(module, verbose=False, tests=(), profile=False):
def _add_test(app, path, filename, verbose, test_suite=None):
import os, imp
import os
if os.path.sep.join(["doctype", "doctype", "boilerplate"]) in path:
# in /doctype/doctype/boilerplate/

View file

@ -168,7 +168,7 @@ def get_full_dict(lang):
:param lang: Language Code, e.g. `hi`
"""
if not lang or lang=='en':
if not lang:
return {}
# found in local, return!
@ -201,7 +201,7 @@ def load_lang(lang, apps=None):
out = {}
for app in (apps or frappe.get_all_apps(True)):
path = os.path.join(frappe.get_pymodule_path(app), "translations", lang + ".csv")
out.update(get_translation_dict_from_file(path, lang, app))
out.update(get_translation_dict_from_file(path, lang, app) or {})
if '-' in lang:
parent = lang.split('-')[0]
@ -209,7 +209,7 @@ def load_lang(lang, apps=None):
frappe.cache().hset("lang_full_dict", lang, out)
return out
return out or {}
def get_translation_dict_from_file(path, lang, app):
"""load translation dict from given path"""