You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "ceenayekta (via GitHub)" <gi...@apache.org> on 2026/05/09 15:48:04 UTC

Re: [PR] fix: localization of humanize naturaltime [superset]

ceenayekta commented on code in PR #33189:
URL: https://github.com/apache/superset/pull/33189#discussion_r2278888916


##########
tests/unit_tests/utils/test_core.py:
##########
@@ -1122,3 +1125,26 @@ def test_get_stacktrace():
     except Exception:
         stacktrace = get_stacktrace()
         assert stacktrace is None
+
+
+@pytest.mark.parametrize(
+    "mock_locale,expected_phrase",
+    [
+        ("en", "a day ago"),
+        ("fr", "il y a 1 jour"),
+        ("es", "hace 1 día"),
+        ("xx", "a day ago"),
+    ],
+)
+def test_activate_humanize_locale_changes_naturaltime(mock_locale, expected_phrase):
+    """
+    Test that activate_humanize_locale sets the correct locale for humanize.naturaltime.
+    This test mocks flask_babel.get_locale to simulate different user locales and checks
+    that humanize.naturaltime returns the expected translation for '1 day ago'.
+    """
+    with patch("superset.utils.core.get_locale", return_value=mock_locale), \
+        patch.dict("superset.utils.core.LOCALES_LANGUAGE_MAP", {"en": "en_US", "fr": "fr_FR", "es": "es_ES"}):
+        activate_humanize_locale()
+        result = humanize.naturaltime(datetime.now() - timedelta(days=1))
+        assert expected_phrase.lower() in result.lower()
+

Review Comment:
   @Quatters will this method satisfy the requirements?
   
   If seems fine, I would be glad if I get your additional approval on this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org