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
+
+
[email protected](
+ "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?
I have written it with copilot, and didn't run it on my local as I don't
have the project up and ready on my system currently. Please let me know if it
needs any additional change.
If seems fine, I would be glad if I get your additional approval on this PR.
Would be my first contribution ever :D
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]