annotate test/session_common.py @ 6813:6b636fb29740

Refactor client.py session cookie code. Remove session db access. The original code did a session_db.exists test followed by a session_db.getall. Refactor does a getall and if a KeyError is thrown, handles the error. Most likely the session key will be found so exception handling won't be triggered. Added test case to test the exception code path and minor rearrangement of setup code.
author John Rouillard <rouilj@ieee.org>
date Wed, 03 Aug 2022 17:34:58 -0400
parents 375d40a9e730
children 3f60a71b0812
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
1 import os, shutil, time, unittest
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
2
5388
d26921b851c3 Python 3 preparation: make relative imports explicit.
Joseph Myers <jsm@polyomino.org.uk>
parents: 5319
diff changeset
3 from .db_test_base import config
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
4
6808
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
5 """
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
6 here are three different impementations for these. I am trying to fix
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
7 them so they all act the same.
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4386
diff changeset
8
6808
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
9 set with invalid timestamp:
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
10
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
11 session_dbm/memorydb - sets to invalid timestamp if new or existing item.
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
12 session_rdbms - sets to time.time if new item, keeps original
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
13 if item exists. (note that the timestamp is
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
14 a separate column, the timestamp embedded in the
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
15 value object in the db has the bad __timestamp.
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
16 reconciled: set to time.time for new item, keeps original time
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
17 of existing item.
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
18
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
19 Also updateTimestamp does not update the marshalled values idea of
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
20 __timestamp. So get(item, '__timestamp') will not work as expected
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
21 for rdbms backends, need a sql query to get the timestamp column.
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
22
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
23 FIXME need to add getTimestamp method to sessions_rdbms.py and
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
24 sessions_dbm.py.
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
25
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
26 """
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 4386
diff changeset
27 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
28 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
29 # 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
30 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
31 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
32 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
33 self.db = self.module.Database(config, 'admin')
5319
62de601bdf6f Fix commits although a Reject exception is raised
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5033
diff changeset
34 self.sessions = self.db.getSessionManager()
62de601bdf6f Fix commits although a Reject exception is raised
Ralf Schlatterbeck <rsc@runtux.com>
parents: 5033
diff changeset
35 self.otks = self.db.getOTKManager()
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
36
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
37 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
38 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
39 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
40 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
41 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
42
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
43 def testList(self):
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
44 '''Under dbm/memory sessions store, keys are returned as
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
45 byte strings. self.s2b converts string to byte under those
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
46 backends but is a no-op for rdbms based backends.
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
47
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
48 Unknown why keys can be strings not bytes for get/set
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
49 and work correctly.
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
50 '''
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
51 self.sessions.list()
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
52 self.sessions.set('random_key', text='hello, world!')
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
53 self.sessions.set('random_key2', text='hello, world!')
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
54 self.assertEqual(self.sessions.list().sort(),
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
55 [self.s2b('random_key'), self.s2b('random_key2')].sort())
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
56
6808
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
57 def testGetMissingKey(self):
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
58 self.sessions.set('random_key', text='hello, world!', otherval='bar')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
59 with self.assertRaises(KeyError) as e:
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
60 self.sessions.get('badc_key', 'text')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
61
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
62 def testGetAll(self):
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
63 self.sessions.set('random_key', text='hello, world!', otherval='bar')
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
64 self.assertEqual(self.sessions.getall('random_key'),
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
65 {'text': 'hello, world!', 'otherval': 'bar'})
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
66
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
67 def testDestroy(self):
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
68 self.sessions.set('random_key', text='hello, world!')
5794
95a366d46065 Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents: 5388
diff changeset
69 self.assertEqual(self.sessions.getall('random_key'),
4386
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
70 {'text': 'hello, world!'})
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
71 self.sessions.destroy('random_key')
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
72 self.assertRaises(KeyError, self.sessions.getall, 'random_key')
cc33dc9aa3f2 moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents: 2089
diff changeset
73
6808
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
74 def testClear(self):
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
75 self.sessions.set('random_key', text='hello, world!')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
76 self.sessions.set('random_key2', text='hello, world!')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
77 self.sessions.set('random_key3', text='hello, world!')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
78 self.assertEqual(self.sessions.getall('random_key3'),
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
79 {'text': 'hello, world!'})
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
80 self.assertEqual(len(self.sessions.list()), 3)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
81 self.sessions.clear()
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
82 self.assertEqual(len(self.sessions.list()), 0)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
83
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
84 def testSetSession(self):
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
85 self.sessions.set('random_key', text='hello, world!', otherval='bar')
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
86 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
87 'hello, world!')
6802
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
88 self.assertEqual(self.sessions.get('random_key', 'otherval'),
044dcf3608a2 update session db tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
89 'bar')
2082
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
90
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
91 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
92 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
93 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
94 'hello, world!')
c091cacdc505 Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff changeset
95 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
96 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
97
6808
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
98 def testBadTimestamp(self):
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
99 self.sessions.set('random_key',
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
100 text='hello, world!',
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
101 __timestamp='not a timestamp')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
102 ts = self.sessions.get('random_key', '__timestamp')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
103 self.assertNotEqual(ts, 'not a timestamp')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
104 # use {1,7} because db's don't pad the fraction to 7 digits.
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
105 ts_re=r'^[0-9]{10,16}\.[0-9]{1,7}$'
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
106 try:
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
107 self.assertRegex(str(ts), ts_re)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
108 except AttributeError: # 2.7 version
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
109 import warnings
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
110 with warnings.catch_warnings():
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
111 warnings.filterwarnings("ignore",category=DeprecationWarning)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
112 self.assertRegexpMatches(str(ts), ts_re)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
113
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
114 # now update with a bad timestamp, original timestamp should
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
115 # be kept.
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
116 self.sessions.set('random_key',
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
117 text='hello, world2!',
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
118 __timestamp='not a timestamp')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
119 item = self.sessions.get('random_key', "text")
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
120 item_ts = self.sessions.get('random_key', "__timestamp")
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
121 self.assertEqual(item, 'hello, world2!')
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
122 self.assertAlmostEqual(ts, item_ts, 2)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
123
6806
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
124 # overridden in dbm and memory backends
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
125 def testUpdateTimestamp(self):
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
126 def get_ts_via_sql(self):
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
127 sql = '''select %(name)s_time from %(name)ss
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
128 where %(name)s_key = '%(session)s';'''% \
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
129 {'name': self.sessions.name,
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
130 'session': 'random_session'}
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
131
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
132 self.sessions.cursor.execute(sql)
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
133 db_tstamp = self.sessions.cursor.fetchone()
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
134 return db_tstamp
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
135
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
136 # make sure timestamp is older than one minute so update will apply
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
137 timestamp = time.time() - 62
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
138 self.sessions.set('random_session', text='hello, world!',
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
139 __timestamp=timestamp)
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
140
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
141 self.sessions.updateTimestamp('random_session')
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
142 # this doesn't work as the rdbms backends have a
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
143 # session_time, otk_time column and the timestamp in the
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
144 # session marshalled payload isn't updated. The dbm
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
145 # backend does update the __timestamp value so it works
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
146 # for dbm.
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
147 #self.assertNotEqual (self.sessions.get('random_session',
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
148 # '__timestamp'),
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
149 # timestamp)
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
150
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
151 # use 61 to allow a fudge factor
bdd28b244839 - issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents: 6802
diff changeset
152 self.assertGreater(get_ts_via_sql(self)[0] - timestamp, 61)
6808
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
153
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
154 def testLifetime(self):
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
155 ts = self.sessions.lifetime(300)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
156 week_ago = time.time() - 60*60*24*7
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
157 self.assertGreater(week_ago + 302, ts)
375d40a9e730 Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents: 6806
diff changeset
158 self.assertLess(week_ago + 298, ts)

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