changeset 2178:2c7cad827dcb

email and locale fix in determining subscribers
author Ana Balica <ana.balica@gmail.com>
date Wed, 28 Aug 2013 00:07:16 +0300
parents 98af52a80d21
children 4491afa24f1e
files MoinMoin/constants/keys.py MoinMoin/util/_tests/test_subscriptions.py MoinMoin/util/subscriptions.py
diffstat 3 files changed, 31 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/constants/keys.py	Mon Aug 26 19:24:07 2013 +0300
+++ b/MoinMoin/constants/keys.py	Wed Aug 28 00:07:16 2013 +0300
@@ -125,3 +125,6 @@
 ACTION_TRASH = u"TRASH"
 ACTION_COPY = u"COPY"
 ACTION_RENAME = u"RENAME"
+
+# defaul LOCALE key value
+DEFAULT_LOCALE = u"en"
--- a/MoinMoin/util/_tests/test_subscriptions.py	Mon Aug 26 19:24:07 2013 +0300
+++ b/MoinMoin/util/_tests/test_subscriptions.py	Wed Aug 28 00:07:16 2013 +0300
@@ -31,11 +31,19 @@
         users = get_subscribers(self.item)
         assert users == set()
 
-        name = u'baz'
+        name1 = u'baz'
         password = u'password'
-        email = u'baz@example.org'
-        user.create_user(username=name, password=password, email=email, validate=False, locale=u'en')
-        user_ = user.User(name=name, password=password)
+        email1 = u'baz@example.org'
+        name2 = u"bar"
+        email2 = u"bar@example.org"
+        name3 = u"barbaz"
+        email3 = u"barbaz@example.org"
+        user.create_user(username=name1, password=password, email=email1, validate=False, locale=u'en')
+        user1 = user.User(name=name1, password=password)
+        user.create_user(username=name2, password=password, email=email2, validate=False)
+        user2 = user.User(name=name2, password=password)
+        user.create_user(username=name3, password=password, email=email3, locale=u"en")
+        user3 = user.User(name=name3, password=password, email1=email3)
         subscribers = get_subscribers(self.item)
         assert subscribers == set()
 
@@ -48,13 +56,15 @@
             ["{0}:{1}:{2}".format(NAMERE, self.namespace, namere)],
             ["{0}:{1}:{2}".format(NAMEPREFIX, self.namespace, nameprefix)],
         ]
-        expected_name = user_.name0
+        users = [user1, user2, user3]
+        expected_names = {user1.name0, user2.name0}
         for subscriptions in subscription_lists:
-            user_.profile._meta[SUBSCRIPTIONS] = subscriptions
-            user_.save(force=True)
+            for user_ in users:
+                user_.profile._meta[SUBSCRIPTIONS] = subscriptions
+                user_.save(force=True)
             subscribers = get_subscribers(self.item)
-            subscribers_names = [subscriber.name for subscriber in subscribers]
-            assert subscribers_names == [expected_name]
+            subscribers_names = {subscriber.name for subscriber in subscribers}
+            assert subscribers_names == expected_names
 
     def test_get_matched_subscription_patterns(self):
         patterns = get_matched_subscription_patterns(self.item, [])
--- a/MoinMoin/util/subscriptions.py	Mon Aug 26 19:24:07 2013 +0300
+++ b/MoinMoin/util/subscriptions.py	Wed Aug 28 00:07:16 2013 +0300
@@ -13,9 +13,9 @@
 
 from whoosh.query import Term, Or
 
-from MoinMoin.constants.keys import (EMAIL, ITEMID, LATEST_REVS, LOCALE, NAME, NAMERE,
-                                     NAMEPREFIX, NAMESPACE, SUBSCRIPTION_IDS,
-                                     SUBSCRIPTION_PATTERNS, TAGS)
+from MoinMoin.constants.keys import (DEFAULT_LOCALE, EMAIL, EMAIL_UNVALIDATED, ITEMID,
+                                     LATEST_REVS, LOCALE, NAME, NAMERE, NAMEPREFIX,
+                                     NAMESPACE, SUBSCRIPTION_IDS, SUBSCRIPTION_PATTERNS, TAGS)
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
@@ -43,8 +43,12 @@
         subscription_patterns = searcher.lexicon(SUBSCRIPTION_PATTERNS)
         patterns = get_matched_subscription_patterns(item, subscription_patterns)
         result_iterators.extend(searcher.documents(subscription_patterns=pattern) for pattern in patterns)
-        subscribers = {Subscriber(user[ITEMID], user[NAME][0], user[EMAIL], user[LOCALE])
-                       for user in chain.from_iterable(result_iterators)}
+        subscribers = set()
+        for user in chain.from_iterable(result_iterators):
+            email = user.get(EMAIL)
+            if email:
+                locale = user.get(LOCALE, DEFAULT_LOCALE)
+                subscribers.add(Subscriber(user[ITEMID], user[NAME][0], email, locale))
     return subscribers