Mercurial > p > roundup > code
annotate test/session_common.py @ 6915:9ff091537f43
postgresql native-fts; more indexer tests
1) Make postgresql native-fts actually work.
2) Add simple stopword filtering to sqlite native-fts indexer.
3) Add more tests for indexer_common get_indexer
Details:
1) roundup/backends/indexer_postgresql_fts.py:
ignore ValueError raised if we try to index a string with a null
character in it. This could happen due to an incorrect text/ mime
type on a file that has nulls in it.
Replace ValueError raised by postgresql with customized
IndexerQueryError if a search string has a null in it.
roundup/backends/rdbms_common.py:
Make postgresql native-fts work. When specified it was using using
whatever was returned from get_indexer(). However loading the
native-fts indexer backend failed because there was no connection to
the postgresql database when this call was made.
Simple solution, move the call after the open_connection call in
Database::__init__().
However the open_connection call creates the schema for the
database if it is not there. The schema builds tables for
indexer=native type indexing. As part of the build it looks at the
indexer to see the min/max size of the indexed tokens. No indexer
define, we get a crash.
So it's a a chicken/egg issue. I solved it by setting the indexer
to the Indexer from indexer_common which has the min/max token size
info. I also added a no-op save_indexer to this Indexer class. I
claim save_indexer() isn't needed as a commit() on the db does all
the saving required. Then after open_connection is called, I call
get_indexer to retrieve the correct indexer and
indexer_postgresql_fts woks since the conn connection property is
defined.
roundup/backends/indexer_common.py:
add save_index() method for indexer. It does nothing but is needed
in rdbms backends during schema initialization.
2) roundup/backends/indexer_sqlite_fts.py:
when this indexer is used, the indexer test in DBTest on the word
"the" fail. This is due to missing stopword filtering. Implement
basic stopword filtering for bare stopwords (like 'the') to make the
test pass. Note: this indexer is not currently automatically run by
the CI suite, it was found during manual testing. However there is a
FIXME to extract the indexer tests from DBTest and run it using this
backend.
roundup/configuration.py, roundup/doc/admin_guide.txt:
update doc on stopword use for sqlite native-fts.
test/db_test_base.py:
DBTest::testStringBinary creates a file with nulls in it. It was
breaking postgresql with native-fts indexer. Changed test to assign
mime type application/octet-stream that prevents it from being
processed by any text search indexer.
add test to exclude indexer searching in specific props. This code
path was untested before.
test/test_indexer.py:
add test to call find with no words. Untested code path.
add test to index and find a string with a null \x00 byte. it was
tested inadvertently by testStringBinary but this makes it explicit
and moves it to indexer testing. (one version each for: generic,
postgresql and mysql)
Renamed Get_IndexerAutoSelectTest to Get_IndexerTest and renamed
autoselect tests to include autoselect. Added tests for an invalid
indexer and using native-fts with anydbm (unsupported combo) to make
sure the code does something useful if the validation in
configuration.py is broken.
test/test_liveserver.py:
add test to load an issue
add test using text search (fts) to find the issue
add tests to find issue using postgresql native-fts
test/test_postgresql.py, test/test_sqlite.py:
added explanation on how to setup integration test using native-fts.
added code to clean up test environment if native-fts test is run.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 05 Sep 2022 16:25:20 -0400 |
| parents | fe0091279f50 |
| children | 39c482e6a246 |
| 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): |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 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
|
54 |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
55 def testList(self): |
| 6802 | 56 '''Under dbm/memory sessions store, keys are returned as |
| 57 byte strings. self.s2b converts string to byte under those | |
| 58 backends but is a no-op for rdbms based backends. | |
| 59 | |
| 60 Unknown why keys can be strings not bytes for get/set | |
| 61 and work correctly. | |
| 62 ''' | |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
63 self.sessions.list() |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
64 self.sessions.set('random_key', text='hello, world!') |
| 6802 | 65 self.sessions.set('random_key2', text='hello, world!') |
| 66 self.assertEqual(self.sessions.list().sort(), | |
| 67 [self.s2b('random_key'), self.s2b('random_key2')].sort()) | |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
68 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
69 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
|
70 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
|
71 '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
|
72 'default_val') |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
73 |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
74 with self.assertRaises(KeyError) as e: |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
75 self.sessions.get('badc_key', 'text') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
76 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
77 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
|
78 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
|
79 |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
80 def testGetAll(self): |
| 6802 | 81 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
|
82 self.assertEqual(self.sessions.getall('random_key'), |
| 6802 | 83 {'text': 'hello, world!', 'otherval': 'bar'}) |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
84 |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
85 def testDestroy(self): |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
86 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
|
87 self.assertEqual(self.sessions.getall('random_key'), |
|
4386
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
88 {'text': 'hello, world!'}) |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
89 self.sessions.destroy('random_key') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
90 self.assertRaises(KeyError, self.sessions.getall, 'random_key') |
|
cc33dc9aa3f2
moar test coverage
Richard Jones <richard@users.sourceforge.net>
parents:
2089
diff
changeset
|
91 |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
92 def testClear(self): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 self.assertEqual(self.sessions.getall('random_key3'), |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
97 {'text': 'hello, world!'}) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
98 self.assertEqual(len(self.sessions.list()), 3) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
99 self.sessions.clear() |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
100 self.assertEqual(len(self.sessions.list()), 0) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
101 |
|
2082
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
102 def testSetSession(self): |
| 6802 | 103 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
|
104 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
|
105 'hello, world!') |
| 6802 | 106 self.assertEqual(self.sessions.get('random_key', 'otherval'), |
| 107 'bar') | |
|
2082
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
108 |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 'hello, world!') |
|
c091cacdc505
Finished implementation of session and one-time-key stores for RDBMS backends.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
113 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
|
114 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
|
115 |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
116 def testBadTimestamp(self): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
117 self.sessions.set('random_key', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
118 text='hello, world!', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
119 __timestamp='not a timestamp') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
120 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.assertNotEqual(ts, 'not a timestamp') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
122 # 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
|
123 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
|
124 try: |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
125 self.assertRegex(str(ts), ts_re) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
126 except AttributeError: # 2.7 version |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
127 import warnings |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
128 with warnings.catch_warnings(): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
129 warnings.filterwarnings("ignore",category=DeprecationWarning) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
130 self.assertRegexpMatches(str(ts), ts_re) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
131 |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
132 # 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
|
133 # be kept. |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
134 self.sessions.set('random_key', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
135 text='hello, world2!', |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
136 __timestamp='not a timestamp') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
137 item = self.sessions.get('random_key', "text") |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
138 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
|
139 self.assertEqual(item, 'hello, world2!') |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
140 self.assertAlmostEqual(ts, item_ts, 2) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
141 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
142 # overridden in test_memory |
|
6806
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
143 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
|
144 # 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
|
145 # will apply |
|
6806
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
146 timestamp = time.time() - 62 |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
147 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
|
148 __timestamp=timestamp) |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
149 |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
150 self.sessions.updateTimestamp('random_session') |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
151 # 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
|
152 # 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
|
153 # 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
|
154 # 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
|
155 # for dbm. |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
156 #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
|
157 # '__timestamp'), |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
158 # timestamp) |
|
bdd28b244839
- issue2551223 - fix timestamp truncation in mysql and postgresql
John Rouillard <rouilj@ieee.org>
parents:
6802
diff
changeset
|
159 |
|
6814
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
160 # 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
|
161 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
|
162 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
163 # 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
|
164 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
|
165 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
|
166 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
|
167 {'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
|
168 'session': key} |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
169 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
174 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
|
175 """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
|
176 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
|
177 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 as strings. |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
182 """ |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
183 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
|
184 "integer": 56, |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
185 "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
|
186 "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
|
187 "boolean": True, |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
188 "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
|
189 } |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
190 |
|
3f60a71b0812
Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents:
6808
diff
changeset
|
191 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
|
192 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
|
193 self.assertEqual(in_data, out_data) |
|
6808
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
194 |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
195 def testLifetime(self): |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
196 ts = self.sessions.lifetime(300) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
197 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
|
198 self.assertGreater(week_ago + 302, ts) |
|
375d40a9e730
Add tests to BasicDatabase and merge implementations
John Rouillard <rouilj@ieee.org>
parents:
6806
diff
changeset
|
199 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
|
200 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
201 def testGetUniqueKey(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
202 # 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
|
203 key = self.sessions.getUniqueKey() |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
204 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
|
205 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
206 # 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
|
207 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
|
208 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
|
209 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
210 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
|
211 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
|
212 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
213 def testget_logger(self): |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
214 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
|
215 # 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
|
216 # 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
|
217 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
|
218 "roundup.hyperdb.backends.session"]) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
219 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
220 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
|
221 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
|
222 "roundup.hyperdb.backends.otk"]) |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
223 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
224 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
|
225 self.sessions.name="otks" |
|
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 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
|
228 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
229 @skip_py2 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
230 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
|
231 """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
|
232 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
|
233 """ |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
234 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
235 self.sessions.name = "newdb" |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
236 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
237 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
|
238 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
|
239 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
240 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
|
241 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
|
242 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
243 @skip_py2 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
244 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
|
245 """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
|
246 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
|
247 """ |
|
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 self.sessions.name = "newdb" |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
250 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
251 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
|
252 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
|
253 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
254 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
|
255 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
|
256 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
257 @skip_py2 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
258 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
|
259 """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
|
260 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
|
261 """ |
|
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 self.sessions.name = "newdb" |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
264 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
265 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
|
266 level='DEBUG') as logs: |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
267 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
|
268 |
|
fe0091279f50
Refactor session db logging and key generation for sessions/otks
John Rouillard <rouilj@ieee.org>
parents:
6814
diff
changeset
|
269 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
|
270 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
|
271 |
