def test_request_language_resolution_with_request_header(self): """Test for frappe.translate.get_language Case 5: frappe.form_dict._lang & preferred_language cookie is not set, but Accept-Language header is """ set_request(method="POST", path="/", headers=[("Accept-Language", third_lang)]) return_val = get_language() self.assertNotIn(return_val, [third_lang, get_parent_language(third_lang)])
def test_guest_request_language_resolution_with_cookie(self): """Test for frappe.translate.get_language Case 3: frappe.form_dict._lang is not set, but preferred_language cookie is [Guest User] """ with patch.object(frappe.translate, "get_preferred_language_cookie", return_value=second_lang): set_request(method="POST", path="/", headers=[("Accept-Language", third_lang)]) return_val = get_language() self.assertIn(return_val, [second_lang, get_parent_language(second_lang)])
def test_request_language_resolution_with_cookie(self): """Test for frappe.translate.get_language Case 2: frappe.form_dict._lang is not set, but preferred_language cookie is """ with patch.object(frappe.translate, "get_preferred_language_cookie", return_value="fr"): set_request(method="POST", path="/", headers=[("Accept-Language", "hr")]) return_val = get_language() # system default language self.assertEqual(return_val, "en") self.assertNotIn(return_val, [second_lang, get_parent_language(second_lang)])
def test_request_language_resolution_with_form_dict(self): """Test for frappe.translate.get_language Case 1: frappe.form_dict._lang is set """ frappe.form_dict._lang = first_lang with patch.object(frappe.translate, "get_preferred_language_cookie", return_value=second_lang): return_val = get_language() self.assertIn(return_val, [first_lang, get_parent_language(first_lang)])