Changeset 1186 in main


Ignore:
Timestamp:
06/07/12 07:53:16 (7 years ago)
Author:
pcosquer
Message:

invitation: fix tests when the environment variable TEST_TRANS is set to "on"

Location:
trunk/openPLM/plmapp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/mail.py

    r1180 r1186  
    2727users about a changement in a :class:`.PLMObject`. 
    2828""" 
    29 from collections import Iterable, Mapping 
     29from collections import Iterable, Mapping, defaultdict 
    3030 
    3131import kjbuckets 
     
    4141from celery.task import task 
    4242 
    43 from openPLM.plmapp.models import User, DelegationLink, ROLE_OWNER, ROLE_SIGN 
     43from openPLM.plmapp.models import User, UserProfile, DelegationLink, ROLE_OWNER, ROLE_SIGN 
    4444 
    4545 
     
    167167def do_send_mail(subject, recipients, ctx, template, blacklist=()): 
    168168    if recipients: 
    169         from collections import defaultdict 
    170169        lang_to_email = defaultdict(set) 
    171170        if len(recipients) == 1: 
     
    175174            lang_to_email[recipient.get_profile().language].add(recipient.email) 
    176175        else: 
    177             users = User.objects.filter(id__in=recipients).exclude(email="") 
    178             for user in users: 
    179                 if not user.email in blacklist: 
    180                     lang_to_email[user.get_profile().language].add(user.email) 
     176            qs = UserProfile.objects.filter(user__in=recipients).exclude(user__email="") 
     177            for lang, email in qs.values_list("language", "user__email"): 
     178                if email not in blacklist: 
     179                    lang_to_email[lang].add(email) 
    181180            if not lang_to_email: 
    182181                return     
     
    184183        ctx = unserialize(ctx) 
    185184        ctx["site"] = Site.objects.get_current() 
    186  
    187         for lang, emails in lang_to_email.items(): 
     185        for lang, emails in lang_to_email.iteritems(): 
    188186            translation.activate(lang) 
    189187            html_content = render_to_string(template + ".html", ctx) 
     
    195193            msg.send(fail_silently=True) 
    196194         
    197         if lang_to_email.items(): 
     195        if lang_to_email: 
    198196            translation.deactivate() 
    199197 
  • trunk/openPLM/plmapp/tests/views.py

    r1182 r1186  
    22942294        self.assertEqual(self.brian, form.initial["user"]) 
    22952295        self.assertTrue(self.brian.groups.filter(id=self.group.id).exists()) 
    2296         self.assertEqual(1, len(mail.outbox)) 
     2296        if self.LANGUAGE == "en": 
     2297            self.assertEqual(1, len(mail.outbox)) 
     2298        else: 
     2299            # two languages -> two messages  
     2300            self.assertEqual(2, len(mail.outbox)) 
    22972301        # a notification is sent to the owner and to the guest 
    2298         self.assertEqual(set(mail.outbox[0].to),  
    2299                 set([self.user.email, self.brian.email])) 
     2302        recipients = set() 
     2303        for msg in mail.outbox: 
     2304            recipients.update(msg.to) 
     2305        self.assertEqual(recipients, set([self.user.email, self.brian.email])) 
    23002306        inv = m.Invitation.objects.get(group=self.group, 
    23012307                guest=self.brian, owner=self.user) 
Note: See TracChangeset for help on using the changeset viewer.