annotate test/session_common.py @ 5123:226052e0cc4c

Fixed incorrect header comparisons in compareMessages. It iterated over every header in the new message and didn't detect when the new message was missing a header that was in the reference message. I have fixed that by retrieving all header names from the new and reference (old) messages, lower casing the list and comparing them (with a fixup for the x-roundup-version header). If the list of headers isn't identical, I throw an error. Also the Content-Type mime values are now being compared as well to make sure the new message being generates matches the reference mime content type. Of course this broke some tests. A number of them were using compareMessages when they should have been using assertEqual. That was an easy fix. Also some messages when retrieved from the content property are missing trailing newlines. I think this is part of the signature removal algorithm. This may be a bug or intended. In any case I am fixing the tests to remove trailing newlines. However I have a handful of tests that are not that obvious. Two of are test_mailgw.py:testMultipartCharsetLatin1AttachFile test_mailgw.py:testMultipartCharsetUTF8AttachFile I removed a: Content-Transfer-Encoding: quoted-printable message header from the reference message in both cases. The message content-type was multipart/mixed and it had no content that was outside of a mime part. Sending a message like this using mailx and nmh resulted in an email being delivered that was missing a Content-Transfer-Encoding, so I think I am ok here. The last broken test also started as a missing Content-Transfer-Encoding header. But there was a twist: test-mailgw.py:testMultipartRFC822 had a reference copy with a mime type of text/plain which requires a Content-Transfer-Encoding. However I never looked at the mime type of the mail being generated. The generated mail was of type multipart/mixed. So I changed the reference copy to remove the Content-Transfer-Encoding and changed the reference mime type to multipart/mixed. Now all the mailgw tests are passing. With luck I haven't encoded an invalid test. Also did one minor spelling correction.
author John Rouillard <rouilj@ieee.org>
date Sun, 03 Jul 2016 18:54:18 -0400
parents 63c79c0992ae
children 62de601bdf6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
1 import os, shutil, unittest
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
3 from db_test_base import config
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4386
diff changeset
5
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4386
diff changeset
6 class SessionTest(object):
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
7 def setUp(self):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
8 # remove previous test, ignore errors
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
9 if os.path.exists(config.DATABASE):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
10 shutil.rmtree(config.DATABASE)
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
11 os.makedirs(config.DATABASE + '/files')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
12 self.db = self.module.Database(config, 'admin')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
13 self.sessions = self.sessions_module.Sessions(self.db)
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
14 self.otks = self.sessions_module.OneTimeKeys(self.db)
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
15
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
16 def tearDown(self):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
17 del self.otks
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
18 del self.sessions
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
19 if hasattr(self, 'db'):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
20 self.db.close()
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
21 if os.path.exists(config.DATABASE):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
22 shutil.rmtree(config.DATABASE)
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
23
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
24 def testList(self):
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
25 self.sessions.list()
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
26 self.sessions.set('random_key', text='hello, world!')
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
27 self.sessions.list()
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
28
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
29 def testGetAll(self):
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
30 self.sessions.set('random_key', text='hello, world!')
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
31 self.assertEqual(self.sessions.getall('random_key'),
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
32 {'text': 'hello, world!'})
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
33
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
34 def testDestroy(self):
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
35 self.sessions.set('random_key', text='hello, world!')
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
36 self.assertEquals(self.sessions.getall('random_key'),
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
37 {'text': 'hello, world!'})
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
38 self.sessions.destroy('random_key')
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
39 self.assertRaises(KeyError, self.sessions.getall, 'random_key')
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
40
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
41 def testSetSession(self):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
42 self.sessions.set('random_key', text='hello, world!')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
43 self.assertEqual(self.sessions.get('random_key', 'text'),
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
44 'hello, world!')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
45
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
46 def testUpdateSession(self):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
47 self.sessions.set('random_key', text='hello, world!')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
48 self.assertEqual(self.sessions.get('random_key', 'text'),
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
49 'hello, world!')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
50 self.sessions.set('random_key', text='nope')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
51 self.assertEqual(self.sessions.get('random_key', 'text'), 'nope')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
52
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
53 class DBMTest(SessionTest):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
54 import roundup.backends.sessions_dbm as sessions_module
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
55
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
56 class RDBMSTest(SessionTest):
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
57 import roundup.backends.sessions_rdbms as sessions_module
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
58

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