comparison test/test_mailgw.py @ 4211:61cf00ca920a

Process each message through the mail gateway as a separate transaction. The mail-gateway used to process messages fetched, e.g., via imap in a single big transaction. Now we process each message coming in via the mail-gateway in its own transaction. Regression-tests passed. See also discussion: http://thread.gmane.org/gmane.comp.bug-tracking.roundup.user/9500
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Tue, 14 Jul 2009 09:10:43 +0000
parents 1ebab2e397d0
children 57dfcc824acc
comparison
equal deleted inserted replaced
4202:e47ec982645b 4211:61cf00ca920a
114 self.db = self.instance.open('admin') 114 self.db = self.instance.open('admin')
115 self.chef_id = self.db.user.create(username='Chef', 115 self.chef_id = self.db.user.create(username='Chef',
116 address='chef@bork.bork.bork', realname='Bork, Chef', roles='User') 116 address='chef@bork.bork.bork', realname='Bork, Chef', roles='User')
117 self.richard_id = self.db.user.create(username='richard', 117 self.richard_id = self.db.user.create(username='richard',
118 address='richard@test.test', roles='User') 118 address='richard@test.test', roles='User')
119 self.mary_id = self.db.user.create(username='mary', address='mary@test.test', 119 self.mary_id = self.db.user.create(username='mary',
120 roles='User', realname='Contrary, Mary') 120 address='mary@test.test', roles='User', realname='Contrary, Mary')
121 self.john_id = self.db.user.create(username='john', address='john@test.test', 121 self.john_id = self.db.user.create(username='john',
122 alternate_addresses='jondoe@test.test\njohn.doe@test.test', roles='User', 122 address='john@test.test', roles='User', realname='John Doe',
123 realname='John Doe') 123 alternate_addresses='jondoe@test.test\njohn.doe@test.test')
124 124
125 def tearDown(self): 125 def tearDown(self):
126 if os.path.exists(SENDMAILDEBUG): 126 if os.path.exists(SENDMAILDEBUG):
127 os.remove(SENDMAILDEBUG) 127 os.remove(SENDMAILDEBUG)
128 self.db.close() 128 self.db.close()
130 shutil.rmtree(self.dirname) 130 shutil.rmtree(self.dirname)
131 except OSError, error: 131 except OSError, error:
132 if error.errno not in (errno.ENOENT, errno.ESRCH): raise 132 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
133 133
134 def _handle_mail(self, message): 134 def _handle_mail(self, message):
135 handler = self.instance.MailGW(self.instance, self.db) 135 # handler will open a new db handle. On single-threaded
136 # databases we'll have to close our current connection
137 self.db.commit()
138 self.db.close()
139 handler = self.instance.MailGW(self.instance)
136 handler.trapExceptions = 0 140 handler.trapExceptions = 0
137 ret = handler.main(StringIO(message)) 141 ret = handler.main(StringIO(message))
138 # handler can close the db on us and open a new one 142 # handler had its own database, open new connection
139 self.db = handler.db 143 self.db = self.instance.open('admin')
140 return ret 144 return ret
141 145
142 def _get_mail(self): 146 def _get_mail(self):
143 f = open(SENDMAILDEBUG) 147 f = open(SENDMAILDEBUG)
144 try: 148 try:
547 551
548 def testPropertyChangeOnly(self): 552 def testPropertyChangeOnly(self):
549 self.doNewIssue() 553 self.doNewIssue()
550 oldvalues = self.db.getnode('issue', '1').copy() 554 oldvalues = self.db.getnode('issue', '1').copy()
551 oldvalues['assignedto'] = None 555 oldvalues['assignedto'] = None
556 # reconstruct old behaviour: This would reuse the
557 # database-handle from the doNewIssue above which has committed
558 # as user "Chef". So we close and reopen the db as that user.
559 self.db.close()
560 self.db = self.instance.open('Chef')
552 self.db.issue.set('1', assignedto=self.chef_id) 561 self.db.issue.set('1', assignedto=self.chef_id)
553 self.db.commit() 562 self.db.commit()
554 self.db.issue.nosymessage('1', None, oldvalues) 563 self.db.issue.nosymessage('1', None, oldvalues)
555 564
556 new_mail = "" 565 new_mail = ""
988 997
989 # NO NOSY MESSAGE SHOULD BE SENT! 998 # NO NOSY MESSAGE SHOULD BE SENT!
990 assert not os.path.exists(SENDMAILDEBUG) 999 assert not os.path.exists(SENDMAILDEBUG)
991 1000
992 def testNewUserAuthor(self): 1001 def testNewUserAuthor(self):
993 # first without the permission
994 # heh... just ignore the API for a second ;)
995 self.db.security.role['anonymous'].permissions=[]
996 anonid = self.db.user.lookup('anonymous')
997 self.db.user.set(anonid, roles='Anonymous')
998 1002
999 l = self.db.user.list() 1003 l = self.db.user.list()
1000 l.sort() 1004 l.sort()
1001 message = '''Content-Type: text/plain; 1005 message = '''Content-Type: text/plain;
1002 charset="iso-8859-1" 1006 charset="iso-8859-1"
1005 Message-Id: <dummy_test_message_id> 1009 Message-Id: <dummy_test_message_id>
1006 Subject: [issue] Testing... 1010 Subject: [issue] Testing...
1007 1011
1008 This is a test submission of a new issue. 1012 This is a test submission of a new issue.
1009 ''' 1013 '''
1014 def hook (db, **kw):
1015 ''' set up callback for db open '''
1016 db.security.role['anonymous'].permissions=[]
1017 anonid = db.user.lookup('anonymous')
1018 db.user.set(anonid, roles='Anonymous')
1019 self.instance.schema_hook = hook
1010 try: 1020 try:
1011 self._handle_mail(message) 1021 self._handle_mail(message)
1012 except Unauthorized, value: 1022 except Unauthorized, value:
1013 body_diff = self.compareMessages(str(value), """ 1023 body_diff = self.compareMessages(str(value), """
1014 You are not a registered user. 1024 You are not a registered user.
1019 assert not body_diff, body_diff 1029 assert not body_diff, body_diff
1020 1030
1021 else: 1031 else:
1022 raise AssertionError, "Unathorized not raised when handling mail" 1032 raise AssertionError, "Unathorized not raised when handling mail"
1023 1033
1024 # Add Web Access role to anonymous, and try again to make sure 1034
1025 # we get a "please register at:" message this time. 1035 def hook (db, **kw):
1026 p = [ 1036 ''' set up callback for db open '''
1027 self.db.security.getPermission('Create', 'user'), 1037 # Add Web Access role to anonymous, and try again to make sure
1028 self.db.security.getPermission('Web Access', None), 1038 # we get a "please register at:" message this time.
1029 ] 1039 p = [
1030 1040 db.security.getPermission('Create', 'user'),
1031 self.db.security.role['anonymous'].permissions=p 1041 db.security.getPermission('Web Access', None),
1032 1042 ]
1043 db.security.role['anonymous'].permissions=p
1044 self.instance.schema_hook = hook
1033 try: 1045 try:
1034 self._handle_mail(message) 1046 self._handle_mail(message)
1035 except Unauthorized, value: 1047 except Unauthorized, value:
1036 body_diff = self.compareMessages(str(value), """ 1048 body_diff = self.compareMessages(str(value), """
1037 You are not a registered user. Please register at: 1049 You are not a registered user. Please register at:
1051 # Make sure list of users is the same as before. 1063 # Make sure list of users is the same as before.
1052 m = self.db.user.list() 1064 m = self.db.user.list()
1053 m.sort() 1065 m.sort()
1054 self.assertEqual(l, m) 1066 self.assertEqual(l, m)
1055 1067
1056 # now with the permission 1068 def hook (db, **kw):
1057 p = [ 1069 ''' set up callback for db open '''
1058 self.db.security.getPermission('Create', 'user'), 1070 # now with the permission
1059 self.db.security.getPermission('Email Access', None), 1071 p = [
1060 ] 1072 db.security.getPermission('Create', 'user'),
1061 self.db.security.role['anonymous'].permissions=p 1073 db.security.getPermission('Email Access', None),
1074 ]
1075 db.security.role['anonymous'].permissions=p
1076 self.instance.schema_hook = hook
1062 self._handle_mail(message) 1077 self._handle_mail(message)
1063 m = self.db.user.list() 1078 m = self.db.user.list()
1064 m.sort() 1079 m.sort()
1065 self.assertNotEqual(l, m) 1080 self.assertNotEqual(l, m)
1066 1081
1074 Message-Id: <dummy_test_message_id> 1089 Message-Id: <dummy_test_message_id>
1075 Subject: [issue] Testing... 1090 Subject: [issue] Testing...
1076 1091
1077 This is a test submission of a new issue. 1092 This is a test submission of a new issue.
1078 ''' 1093 '''
1079 p = [ 1094 def hook (db, **kw):
1080 self.db.security.getPermission('Create', 'user'), 1095 ''' set up callback for db open '''
1081 self.db.security.getPermission('Email Access', None), 1096 p = [
1082 ] 1097 db.security.getPermission('Create', 'user'),
1083 self.db.security.role['anonymous'].permissions=p 1098 db.security.getPermission('Email Access', None),
1099 ]
1100 db.security.role['anonymous'].permissions=p
1101 self.instance.schema_hook = hook
1084 self._handle_mail(message) 1102 self._handle_mail(message)
1085 m = set(self.db.user.list()) 1103 m = set(self.db.user.list())
1086 new = list(m - l)[0] 1104 new = list(m - l)[0]
1087 name = self.db.user.get(new, 'realname') 1105 name = self.db.user.get(new, 'realname')
1088 self.assertEquals(name, 'H€llo') 1106 self.assertEquals(name, 'H€llo')

Roundup Issue Tracker: http://roundup-tracker.org/