close #472361: omit password and bytes attributes in allowed mass-mailing keys stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 12 Nov 2009 17:15:07 +0100
branchstable
changeset 3830 3b6bbb3a3c3e
parent 3829 9674d62a54f9
child 3831 5eb369d24e7d
close #472361: omit password and bytes attributes in allowed mass-mailing keys by fixing default implementation for allowed_massmail_keys() in the Emailable pluggable mixin (cw.common.mixins). Added test (in entities.test though), also fix CWUserTC classes conflicts in the test module.
common/mixins.py
entities/test/unittest_base.py
--- a/common/mixins.py	Thu Nov 12 13:53:26 2009 +0100
+++ b/common/mixins.py	Thu Nov 12 17:15:07 2009 +0100
@@ -180,7 +180,9 @@
         For instance, the Person class might want to return a `companyname`
         key.
         """
-        return set(rs.type for rs, _ in cls.e_schema.attribute_definitions())
+        return set(rschema.type
+                   for rschema, attrtype in cls.e_schema.attribute_definitions()
+                   if attrtype.type not in ('Password', 'Bytes'))
 
     def as_email_context(self):
         """returns the dictionary as used by the sendmail controller to
--- a/entities/test/unittest_base.py	Thu Nov 12 13:53:26 2009 +0100
+++ b/entities/test/unittest_base.py	Thu Nov 12 17:15:07 2009 +0100
@@ -45,18 +45,6 @@
                           {'description_format': ('format', 'description')})
 
 
-class CWUserTC(BaseEntityTC):
-    def test_dc_title_and_name(self):
-        e = self.entity('CWUser U WHERE U login "member"')
-        self.assertEquals(e.dc_title(), 'member')
-        self.assertEquals(e.name(), 'member')
-        self.execute(u'SET X firstname "bouah" WHERE X is CWUser, X login "member"')
-        self.assertEquals(e.dc_title(), 'member')
-        self.assertEquals(e.name(), u'bouah')
-        self.execute(u'SET X surname "lôt" WHERE X is CWUser, X login "member"')
-        self.assertEquals(e.dc_title(), 'member')
-        self.assertEquals(e.name(), u'bouah lôt')
-
 class EmailAddressTC(BaseEntityTC):
     def test_canonical_form(self):
         email1 = self.execute('INSERT EmailAddress X: X address "maarten.ter.huurne@philips.com"').get_entity(0, 0)
@@ -94,6 +82,25 @@
         self.failUnless(e.matching_groups(('xyz', 'managers')))
         self.failIf(e.matching_groups(('xyz', 'abcd')))
 
+    def test_dc_title_and_name(self):
+        e = self.entity('CWUser U WHERE U login "member"')
+        self.assertEquals(e.dc_title(), 'member')
+        self.assertEquals(e.name(), 'member')
+        e.set_attributes(firstname=u'bouah')
+        self.assertEquals(e.dc_title(), 'member')
+        self.assertEquals(e.name(), u'bouah')
+        e.set_attributes(surname=u'lôt')
+        self.assertEquals(e.dc_title(), 'member')
+        self.assertEquals(e.name(), u'bouah lôt')
+
+    def test_allowed_massmail_keys(self):
+        e = self.entity('CWUser U WHERE U login "member"')
+        # Bytes/Password attributes should be omited
+        self.assertEquals(e.allowed_massmail_keys(),
+                          set(('surname', 'firstname', 'login', 'last_login_time',
+                               'creation_date', 'modification_date', 'cwuri', 'eid'))
+                          )
+
 
 class InterfaceTC(EnvBasedTC):