Mercurial > p > roundup > code
annotate test/session_common.py @ 8218:32aaf5dc562b
fix(REST): issue2551383; improve errors for bad json, fix PUT docs
While adding fuzz testing for email addresses via REST
/rest/data/user/1/address, I had an error when setting the address to
the same value it currently had. Traced this to a bug in
userauditor.py. Fixed the bug. Documented in upgrading.txt.
While trying to track down issue, I realized invalid json was being
accepted without error. So I fixed the code that parses the json and
have it return an error. Also modified some tests that broke (used
invalid json, or passed body (e.g. DELETE) but shouldn't have. Add
tests for bad json to verify new code.
Fixed test that wasn't initializing the body_file in each loop, so the
test wasn't actually supplying a body.
Also realised PUT documentation was not correct. Output format isn't
quite like GET.
Fuss tests for email address also added.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 17 Dec 2024 19:42:46 -0500 |
| parents | 9347c4a0ecd6 |
| children |
| rev | line source |
|---|---|
| 6802 | 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 """ |
|
6823
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
27 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
28 import pytest, sys |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
29 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
30 _py3 = sys.version_info[0] > 2 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
31 if _py3: |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
32 skip_py2 = lambda func, *args, **kwargs: func |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
33 else: |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
34 from .pytest_patcher import mark_class |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
35 skip_py2 = mark_class(pytest.mark.skip( |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
36 reason="Skipping log test, test doesn't work on python2")) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
37 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
38 |
|
5033
63c79c0992ae
Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents:
4386
diff
changeset
|
39 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
|
40 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
|
41 # 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 self.sessions = self.db.getSessionManager() |
|
62de601bdf6f
Fix commits although a Reject exception is raised
Ralf Schlatterbeck <rsc@runtux.com>
parents:
5033
diff
changeset
|
47 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
|
48 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 def tearDown(self): |
|
7890
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
50 if hasattr(self, 'sessions'): |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
51 if not hasattr(self.sessions, 'conn'): |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
52 # only do this for file based databases that do not |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
53 # have a conn(ection). If they have a connection |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
54 # mysql throws an error when closing self.db. |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
55 self.sessions.close() |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
56 if hasattr(self, 'otks'): |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
57 if not hasattr(self.otks, 'conn'): |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
58 # only do this for file based databases that do not |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
59 # have a conn(ection). If they have a connection |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
60 # mysql throws an error when closing self.db. |
|
9347c4a0ecd6
test: close session/otks only if local file.
John Rouillard <rouilj@ieee.org>
parents:
7879
diff
changeset
|
61 self.otks.close() |
|
2082
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 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
|
66 |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
67 def testList(self): |
| 6802 | 68 '''Under dbm/memory sessions store, keys are returned as |
| 69 byte strings. self.s2b converts string to byte under those | |
| 70 backends but is a no-op for rdbms based backends. | |
| 71 | |
| 72 Unknown why keys can be strings not bytes for get/set | |
| 73 and work correctly. | |
| 74 ''' | |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
75 self.sessions.list() |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
76 self.sessions.set('random_key', text='hello, world!') |
| 6802 | 77 self.sessions.set('random_key2', text='hello, world!') |
| 78 self.assertEqual(self.sessions.list().sort(), | |
| 79 [self.s2b('random_key'), self.s2b('random_key2')].sort()) | |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
80 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
81 def testGetGetAllMissingKey(self): |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
82 self.assertEqual(self.sessions.get('badc_key', |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
83 'text', 'default_val'), |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
84 'default_val') |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
85 |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
86 with self.assertRaises(KeyError) as e: |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
87 self.sessions.get('badc_key', 'text') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
88 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
89 with self.assertRaises(KeyError) as e: |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
90 self.sessions.getall('badc_key') |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
91 |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
92 def testGetAll(self): |
| 6802 | 93 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
|
94 self.assertEqual(self.sessions.getall('random_key'), |
| 6802 | 95 {'text': 'hello, world!', 'otherval': 'bar'}) |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
96 |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
97 def testDestroy(self): |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
98 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
|
99 self.assertEqual(self.sessions.getall('random_key'), |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
100 {'text': 'hello, world!'}) |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
101 self.sessions.destroy('random_key') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
102 self.assertRaises(KeyError, self.sessions.getall, 'random_key') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
103 |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
104 def testClear(self): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 self.assertEqual(self.sessions.getall('random_key3'), |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
109 {'text': 'hello, world!'}) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
110 self.assertEqual(len(self.sessions.list()), 3) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
111 self.sessions.clear() |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
112 self.assertEqual(len(self.sessions.list()), 0) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
113 |
|
2082
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
114 def testSetSession(self): |
| 6802 | 115 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
|
116 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
|
117 'hello, world!') |
| 6802 | 118 self.assertEqual(self.sessions.get('random_key', 'otherval'), |
| 119 'bar') | |
|
2082
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
120 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 'hello, world!') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
125 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
|
126 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
|
127 |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
128 def testBadTimestamp(self): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
129 self.sessions.set('random_key', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
130 text='hello, world!', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
131 __timestamp='not a timestamp') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
132 ts = self.sessions.get('random_key', '__timestamp') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
133 self.assertNotEqual(ts, 'not a timestamp') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
134 # 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
|
135 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
|
136 try: |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
137 self.assertRegex(str(ts), ts_re) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
138 except AttributeError: # 2.7 version |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
139 import warnings |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
140 with warnings.catch_warnings(): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
141 warnings.filterwarnings("ignore",category=DeprecationWarning) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
142 self.assertRegexpMatches(str(ts), ts_re) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
143 |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
144 # 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
|
145 # be kept. |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
146 self.sessions.set('random_key', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
147 text='hello, world2!', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
148 __timestamp='not a timestamp') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
149 item = self.sessions.get('random_key', "text") |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
150 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
|
151 self.assertEqual(item, 'hello, world2!') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
152 self.assertAlmostEqual(ts, item_ts, 2) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
153 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
154 # overridden in test_memory |
|
6806
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
155 def testUpdateTimestamp(self): |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
156 # make sure timestamp is older than one minute so update |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
157 # will apply |
|
6806
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
158 timestamp = time.time() - 62 |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
159 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
|
160 __timestamp=timestamp) |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
161 |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
162 self.sessions.updateTimestamp('random_session') |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
163 # 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
|
164 # 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
|
165 # 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
|
166 # 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
|
167 # for dbm. |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
168 #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
|
169 # '__timestamp'), |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
170 # timestamp) |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
171 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
172 # use 61 to allow a 1 second delay in test |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
173 self.assertGreater(self.get_ts()[0] - timestamp, 61) |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
174 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
175 # overridden in test_anydbm |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
176 def get_ts(self, key="random_session"): |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
177 sql = '''select %(name)s_time from %(name)ss |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
178 where %(name)s_key = '%(session)s';'''% \ |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
179 {'name': self.sessions.name, |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
180 'session': key} |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
181 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
182 self.sessions.cursor.execute(sql) |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
183 db_tstamp = self.sessions.cursor.fetchone() |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
184 return db_tstamp |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
185 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
186 def testDataTypes(self): |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
187 """make sure all data survives a round trip through the |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
188 session database including data types. |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
189 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
190 Found this was a problem when trying to store the |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
191 data using a redis hash that has no native data types |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
192 for booleans and numbers get returned by redis module |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
193 as strings. |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
194 """ |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
195 in_data = {"text": 'hello, world!', |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
196 "integer": 56, |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
197 "float": 3.1425, |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
198 "list": [ 1, "Two", 3.0, "Four" ], |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
199 "boolean": True, |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
200 "tuple": ("f", 4), |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
201 } |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
202 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
203 self.sessions.set('random_data', **in_data) |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
204 out_data = self.sessions.getall('random_data') |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
205 self.assertEqual(in_data, out_data) |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
206 |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
207 def testLifetime(self): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
208 ts = self.sessions.lifetime(300) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
209 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
|
210 self.assertGreater(week_ago + 302, ts) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
211 self.assertLess(week_ago + 298, ts) |
|
6823
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
212 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
213 def testGetUniqueKey(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
214 # 40 bytes of randomness gets larger when encoded |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
215 key = self.sessions.getUniqueKey() |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
216 self.assertEqual(len(key), 54) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
217 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
218 # length is bytes of randomness |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
219 key = self.sessions.getUniqueKey(length=23) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
220 self.assertEqual(len(key), 31) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
221 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
222 key = self.sessions.getUniqueKey(length=200) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
223 self.assertEqual(len(key), 267) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
224 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
225 def testget_logger(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
226 logger = self.sessions.get_logger() |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
227 # why do rdbms session use session/otk as the table name |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
228 # while dbm uses sessions/otks? In any case check both. |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
229 self.assertIn(logger.name, ["roundup.hyperdb.backends.sessions", |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
230 "roundup.hyperdb.backends.session"]) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
231 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
232 logger = self.otks.get_logger() |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
233 self.assertIn(logger.name, ["roundup.hyperdb.backends.otks", |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
234 "roundup.hyperdb.backends.otk"]) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
235 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
236 def testget_logger_name_test(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
237 self.sessions.name="otks" |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
238 logger = self.sessions.get_logger() |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
239 self.assertEqual(logger.name, "roundup.hyperdb.backends.otks") |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
240 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
241 @skip_py2 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
242 def test_log_warning(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
243 """Only python3 pytest has the right context handler for this, |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
244 so skip this on python2. |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
245 """ |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
246 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
247 self.sessions.name = "newdb" |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
248 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
249 with self.assertLogs(logger="roundup.hyperdb.backends.newdb") as logs: |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
250 self.sessions.log_warning("hello world") |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
251 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
252 self.assertEqual(len(logs.records), 1) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
253 self.assertEqual(logs.records[0].levelname, "WARNING") |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
254 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
255 @skip_py2 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
256 def test_log_info(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
257 """Only python3 pytest has the right context handler for this, |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
258 so skip this on python2. |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
259 """ |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
260 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
261 self.sessions.name = "newdb" |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
262 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
263 with self.assertLogs(logger="roundup.hyperdb.backends.newdb") as logs: |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
264 self.sessions.log_info("hello world") |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
265 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
266 self.assertEqual(len(logs.records), 1) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
267 self.assertEqual(logs.records[0].levelname, "INFO") |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
268 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
269 @skip_py2 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
270 def test_log_debug(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
271 """Only python3 pytest has the right context handler for this, |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
272 so skip this on python2. |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
273 """ |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
274 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
275 self.sessions.name = "newdb" |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
276 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
277 with self.assertLogs(logger="roundup.hyperdb.backends.newdb", |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
278 level='DEBUG') as logs: |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
279 self.sessions.log_debug("hello world") |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
280 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
281 self.assertEqual(len(logs.records), 1) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
282 self.assertEqual(logs.records[0].levelname, "DEBUG") |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
283 |
