From be003c355cc9b404e81b4fc0170e1f7213b925a9 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Fri, 6 Apr 2018 08:05:53 +0200 Subject: [PATCH] lingo: activate localization in new invoices notifications command (#23024) --- .../management/commands/notify_new_remote_invoices.py | 2 ++ tests/test_lingo_remote_regie.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/combo/apps/lingo/management/commands/notify_new_remote_invoices.py b/combo/apps/lingo/management/commands/notify_new_remote_invoices.py index 7c6c2625..9bca307f 100644 --- a/combo/apps/lingo/management/commands/notify_new_remote_invoices.py +++ b/combo/apps/lingo/management/commands/notify_new_remote_invoices.py @@ -20,6 +20,7 @@ import logging from django.conf import settings from django.core.management.base import BaseCommand +from django.utils import translation from combo.apps.lingo.models import Regie @@ -30,6 +31,7 @@ class Command(BaseCommand): if not settings.LINGO_INVOICE_NOTIFICATIONS_ENABLED: return logger = logging.getLogger(__name__) + translation.activate(settings.LANGUAGE_CODE) for regie in Regie.objects.exclude(webservice_url=''): try: regie.notify_new_remote_invoices() diff --git a/tests/test_lingo_remote_regie.py b/tests/test_lingo_remote_regie.py index 98381b7a..903b7e57 100644 --- a/tests/test_lingo_remote_regie.py +++ b/tests/test_lingo_remote_regie.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import json import pytest import mock @@ -6,6 +8,7 @@ from decimal import Decimal from requests.exceptions import ConnectionError from django.test.client import RequestFactory +from django.test import override_settings from django.core.urlresolvers import reverse from django.conf import settings from django.core.management import call_command @@ -403,11 +406,13 @@ def test_send_new_remote_invoices_by_email(mock_get, user_saml, admin, app, remo mock_response = mock.Mock(status_code=200, content=json.dumps(FAKE_PENDING_INVOICES)) mock_response.json.return_value = FAKE_PENDING_INVOICES mock_get.return_value = mock_response - remote_regie.notify_new_remote_invoices() + with override_settings(LANGUAGE_CODE='fr'): + call_command('notify_new_remote_invoices') + assert len(mailoutbox) == 1 assert mailoutbox[0].recipients() == ['foo@example.net'] assert mailoutbox[0].from_email == settings.DEFAULT_FROM_EMAIL - assert mailoutbox[0].subject == 'New invoice nr. 01 is available' + assert mailoutbox[0].subject == u'Nouvelle facture numéro 01 disponible' html_message = mailoutbox[0].alternatives[0][0] assert 'Combo' in mailoutbox[0].body assert 'Combo' in html_message