annotate test/test_config.py @ 8446:14c7c07b32d8

feature: add thread local trace_id and trace_reason to logging. Added trace_id to default logging so that all logs for a given request share the same trace_id. This allows correlation of logs across a request. admin_guide.txt, upgrading.txt: add docs update sample configs to include trace_id. rewrite logging docs in admin_guide. Hopefully they are clearer now. clean up some stuff in the logging config file docs. admin.py: add decorators to run_command to enable trace_id. change calls to db.commit() to use run_command to get trace_id. configuration.py: clean up imports. update docstrings, comments and inline docs. add trace_id to default log format. add function for testing decorated with trace_id. add support for dumping stack trace in logging. add check for pytest in sys.modules to enable log propagation when pytest is running. Otherwise tests fail as the caplog logger doesn't see the roundup logs. logcontext.py: new file to handle thread local contextvar mangement. mailgw.py: add decorators for trace_id etc. scripts/roundup_xlmrpc_server.py: add decorators for trace_id etc. fix encoding bug turning bytes into a string. fix command line issue where we can't set encoding. (not sure if changing encoding via command line even works) cgi/client.py decorate two entry points for trace_id etc. cgi/wsgi_handler.py: decorate entry point for trace_id etc. test/test_config.py: add test for trace_id in new log format. test various cases for sinfo and errors in formating msg.
author John Rouillard <rouilj@ieee.org>
date Tue, 16 Sep 2025 22:53:00 -0400
parents 39a6825d10ca
children d06be9346c68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
1 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
3 # This module is free software, and you may redistribute it and/or modify
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
4 # under the same terms as Python, so long as this copyright message and
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
5 # disclaimer are retained in their original form.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
6 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
10 # POSSIBILITY OF SUCH DAMAGE.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
11 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
17
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
18 import errno
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
19 import fileinput
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
20 import logging
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
21 import os
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
22 import pytest
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
23 import re
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
24 import shutil
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
25 import sys
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
26 import unittest
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
27
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
28 from os.path import normpath
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
29 from textwrap import dedent
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
30
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
31 from roundup import configuration
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
32 from roundup.backends import get_backend, have_backend
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
33 from roundup.hyperdb import DatabaseError
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
34
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
35 from .db_test_base import config
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
36
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
37 if not have_backend('postgresql'):
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
38 # FIX: workaround for a bug in pytest.mark.skip():
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
39 # https://github.com/pytest-dev/pytest/issues/568
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
40 from .pytest_patcher import mark_class
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
41 skip_postgresql = mark_class(pytest.mark.skip(
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
42 reason='Skipping PostgreSQL tests: backend not available'))
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
43 else:
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
44 try:
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
45 from roundup.backends.back_postgresql import psycopg2, db_command,\
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
46 get_database_schema_names
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
47 db_command(config, 'select 1')
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
48 skip_postgresql = lambda func, *args, **kwargs: func
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
49 except( DatabaseError ) as msg:
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
50 from .pytest_patcher import mark_class
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
51 skip_postgresql = mark_class(pytest.mark.skip(
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
52 reason='Skipping PostgreSQL tests: database not available'))
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
53
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
54
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
55 try:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
56 import xapian
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
57 skip_xapian = lambda func, *args, **kwargs: func
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
58 from .pytest_patcher import mark_class
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
59 include_no_xapian = mark_class(pytest.mark.skip(
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
60 "Skipping missing Xapian indexer tests: 'xapian' is installed"))
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
61 except ImportError:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
62 # FIX: workaround for a bug in pytest.mark.skip():
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
63 # https://github.com/pytest-dev/pytest/issues/568
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
64 from .pytest_patcher import mark_class
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
65 skip_xapian = mark_class(pytest.mark.skip(
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
66 "Skipping Xapian indexer tests: 'xapian' not installed"))
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
67 include_no_xapian = lambda func, *args, **kwargs: func
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
68
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
69
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
70 try:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
71 import redis
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
72 skip_redis = lambda func, *args, **kwargs: func
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
73 except ImportError:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
74 # FIX: workaround for a bug in pytest.mark.skip():
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
75 # https://github.com/pytest-dev/pytest/issues/568
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
76 from .pytest_patcher import mark_class
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
77 skip_redis = mark_class(pytest.mark.skip(
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
78 "Skipping redis tests: 'redis' not installed"))
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
79
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
80 _py3 = sys.version_info[0] > 2
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
81 if _py3:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
82 skip_py2 = lambda func, *args, **kwargs: func
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
83 else:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
84 # FIX: workaround for a bug in pytest.mark.skip():
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
85 # https://github.com/pytest-dev/pytest/issues/568
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
86 from .pytest_patcher import mark_class
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
87 skip_py2 = mark_class(pytest.mark.skip(
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
88 reason='Skipping test under python2.'))
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
89
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
90
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
91 config = configuration.CoreConfig()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
92 config.DATABASE = "db"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
93 config.RDBMS_NAME = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
94 config.RDBMS_HOST = "localhost"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
95 config.RDBMS_USER = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
96 config.RDBMS_PASSWORD = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
97 config.RDBMS_TEMPLATE = "template0"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
98 # these TRACKER_WEB and MAIL_DOMAIN values are used in mailgw tests
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
99 config.MAIL_DOMAIN = "your.tracker.email.domain.example"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
100 config.TRACKER_WEB = "http://tracker.example/cgi-bin/roundup.cgi/bugs/"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
101 # uncomment the following to have excessive debug output from test cases
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
102 # FIXME: tracker logging level should be increased by -v arguments
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
103 # to 'run_tests.py' script
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
104 #config.LOGGING_FILENAME = "/tmp/logfile"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
105 #config.LOGGING_LEVEL = "DEBUG"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
106 config.init_logging()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
107 config.options['FOO'] = "value"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
108
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
109 # for TrackerConfig test class
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
110 from roundup import instance
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
111 from . import db_test_base
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
112
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
113 class ConfigTest(unittest.TestCase):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
114
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
115 def test_badConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
116 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
117 """
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
118 self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName")
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
119
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
120 def test_validConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
121 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
122 """
5794
95a366d46065 Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
123 self.assertEqual(config._get_option("FOO"), "value")
5770
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
124
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
125 def testTrackerWeb(self):
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
126 config = configuration.CoreConfig()
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
127
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
128 self.assertEqual(None,
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
129 config._get_option('TRACKER_WEB').set("http://foo.example/bar/"))
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
130 self.assertEqual(None,
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
131 config._get_option('TRACKER_WEB').set("https://foo.example/bar/"))
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
132
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
133 self.assertRaises(configuration.OptionValueError,
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
134 config._get_option('TRACKER_WEB').set, "https://foo.example/bar")
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
135
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
136 self.assertRaises(configuration.OptionValueError,
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
137 config._get_option('TRACKER_WEB').set, "htt://foo.example/bar/")
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
138
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
139 self.assertRaises(configuration.OptionValueError,
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
140 config._get_option('TRACKER_WEB').set, "htt://foo.example/bar")
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
141
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
142 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
143 config._get_option('TRACKER_WEB').set, "")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
144
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
145 def testRedis_Url(self):
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
146 config = configuration.CoreConfig()
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
147
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
148 with self.assertRaises(configuration.OptionValueError) as cm:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
149 config._get_option('SESSIONDB_REDIS_URL').set(
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
150 "redis://foo.example/bar?decode_responses=False")
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
151 self.assertIn('decode_responses', cm.exception.__str__())
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
152
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
153 config._get_option('SESSIONDB_REDIS_URL').set(
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
154 "redis://localhost:6379/0?health_check_interval=2")
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
155
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
156 def testLoginAttemptsMin(self):
5772
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
157 config = configuration.CoreConfig()
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
158
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
159 self.assertEqual(None,
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
160 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("0"))
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
161 self.assertEqual(None,
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
162 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("200"))
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
163
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
164 self.assertRaises(configuration.OptionValueError,
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
165 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred")
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
166
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
167 self.assertRaises(configuration.OptionValueError,
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
168 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "-1")
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
169
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
170 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
171 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
172
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
173 def testTimeZone(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
174 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
175
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
176 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
177 config._get_option('TIMEZONE').set("0"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
178
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
179 # not a valid timezone
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
180 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
181 config._get_option('TIMEZONE').set, "Zot")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
182
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
183 # 25 is not a valid UTC offset: -12 - +14 is range
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
184 # possibly +/- 1 for DST. But roundup.date doesn't
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
185 # constrain to this range.
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
186 #self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
187 # config._get_option('TIMEZONE').set, "25")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
188
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
189 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
190 import pytz
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
191 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
192 config._get_option('TIMEZONE').set("UTC"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
193 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
194 config._get_option('TIMEZONE').set("America/New_York"))
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
195 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
196 config._get_option('TIMEZONE').set("EST"))
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
197 self.assertRaises(configuration.OptionValueError,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
198 config._get_option('TIMEZONE').set, "Zool/Zot")
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
199
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
200 except ImportError:
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
201 # UTC is a known offset of 0 coded into roundup.date
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
202 # so it works even without pytz.
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
203 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
204 config._get_option('TIMEZONE').set("UTC"))
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
205 # same with EST known timeone offset of 5
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
206 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
207 config._get_option('TIMEZONE').set("EST"))
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
208 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
209 config._get_option('TIMEZONE').set, "America/New_York")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
210
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
211
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
212 def testWebSecretKey(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
213 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
214
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
215 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
216 config._get_option('WEB_SECRET_KEY').set("skskskd"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
217
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
218 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
219 config._get_option('WEB_SECRET_KEY').set, "")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
220
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
221
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
222 def testStaticFiles(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
223 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
224
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
225
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
226 if ("/tmp/bar" == normpath("/tmp/bar/")):
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
227 result_list = ["./foo", "/tmp/bar"]
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
228 else:
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
229 result_list = [".\\foo", "\\tmp\\bar"]
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
230 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
231 config._get_option('STATIC_FILES').set("foo /tmp/bar"))
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
232 print(config.STATIC_FILES)
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
233 self.assertEqual(config.STATIC_FILES, result_list)
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
234
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
235 def testIsolationLevel(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
236 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
237
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
238 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
239 config._get_option('RDBMS_ISOLATION_LEVEL').set("read uncommitted"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
240 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
241 config._get_option('RDBMS_ISOLATION_LEVEL').set("read committed"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
242 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
243 config._get_option('RDBMS_ISOLATION_LEVEL').set("repeatable read"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
244
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
245
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
246 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
247 config._get_option('RDBMS_ISOLATION_LEVEL').set, "not a level")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
248
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
249 def testConfigSave(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
250
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
251 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
252 # make scratch directory to create files in
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
253
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
254 self.startdir = os.getcwd()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
255
7584
a5629f6e7ec2 test: fix mising / in directory spec.
John Rouillard <rouilj@ieee.org>
parents: 7556
diff changeset
256 self.dirname = os.getcwd() + '/_test_config'
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
257 os.mkdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
258
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
259 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
260 os.chdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
261 self.assertFalse(os.access("config.ini", os.F_OK))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
262 self.assertFalse(os.access("config.bak", os.F_OK))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
263 config.save()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
264 config.save() # creates .bak file
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
265 self.assertTrue(os.access("config.ini", os.F_OK))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
266 self.assertTrue(os.access("config.bak", os.F_OK))
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
267 config.save() # trigger delete of old .bak file
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
268 # FIXME: this should test to see if a new .bak
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
269 # was created. For now verify .bak still exists
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
270 self.assertTrue(os.access("config.bak", os.F_OK))
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
271
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
272 self.assertFalse(os.access("foo.bar", os.F_OK))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
273 self.assertFalse(os.access("foo.bak", os.F_OK))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
274 config.save("foo.bar")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
275 config.save("foo.bar") # creates .bak file
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
276 self.assertTrue(os.access("foo.bar", os.F_OK))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
277 self.assertTrue(os.access("foo.bak", os.F_OK))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
278
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
279 finally:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
280 # cleanup scratch directory and files
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
281 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
282 os.chdir(self.startdir)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
283 shutil.rmtree(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
284 except OSError as error:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
285 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
286
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
287 def testFloatAndInt_with_update_option(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
288
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
289 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
290
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
291 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
292 config.update_option('WEB_LOGIN_ATTEMPTS_MIN',
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
293 configuration.IntegerNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
294 "0", description="new desc")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
295
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
296 # -1 is allowed now that it is an int.
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
297 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
298 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("-1"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
299
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
300 # but can't float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
301 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
302 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "2.4")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
303
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
304 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
305 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
306 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
307
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
308 # Update existing IntegerNumberOption to FloatNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
309 config.update_option('WEB_LOGIN_ATTEMPTS_MIN',
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
310 configuration.FloatNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
311 "0.0")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
312
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
313 self.assertEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], -1)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
314
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
315 # can float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
316 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
317 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("3.1415926"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
318
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
319 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
320 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
321 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
322
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
323 self.assertAlmostEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], 3.1415926,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
324 places=6)
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
325
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
326 # test removal of .0 on floats that are integers
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
327 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
328 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("3.0"))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
329
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
330 self.assertEqual("3",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
331 config._get_option('WEB_LOGIN_ATTEMPTS_MIN')._value2str(3.00))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
332
7556
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
333 def testIntegerNumberGtZeroOption(self):
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
334
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
335 config = configuration.CoreConfig()
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
336
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
337 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
338 config.update_option('WEB_LOGIN_ATTEMPTS_MIN',
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
339 configuration.IntegerNumberGtZeroOption,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
340 "1", description="new desc")
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
341
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
342 self.assertEqual(None,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
343 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("1"))
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
344
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
345 # -1 is not allowed
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
346 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
347 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "-1")
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
348
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
349 # but can't float this
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
350 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
351 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "2.4")
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
352
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
353 # but can't float this
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
354 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
355 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "0.5")
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
356
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
357
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
358 def testOriginHeader(self):
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
359 config = configuration.CoreConfig()
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
360
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
361 with self.assertRaises(configuration.OptionValueError) as cm:
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
362 config._get_option('WEB_ALLOWED_API_ORIGINS').set("https://foo.edu *")
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
363
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
364 config._get_option('WEB_ALLOWED_API_ORIGINS').set("* https://foo.edu HTTP://baR.edu")
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
365
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
366 self.assertEqual(config['WEB_ALLOWED_API_ORIGINS'][0], '*')
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
367 self.assertEqual(config['WEB_ALLOWED_API_ORIGINS'][1], 'https://foo.edu')
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
368 self.assertEqual(config['WEB_ALLOWED_API_ORIGINS'][2], 'HTTP://baR.edu')
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
369
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
370
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
371
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
372 def testOptionAsString(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
373
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
374 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
375
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
376 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("2552")
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
377
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
378 v = config._get_option('WEB_LOGIN_ATTEMPTS_MIN').__str__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
379 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
380 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
381
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
382 v = config._get_option('WEB_LOGIN_ATTEMPTS_MIN').__repr__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
383 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
384 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
385
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
386 def testBooleanOption(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
387
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
388 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
389
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
390 with self.assertRaises(configuration.OptionValueError) as cm:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
391 config._get_option('INSTANT_REGISTRATION').set("3")
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
392
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
393 # test multiple boolean representations
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
394 for b in [ "yes", "1", "true", "TRUE", "tRue", "on",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
395 "oN", 1, True ]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
396 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
397 config._get_option('INSTANT_REGISTRATION').set(b))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
398 self.assertEqual(1,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
399 config._get_option('INSTANT_REGISTRATION').get())
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
400
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
401 for b in ["no", "0", "false", "FALSE", "fAlse", "off",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
402 "oFf", 0, False]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
403 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
404 config._get_option('INSTANT_REGISTRATION').set(b))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
405 self.assertEqual(0,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
406 config._get_option('INSTANT_REGISTRATION').get())
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
407
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
408 def testOctalNumberOption(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
409
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
410 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
411
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
412 with self.assertRaises(configuration.OptionValueError) as cm:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
413 config._get_option('UMASK').set("xyzzy")
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
414
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
415 print(type(config._get_option('UMASK')))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
416
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
417
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
418 @pytest.mark.usefixtures("save_restore_logging")
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
419 class TrackerConfig(unittest.TestCase):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
420
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
421 @pytest.fixture(autouse=True)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
422 def inject_fixtures(self, caplog):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
423 self._caplog = caplog
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
424
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
425 @pytest.fixture(scope="class")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
426 def save_restore_logging(self):
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
427 """Save logger state and try to restore it after all tests in
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
428 this class have finished.
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
429
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
430 The primary test is testDictLoggerConfigViaJson which
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
431 can change the loggers and break tests that depend on caplog
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
432 """
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
433 # Save logger state for root and roundup top level logger
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
434 loggernames = ("", "roundup")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
435
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
436 # The state attributes to save. Lists are shallow copied
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
437 state_to_save = ("filters", "handlers", "level", "propagate")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
438
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
439 logger_state = {}
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
440 for name in loggernames:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
441 logger_state[name] = {}
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
442 roundup_logger = logging.getLogger(name)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
443
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
444 for i in state_to_save:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
445 attr = getattr(roundup_logger, i)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
446 if isinstance(attr, list):
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
447 logger_state[name][i] = attr.copy()
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
448 else:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
449 logger_state[name][i] = getattr(roundup_logger, i)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
450
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
451 # run all class tests here
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
452 yield
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
453
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
454 # rip down all the loggers leaving the root logger reporting
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
455 # to stdout.
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
456 # otherwise logger config is leaking to other tests
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
457 roundup_loggers = [logging.getLogger(name) for name in
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
458 logging.root.manager.loggerDict
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
459 if name.startswith("roundup")]
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
460
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
461 # cribbed from configuration.py:init_loggers
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
462 hdlr = logging.StreamHandler(sys.stdout)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
463 formatter = logging.Formatter(
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
464 '%(asctime)s %(levelname)s %(message)s')
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
465 hdlr.setFormatter(formatter)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
466
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
467 for logger in roundup_loggers:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
468 # no logging API to remove all existing handlers!?!
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
469 for h in logger.handlers:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
470 h.close()
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
471 logger.removeHandler(h)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
472 logger.handlers = [hdlr]
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
473 logger.setLevel("WARNING")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
474 logger.propagate = True # important as caplog requires this
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
475
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
476 # Restore the info we stored before running tests
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
477 for name in loggernames:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
478 local_logger = logging.getLogger(name)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
479 for attr in logger_state[name]:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
480 setattr(local_logger, attr, logger_state[name][attr])
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
481
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
482 # reset logging as well
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
483 from importlib import reload
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
484 logging.shutdown()
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
485 reload(logging)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
486
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
487 backend = 'anydbm'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
488
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
489 def setUp(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
490 self.dirname = '_test_instance'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
491 # set up and open a tracker
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
492 self.instance = db_test_base.setupTracker(self.dirname, self.backend)
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
493
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
494 # open the database
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
495 self.db = self.instance.open('admin')
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
496
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
497 self.db.commit()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
498 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
499
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
500 def tearDown(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
501 if self.db:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
502 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
503 try:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
504 shutil.rmtree(self.dirname)
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
505 except OSError as error:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
506 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
507
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
508 def munge_configini(self, mods = None, section=None):
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
509 """ modify config.ini to meet testing requirements
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
510
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
511 mods is a list of tuples:
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
512 [ ( "a = ", "b" ), ("c = ", None), ("d = ", "b", "z = ") ]
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
513 Match line with first tuple element e.g. "a = ". Note specify
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
514 trailing "=" and space to delimit keyword and properly format
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
515 replacement line. If there are two elements in the tuple,
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
516 and the first element matches, the line is
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
517 replaced with the concatenation of the first and second elements.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
518 If second element is None ("" doesn't work), the line will be
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
519 deleted. If there are three elements in the tuple, the line
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
520 is replaced with the contcatentation of the third and second
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
521 elements (used to replace commented out parameters).
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
522
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
523 Note if the key/first element of tuple is not unique in
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
524 config.ini, you must set the section to match the bracketed
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
525 section name.
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
526 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
527
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
528 if mods is None:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
529 return
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
530
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
531 # if section is defined, the tests in the loop will turn
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
532 # it off on [main] if section != '[main]'.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
533 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
534
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
535 for line in fileinput.input(os.path.join(self.dirname, "config.ini"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
536 inplace=True):
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
537 if section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
538 if line.startswith('['):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
539 in_section = False
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
540
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
541 if line.startswith(section):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
542 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
543
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
544 if in_section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
545 for rule in mods:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
546 if len(rule) == 3:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
547 match, value, repl = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
548 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
549 match, value = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
550 repl = None
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
551
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
552 if line.startswith(match):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
553 if value is not None:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
554 if repl:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
555 print(repl + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
556 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
557 print(match + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
558 break
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
559 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
560 print(line[:-1]) # remove trailing \n
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
561 else:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
562 print(line[:-1]) # remove trailing \n
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
563
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
564 def testNoDBInConfig(self):
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
565 """Arguably this should be tested in test_instance since it is
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
566 triggered by instance.open. But it raises an error in the
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
567 configuration module with a missing required param in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
568 config.ini.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
569 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
570
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
571 # remove the backend key in config.ini
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
572 self.munge_configini(mods=[ ("backend = ", None) ])
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
573
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
574 # this should fail as backend isn't defined.
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
575 with self.assertRaises(configuration.OptionUnsetError) as cm:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
576 instance.open(self.dirname)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
577
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
578 self.assertEqual("RDBMS_BACKEND is not set"
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
579 " and has no default", cm.exception.__str__())
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
580
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
581 def testUnsetMailPassword_with_set_username(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
582 """ Set [mail] username but don't set the
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
583 [mail] password. Should get an OptionValueError.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
584 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
585 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
586 self.munge_configini(mods=[ ("username = ", "foo"), ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
587 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
588
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
589 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
590
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
591 with self.assertRaises(configuration.OptionValueError) as cm:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
592 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
593
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
594 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
595 # test repr. The type is right since it passed assertRaises.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
596 self.assertIn("OptionValueError", repr(cm.exception))
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
597 # look for 'not defined'
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
598 self.assertEqual("not defined", cm.exception.args[1])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
599
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
600
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
601 def testUnsetMailPassword_with_unset_username(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
602 """ Set [mail] username but don't set the
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
603 [mail] password. Should get an OptionValueError.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
604 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
605 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
606
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
607 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
608
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
609 self.assertEqual(config['MAIL_USERNAME'], '')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
610
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
611 with self.assertRaises(configuration.OptionUnsetError) as cm:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
612 self.assertEqual(config['MAIL_PASSWORD'], 'NO DEFAULT')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
613
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
614 def testSecretMandatory_missing_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
615
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
616 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
617 self.munge_configini(mods=[ ("secret_key = ", "file://secret_key"), ])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
618
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
619 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
620
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
621 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
622 config.load(self.dirname)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
623
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
624 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
625 self.assertEqual(cm.exception.args[0].setting, "secret_key")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
626
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
627 def testSecretMandatory_load_from_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
628
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
629 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
630 self.munge_configini(mods=[ ("secret_key = ", "file://secret_key"), ])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
631
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
632 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
633 with open(self.dirname + "/secret_key", "w") as f:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
634 f.write(secret + "\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
635
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
636 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
637
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
638 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
639
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
640 self.assertEqual(config['WEB_SECRET_KEY'], secret)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
641
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
642
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
643 def testSecretMandatory_load_from_abs_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
644
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
645 abs_file = "/tmp/secret_key.%s"%os.getpid()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
646
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
647 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
648 self.munge_configini(mods=[ ("secret_key = ", "file://%s"%abs_file), ])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
649
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
650 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
651 with open(abs_file, "w") as f:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
652 f.write(secret + "\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
653
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
654 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
655
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
656 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
657
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
658 self.assertEqual(config['WEB_SECRET_KEY'], secret)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
659
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
660 os.remove(abs_file)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
661
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
662 def testSecretMandatory_empty_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
663
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
664 self.munge_configini(mods=[ ("secret_key = ", "file:// secret_key"), ])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
665
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
666 # file with no value just newline.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
667 with open(self.dirname + "/secret_key", "w") as f:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
668 f.write("\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
669
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
670 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
671
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
672 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
673 config.load(self.dirname)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
674
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
675 print(cm.exception.args)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
676 self.assertEqual(cm.exception.args[2],"Value must not be empty.")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
677
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
678 def testNullableSecret_empty_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
679
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
680 self.munge_configini(mods=[ ("password = ", "file://db_password"), ])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
681
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
682 # file with no value just newline.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
683 with open(self.dirname + "/db_password", "w") as f:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
684 f.write("\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
685
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
686 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
687
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
688 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
689
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
690 v = config['RDBMS_PASSWORD']
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
691
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
692 self.assertEqual(v, None)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
693
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
694 def testNullableSecret_with_file_value(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
695
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
696 self.munge_configini(mods=[ ("password = ", "file://db_password"), ])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
697
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
698 # file with no value just newline.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
699 with open(self.dirname + "/db_password", "w") as f:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
700 f.write("test\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
701
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
702 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
703
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
704 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
705
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
706 v = config['RDBMS_PASSWORD']
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
707
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
708 self.assertEqual(v, "test")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
709
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
710 def testNullableSecret_with_value(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
711
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
712 self.munge_configini(mods=[ ("password = ", "test"), ])
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
713
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
714 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
715
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
716 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
717
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
718 v = config['RDBMS_PASSWORD']
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
719
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
720 self.assertEqual(v, "test")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
721
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
722 def testListSecret_for_jwt_invalid_secret(self):
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
723 """A jwt_secret is made of ',' separated strings.
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
724 If the first string is < 32 characters (like the default
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
725 value of disabled) then jwt is disabled and no harm done.
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
726 If any other secrets are <32 characters we raise a red flag
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
727 on startup to prevent them from being used.
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
728 """
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
729 self.munge_configini(mods=[ ("jwt_secret = ", "disable, test"), ])
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
730
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
731 config = configuration.CoreConfig()
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
732
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
733 with self.assertRaises(configuration.OptionValueError) as cm:
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
734 config.load(self.dirname)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
735
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
736 print(cm.exception.args)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
737 self.assertEqual(
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
738 cm.exception.args[2],
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
739 "One or more secrets less then 32 characters in length\nfound: test")
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
740
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
741 def testSetMailPassword_with_set_username(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
742 """ Set [mail] username and set the password.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
743 Should have both values set.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
744 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
745 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
746 self.munge_configini(mods=[ ("username = ", "foo"),
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
747 ("#password = ", "passwordfoo",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
748 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
749 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
750
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
751 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
752
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
753 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
754
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
755 self.assertEqual(config['MAIL_USERNAME'], 'foo')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
756 self.assertEqual(config['MAIL_PASSWORD'], 'passwordfoo')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
757
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
758 def testSetMailPassword_from_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
759 """ Set [mail] username and set the password.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
760 Should have both values set.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
761 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
762 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
763 self.munge_configini(mods=[ ("username = ", "foo"),
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
764 ("#password = ", "file://password",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
765 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
766 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
767 with open(self.dirname + "/password", "w") as f:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
768 f.write("passwordfoo\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
769
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
770 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
771
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
772 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
773
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
774 self.assertEqual(config['MAIL_USERNAME'], 'foo')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
775 self.assertEqual(config['MAIL_PASSWORD'], 'passwordfoo')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
776
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
777 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
778 def testInvalidIndexerLanguage_w_empty(self):
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
779 """ make sure we have a reasonable error message if
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
780 invalid indexer language is specified. This uses
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
781 default search path for indexers.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
782 """
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
783
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
784 # SETUP: set indexer_language value to an invalid value.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
785 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
786 ("indexer_language = ", "NO_LANG") ])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
787
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
788 config = configuration.CoreConfig()
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
789
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
790 with self.assertRaises(configuration.OptionValueError) as cm:
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
791 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
792
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
793 print(cm.exception)
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
794 # test repr. The type is right since it passed assertRaises.
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
795 self.assertIn("OptionValueError", repr(cm.exception))
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
796 # look for failing language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
797 self.assertIn("NO_LANG", cm.exception.args[1])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
798 # look for supported language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
799 self.assertIn("english", cm.exception.args[2])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
800
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
801 @include_no_xapian
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
802 def testInvalidIndexerLanguage_w_empty_no_xapian(self):
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
803 """ Test case for empty indexer if xapian really isn't installed
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
804
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
805 This should behave like testInvalidIndexerLanguage_xapian_missing
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
806 but without all the sys.modules mangling.
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
807 """
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
808 print("Testing when xapian is not installed")
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
809
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
810 # SETUP: set indexer_language value to an invalid value.
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
811 self.munge_configini(mods=[ ("indexer = ", ""),
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
812 ("indexer_language = ", "NO_LANG") ])
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
813
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
814 config = configuration.CoreConfig()
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
815
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
816 config.load(self.dirname)
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
817
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
818 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
819
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
820 def testInvalidIndexerLanguage_xapian_missing(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
821 """Using default path for indexers, make import of xapian
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
822 fail and prevent exception from happening even though
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
823 the indexer_language would be invalid for xapian.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
824 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
825
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
826 print("Testing xapian not loadable")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
827
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
828 # SETUP: same as testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
829 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
830 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
831
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
832 import sys
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
833 # Set module to Non to prevent xapian from loading
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
834 sys.modules['xapian'] = None
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
835 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
836
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
837 # need to delete both to make python2 not error finding _xapian
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
838 del(sys.modules['xapian'])
6371
5c1db5d4baed Fix failing xapian test
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6368
diff changeset
839 if 'xapian._xapian' in sys.modules:
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
840 del(sys.modules['xapian._xapian'])
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
841
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
842 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
843
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
844 # do a reset here to test reset rather than wasting cycles
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
845 # to do setup in a different test
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
846 config.reset()
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
847 self.assertEqual(config['INDEXER_LANGUAGE'], 'english')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
848
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
849 def testInvalidIndexerLanguage_w_native(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
850 """indexer_language is invalid but indexer is not "" or xapian
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
851 Config load should succeed without exception.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
852 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
853
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
854 print("Testing indexer = native")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
855
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
856 self.munge_configini(mods = [ ("indexer = ", "native"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
857 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
858
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
859 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
860
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
861 self.assertEqual(config['HTML_VERSION'], 'html4')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
862 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
863
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
864 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
865 def testInvalidIndexerLanguage_w_xapian(self):
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
866 """ Use explicit xapian indexer. Verify exception is
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
867 generated.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
868 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
869
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
870 print("Testing explicit xapian")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
871
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
872 self.munge_configini(mods=[ ("indexer = ", "xapian"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
873 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
874
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
875 with self.assertRaises(configuration.OptionValueError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
876 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
877 # don't test exception content. Done in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
878 # testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
879 # if exception not generated assertRaises
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
880 # will generate failure.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
881
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
882 def testInvalidIndexerLanguage_w_native_fts(self):
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
883 """ Use explicit native-fts indexer. Verify exception is
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
884 generated.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
885 """
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
886
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
887 self.munge_configini(mods=[ ("indexer = ", "native-fts"),
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
888 ("indexer_language = ", "NO_LANG") ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
889
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
890 with self.assertRaises(configuration.OptionValueError) as cm:
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
891 config.load(self.dirname)
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
892
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
893 # test repr. The type is right since it passed assertRaises.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
894 self.assertIn("OptionValueError", repr(cm.exception))
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
895 # look for failing language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
896 self.assertIn("NO_LANG", cm.exception.args[1])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
897 # look for supported language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
898 self.assertIn("basque", cm.exception.args[2])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
899
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
900 @skip_redis
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
901 def testLoadSessionDbRedisCompatible(self):
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
902 """ run load to validate config """
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
903
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
904 config = configuration.CoreConfig()
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
905
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
906 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
907 config.RDBMS_BACKEND = "sqlite"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
908 config.SESSIONDB_BACKEND = "redis"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
909
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
910 config.validator(config.options)
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
911
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
912 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
913 config.RDBMS_BACKEND = "anydbm"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
914 config.SESSIONDB_BACKEND = "redis"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
915
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
916 config.validator(config.options)
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
917
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
918 @skip_redis
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
919 @skip_postgresql
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
920 def testLoadSessionDbRedisIncompatible(self):
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
921 """ run load to validate config """
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
922 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
923 config.RDBMS_BACKEND = "postgresql"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
924 config.SESSIONDB_BACKEND = "redis"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
925
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
926 with self.assertRaises(configuration.OptionValueError) as cm:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
927 config.validator(config.options)
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
928
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
929 self.assertIn(" db type: redis with postgresql",
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
930 cm.exception.__str__())
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
931
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
932 def testLoadSessionDb(self):
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
933 """ run load to validate config """
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
934
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
935 config = configuration.CoreConfig()
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
936
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
937 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
938 config.RDBMS_BACKEND = "sqlite"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
939 config.SESSIONDB_BACKEND = "foo"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
940
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
941 with self.assertRaises(configuration.OptionValueError) as cm:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
942 config.validator(config.options)
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
943
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
944 self.assertIn(" db type: foo with sqlite",
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
945 cm.exception.__str__())
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
946
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
947 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
948 config.RDBMS_BACKEND = "sqlite"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
949 config.SESSIONDB_BACKEND = ""
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
950
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
951 config.validator(config.options) # any exception will fail test
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
952
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
953 config.RDBMS_BACKEND = "sqlite"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
954 config.SESSIONDB_BACKEND = "anydbm"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
955
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
956 config.validator(config.options) # any exception will fail test
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
957
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
958 config.RDBMS_BACKEND = "anydbm"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
959 config.SESSIONDB_BACKEND = "redis"
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
960
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
961 # make it looks like redis is not available
6821
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
962 try:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
963 del(sys.modules['redis'])
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
964 except KeyError:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
965 # redis is not available anyway.
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
966 pass
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
967
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
968 sys.modules['redis'] = None
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
969 with self.assertRaises(configuration.OptionValueError) as cm:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
970 config.validator(config.options)
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
971 del(sys.modules['redis'])
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
972
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
973 self.assertIn("Unable to load redis module",
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
974 cm.exception.__str__())
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
975
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
976 def testLoadConfig(self):
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
977 """ run load to validate config """
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
978
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
979 config = configuration.CoreConfig()
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
980
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
981 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
982
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
983 # test various ways of accessing config data
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
984 with self.assertRaises(configuration.InvalidOptionError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
985 # using lower case name fails
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
986 c = config['indexer_language']
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
987 print(cm.exception)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
988 self.assertIn("indexer_language", repr(cm.exception))
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
989
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
990 # uppercase name passes as does tuple index for setting in main
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
991 self.assertEqual(config['HTML_VERSION'], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
992 self.assertEqual(config[('main', 'html_version')], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
993
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
994 # uppercase name passes as does tuple index for setting in web
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
995 self.assertEqual(config['WEB_COOKIE_TAKES_PRECEDENCE'], 0)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
996 self.assertEqual(config[('web','cookie_takes_precedence')], 0)
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
997
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
998
6359
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
999 def testLoadConfigNoConfig(self):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1000 """ run load on a directory missing config.ini """
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1001
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1002 c = os.path.join(self.dirname, configuration.Config.INI_FILE)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1003 if os.path.exists(c):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1004 os.remove(c)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1005 else:
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1006 self.assertFalse("setup failed missing config.ini")
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1007
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1008 config = configuration.CoreConfig()
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1009
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1010 with self.assertRaises(configuration.NoConfigError) as cm:
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1011 config.load(self.dirname)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1012
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1013 print(cm.exception)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1014 self.assertEqual(cm.exception.args[0], self.dirname)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1015
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1016 def testFormattedLogging(self):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1017 """Depends on using default logging format with %(trace_id)"""
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1018
8446
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1019 def find_file_occurances(string):
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1020 return len(re.findall(r'\bFile\b', string))
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1021
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1022 config = configuration.CoreConfig()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1023
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1024 config.LOGGING_LEVEL = "DEBUG"
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1025 config.init_logging()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1026
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1027
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1028 # format the record and verify the logformat/trace_id.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1029 config._logging_test(None, msg="message")
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1030 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1031 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1032 self.assertEqual("message", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1033 logger = logging.getLogger('roundup')
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1034 hdlr = logger.handlers[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1035 log = hdlr.format(self._caplog.records[0])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1036 # verify that %(trace_id) was set and substituted
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1037 # Note: trace_id is not initialized in this test case
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1038 log_parts = log.split()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1039 self.assertRegex(log_parts[2], r'^[A-Za-z0-9]{22}')
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1040 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1041
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1042 # the rest check various values of sinfo and msg formating.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1043
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1044 # sinfo = 1 - one line of stack starting with log call
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1045 config._logging_test(1)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1046 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1047 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1048 self.assertIn("test a_var\n File", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1049 self.assertIn("in _logging_test", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1050 self.assertIn("logger.info(msg, extra=", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1051 self.assertEqual(find_file_occurances(tuple[2]), 1)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1052 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1053
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1054 # sinfo = None - 5 lines of stack starting with log call
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1055 config._logging_test(None)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1056 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1057 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1058 self.assertIn("test a_var\n File", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1059 self.assertIn("in _logging_test", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1060 self.assertIn("logger.info(msg, extra=", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1061 self.assertEqual(find_file_occurances(tuple[2]), 5)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1062 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1063
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1064 # sinfo = 0 - whole stack starting with log call
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1065 config._logging_test(0)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1066 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1067 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1068 self.assertIn("test a_var\n File", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1069 self.assertIn("in _logging_test", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1070 self.assertIn("logger.info(msg, extra=", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1071 # A file in 'pytest' directory should be at the top of stack.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1072 self.assertIn("pytest", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1073 # no idea how deep the actual stack is, could change with python
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1074 # versions, but 3.12 is 33 so ....
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1075 self.assertTrue(find_file_occurances(tuple[2]) > 10)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1076 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1077
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1078 # sinfo = -1 - one line of stack starting with extract_stack()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1079 config._logging_test(-1)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1080 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1081 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1082 self.assertIn("test a_var\n File", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1083 # The call to extract_stack should be included as the frame
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1084 # at bottom of stack.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1085 self.assertIn("extract_stack()", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1086 # only one frame included
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1087 self.assertEqual(find_file_occurances(tuple[2]), 1)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1088 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1089
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1090 # sinfo = 1000 - whole stack starting with log call 1000>stack size
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1091 config._logging_test(1000)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1092 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1093 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1094 self.assertIn("test a_var\n File", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1095 self.assertIn("in _logging_test", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1096 self.assertIn("logger.info(msg, extra=", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1097 # A file in 'pytest' directory should be at the top of stack.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1098 self.assertIn("pytest", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1099 # no idea how deep the actual stack is, could change with python
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1100 # versions, but 3.12 is 33 so ....
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1101 self.assertTrue(find_file_occurances(tuple[2]) > 10)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1102 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1103
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1104 # sinfo = -1000 - whole stack starting with extract_stack
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1105 config._logging_test(-1000)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1106 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1107 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1108 self.assertIn("test a_var\n File", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1109 self.assertIn("in _logging_test", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1110 self.assertIn("logger.info(msg, extra=", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1111 # The call to extract_stack should be included as the frame
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1112 # at bottom of stack.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1113 self.assertIn("extract_stack()", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1114 # A file in 'pytest' directory should be at the top of stack.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1115 # no idea how deep the actual stack is, could change with python
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1116 # versions, but 3.12 is 33 so ....
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1117 self.assertTrue(find_file_occurances(tuple[2]) > 10)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1118 self.assertIn("pytest", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1119 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1120
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1121 # pass args and compatible message
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1122 config._logging_test(None, args=(1,2,3),
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1123 msg="one: %s, two: %s, three: %s"
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1124 )
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1125 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1126 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1127 self.assertEqual('one: 1, two: 2, three: 3', tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1128 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1129
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1130 # error case for incorrect placeholder
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1131 config._logging_test(None, msg="%(a)")
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1132 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1133 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1134 self.assertEqual("%(a)", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1135 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1136
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1137 # error case for incompatible format record is the first argument
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1138 # and it can't be turned into floating point.
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1139 config._logging_test(None, msg="%f")
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1140 tuple = self._caplog.record_tuples[0]
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1141 self.assertEqual(tuple[1], 20)
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1142 self.assertEqual("%f", tuple[2])
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1143 self._caplog.clear()
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1144
14c7c07b32d8 feature: add thread local trace_id and trace_reason to logging.
John Rouillard <rouilj@ieee.org>
parents: 8443
diff changeset
1145
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1146 def testXhtmlRaisesOptionError(self):
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1147 self.munge_configini(mods=[ ("html_version = ", "xhtml") ])
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1148
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1149 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1150
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1151 # verify config is initalized to defaults
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1152 self.assertEqual(config['HTML_VERSION'], 'html4')
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1153
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1154
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1155 with self.assertRaises(configuration.OptionValueError) as cm:
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1156 # load config
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1157 config.load(self.dirname)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1158
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1159 print(cm.exception)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1160 self.assertEqual(str(cm.exception),
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1161 "Invalid value for HTML_VERSION: 'xhtml'\n"
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1162 "Allowed values: html4")
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1163
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1164 def testCopyConfig(self):
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1165
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1166 self.munge_configini(mods=[ ("static_files = ", "html2") ])
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1167
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1168 config = configuration.CoreConfig()
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1169
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1170 # verify config is initalized to defaults
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1171 self.assertEqual(config['STATIC_FILES'], None)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1172
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1173 # load config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1174 config.load(self.dirname)
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1175 self.assertEqual(config['STATIC_FILES'], ['_test_instance/html2'])
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1176
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1177 # copy config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1178 config_copy = config.copy()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1179
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1180 # this should work
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1181 self.assertEqual(config_copy['STATIC_FILES'], ['_test_instance/html2'])
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1182
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1183 @skip_py2
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1184 def testConfigValueInterpolateError(self):
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1185 ''' error is not raised using ConfigParser under Python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1186 Unknown cause, so skip it if running python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1187 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1188
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1189 self.munge_configini(mods=[ ("admin_email = ", "a bare % is invalid") ])
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1190
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1191 config = configuration.CoreConfig()
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1192
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1193 # load config generates:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1194 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1195 E roundup.configuration.ParsingOptionError: Error in _test_instance/config.ini with section [main] at option admin_email: '%' must be followed by '%' or '(', found: '% is invalid'
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1196 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1197
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1198 with self.assertRaises(configuration.ParsingOptionError) as cm:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1199 config.load(self.dirname)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1200
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1201 print(cm.exception)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1202 self.assertIn("'%' must be followed by '%' or '(', found: '% is invalid'", cm.exception.args[0])
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1203 self.assertIn(normpath("_test_instance/config.ini") + " with section [main] at option admin_email", cm.exception.args[0])
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1204
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1205
6560
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1206 from roundup.admin import AdminTool
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1207 from .test_admin import captured_output
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1208
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1209 admin=AdminTool()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1210 with captured_output() as (out, err):
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1211 sys.argv=['main', '-i', self.dirname, 'get', 'tile', 'issue1']
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1212 ret = admin.main()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1213
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1214 expected_err = ("Error in " +
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1215 normpath("_test_instance/config.ini") +
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1216 " with section [main] at option admin_email: '%' "
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1217 "must be followed by '%' or '(', found: "
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1218 "'% is invalid'")
6560
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1219
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1220 self.assertEqual(ret, 1)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1221 out = out.getvalue().strip()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1222 self.assertEqual(out, expected_err)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1223
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1224 def testInvalidIndexerValue(self):
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1225 """ Mistype native indexer. Verify exception is
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1226 generated.
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1227 """
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1228
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1229 print("Testing indexer nati")
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1230
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1231 self.munge_configini(mods=[ ("indexer = ", "nati") ])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1232
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1233 with self.assertRaises(configuration.OptionValueError) as cm:
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1234 config.load(self.dirname)
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1235
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1236 self.assertIn("OptionValueError", repr(cm.exception))
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1237 # look for failing value
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1238 self.assertEqual("nati", cm.exception.args[1])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1239 # look for supported values
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1240 self.assertIn("'whoosh'", cm.exception.args[2])
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1241
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1242 # verify that args show up in string representaton
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1243 string_rep = cm.exception.__str__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1244 print(string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1245 self.assertIn("nati", string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1246 self.assertIn("'whoosh'", string_rep)
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1247
8443
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1248 def testLoggerFormat(self):
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1249 config = configuration.CoreConfig()
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1250
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1251 # verify config is initalized to defaults
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1252 self.assertEqual(config['LOGGING_FORMAT'],
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1253 '%(asctime)s %(levelname)s %(message)s')
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1254
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1255 # load config
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1256 config.load(self.dirname)
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1257 self.assertEqual(config['LOGGING_FORMAT'],
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1258 '%(asctime)s %(levelname)s %(message)s')
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1259
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1260 # break config using an incomplete format specifier (no trailing 's')
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1261 self.munge_configini(mods=[ ("format = ", "%%(asctime)s %%(levelname) %%(message)s") ], section="[logging]")
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1262
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1263 # load config
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1264 with self.assertRaises(configuration.OptionValueError) as cm:
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1265 config.load(self.dirname)
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1266
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1267 self.assertIn('Unrecognized use of %(...) in: %(levelname)',
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1268 cm.exception.args[2])
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1269
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1270 # break config by not dubling % sign to quote it from configparser
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1271 self.munge_configini(mods=[ ("format = ", "%(asctime)s %%(levelname) %%(message)s") ], section="[logging]")
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1272
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1273 with self.assertRaises(
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1274 configuration.ParsingOptionError) as cm:
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1275 config.load(self.dirname)
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1276
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1277 self.assertEqual(cm.exception.args[0],
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1278 "Error in _test_instance/config.ini with section "
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1279 "[logging] at option format: Bad value substitution: "
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1280 "option 'format' in section 'logging' contains an "
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1281 "interpolation key 'asctime' which is not a valid "
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1282 "option name. Raw value: '%(asctime)s %%(levelname) "
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1283 "%%(message)s'")
39a6825d10ca feat: allow admin to set logging format from config.ini
John Rouillard <rouilj@ieee.org>
parents: 8434
diff changeset
1284
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1285 def testDictLoggerConfigViaJson(self):
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1286
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1287 # good base test case
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1288 config1 = dedent("""
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1289 {
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1290 "version": 1, // only supported version
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1291 "disable_existing_loggers": false, // keep the wsgi loggers
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1292
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1293 "formatters": {
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1294 // standard Roundup formatter including context id.
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1295 "standard": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1296 "format": "%(asctime)s %(levelname)s %(name)s:%(module)s %(msg)s"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1297 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1298 // used for waitress wsgi server to produce httpd style logs
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1299 "http": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1300 "format": "%(message)s"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1301 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1302 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1303 "handlers": {
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1304 // create an access.log style http log file
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1305 "access": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1306 "level": "INFO",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1307 "formatter": "http",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1308 "class": "logging.FileHandler",
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1309 "filename": "_test_instance/access.log"
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1310 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1311 // logging for roundup.* loggers
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1312 "roundup": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1313 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1314 "formatter": "standard",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1315 "class": "logging.FileHandler",
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1316 "filename": "_test_instance/roundup.log"
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1317 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1318 // print to stdout - fall through for other logging
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1319 "default": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1320 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1321 "formatter": "standard",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1322 "class": "logging.StreamHandler",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1323 "stream": "ext://sys.stdout"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1324 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1325 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1326 "loggers": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1327 "": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1328 "handlers": [
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1329 "default" // used by wsgi/usgi
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1330 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1331 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1332 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1333 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1334 // used by roundup.* loggers
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1335 "roundup": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1336 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1337 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1338 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1339 "level": "DEBUG",
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1340 "propagate": false // note pytest testing with caplog requires
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1341 // this to be true
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1342 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1343 "roundup.hyperdb": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1344 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1345 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1346 ],
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1347 "level": "INFO", // can be a little noisy INFO for production
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1348 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1349 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1350 "roundup.wsgi": { // using the waitress framework
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1351 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1352 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1353 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1354 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1355 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1356 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1357 "roundup.wsgi.translogger": { // httpd style logging
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1358 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1359 "access"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1360 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1361 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1362 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1363 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1364 "root": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1365 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1366 "default"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1367 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1368 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1369 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1370 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1371 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1372 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1373 """)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1374
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1375 log_config_filename = os.path.join(self.instance.tracker_home,
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1376 "_test_log_config.json")
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1377
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1378 # happy path
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1379 with open(log_config_filename, "w") as log_config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1380 log_config_file.write(config1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1381
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1382 config = self.db.config.load_config_dict_from_json_file(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1383 log_config_filename)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1384 self.assertIn("version", config)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1385 self.assertEqual(config['version'], 1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1386
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1387 # broken inline comment misformatted
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1388 test_config = config1.replace(": 1, //", ": 1, //")
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1389 with open(log_config_filename, "w") as log_config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1390 log_config_file.write(test_config)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1391
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1392 with self.assertRaises(configuration.LoggingConfigError) as cm:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1393 config = self.db.config.load_config_dict_from_json_file(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1394 log_config_filename)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1395 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1396 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1397 ('Error parsing json logging dict '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1398 '(%s) near \n\n '
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1399 '"version": 1, // only supported version\n\nExpecting '
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1400 'property name enclosed in double quotes: line 3 column 18.\n'
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1401 'Maybe bad inline comment, 3 spaces needed before //.' %
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1402 log_config_filename)
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1403 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1404
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1405 # broken trailing , on last dict element
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1406 test_config = config1.replace(' "ext://sys.stdout"',
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1407 ' "ext://sys.stdout",'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1408 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1409 with open(log_config_filename, "w") as log_config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1410 log_config_file.write(test_config)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1411
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1412 with self.assertRaises(configuration.LoggingConfigError) as cm:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1413 config = self.db.config.load_config_dict_from_json_file(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1414 log_config_filename)
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1415 #pre 3.12??
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1416 # FIXME check/remove when 3.13. is min supported version
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1417 if "property name" in cm.exception.args[0]:
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1418 self.assertEqual(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1419 cm.exception.args[0],
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1420 ('Error parsing json logging dict '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1421 '(%s) near \n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1422 ' }\n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1423 'Expecting property name enclosed in double '
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1424 'quotes: line 37 column 6.' % log_config_filename)
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1425 )
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1427 # 3.13+ diags FIXME
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1428 print('FINDME')
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1429 print(cm.exception.args[0])
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1430 _junk = '''
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1431 if "property name" not in cm.exception.args[0]:
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1432 self.assertEqual(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1433 cm.exception.args[0],
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1434 ('Error parsing json logging dict '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1435 '(%s) near \n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1436 ' "stream": "ext://sys.stdout"\n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1437 'Expecting property name enclosed in double '
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1438 'quotes: line 37 column 6.' % log_config_filename)
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1439 )
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1440 '''
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1441 # happy path for init_logging()
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1442
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1443 # verify preconditions
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1444 logger = logging.getLogger("roundup")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1445 self.assertEqual(logger.level, 40) # error default from config.ini
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1446 self.assertEqual(logger.filters, [])
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1447
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1448 with open(log_config_filename, "w") as log_config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1449 log_config_file.write(config1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1450
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1451 # file is made relative to tracker dir.
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1452 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1453 config = self.db.config.init_logging()
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1454 self.assertIs(config, None)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1455
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1456 logger = logging.getLogger("roundup")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1457 self.assertEqual(logger.level, 10) # debug
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1458 self.assertEqual(logger.filters, [])
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1459
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1460 # broken invalid format type (int not str)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1461 test_config = config1.replace('"format": "%(message)s"',
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1462 '"format": 1234',)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1463 with open(log_config_filename, "w") as log_config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1464 log_config_file.write(test_config)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1465
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1466 # file is made relative to tracker dir.
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1467 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json'
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1468
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1469
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1470 # different versions of python have different errors
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1471 # (or no error for this case in 3.7)
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1472 # FIXME remove version check post 3.7 as minimum version
8429
3210729950b1 test: fix code that does not run a test on 3.7
John Rouillard <rouilj@ieee.org>
parents: 8428
diff changeset
1473 if sys.version_info >= (3, 8, 0):
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1474 with self.assertRaises(configuration.LoggingConfigError) as cm:
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1475 config = self.db.config.init_logging()
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1476
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1477 # mangle args[0] to add got 'int'
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1478 # FIXME: remove mangle after 3.12 min version
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1479 self.assertEqual(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1480 cm.exception.args[0].replace(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1481 "object\n", "object, got 'int'\n"),
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1482 ('Error loading logging dict from '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1483 '%s.\n'
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1484 "ValueError: Unable to configure formatter 'http'\n"
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1485 "expected string or bytes-like object, got 'int'\n" %
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1486 log_config_filename)
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1487 )
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1488
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1489 # broken invalid level MANGO
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1490 test_config = config1.replace(
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1491 ': "INFO", // can',
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1492 ': "MANGO", // can')
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1493 with open(log_config_filename, "w") as log_config_file:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1494 log_config_file.write(test_config)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1495
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1496 # file is made relative to tracker dir.
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1497 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1498 with self.assertRaises(configuration.LoggingConfigError) as cm:
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1499 config = self.db.config.init_logging()
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1500 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1501 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1502 ("Error loading logging dict from "
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1503 "%s.\nValueError: "
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1504 "Unable to configure logger 'roundup.hyperdb'\nUnknown level: "
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1505 "'MANGO'\n" % log_config_filename)
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1506
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1507 )
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1508
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1509 # broken invalid output directory
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1510 test_config = config1.replace(
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1511 ' "_test_instance/access.log"',
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1512 ' "not_a_test_instance/access.log"')
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1513 access_filename = os.path.join("not_a_test_instance", "access.log")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1514
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1515 with open(log_config_filename, "w") as log_config_file:
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1516 log_config_file.write(test_config)
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1517
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1518 # file is made relative to tracker dir.
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1519 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json'
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1520 with self.assertRaises(configuration.LoggingConfigError) as cm:
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1521 config = self.db.config.init_logging()
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1522
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1523 # error includes full path which is different on different
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1524 # CI and dev platforms. So munge the path using re.sub and
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1525 # replace. Windows needs replace as the full path for windows
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1526 # to the file has '\\\\' not '\\' when taken from __context__.
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1527 # E.G.
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1528 # ("Error loading logging dict from '
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1529 # '_test_instance\\_test_log_config.json.\nValueError: '
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1530 # "Unable to configure handler 'access'\n[Errno 2] No such file "
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1531 # "or directory: "
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1532 # "'C:\\\\tracker\\\\path\\\\not_a_test_instance\\\\access.log'\n")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1533 # sigh.....
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1534 output = re.sub("directory: \'.*not_a", 'directory: not_a' ,
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1535 cm.exception.args[0].replace(r'\\','\\'))
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1536 target = ("Error loading logging dict from "
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1537 "%s.\n"
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1538 "ValueError: Unable to configure handler 'access'\n"
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1539 "[Errno 2] No such file or directory: "
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1540 "%s'\n" % (log_config_filename, access_filename))
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1541 self.assertEqual(output, target)
8427
b34c3b8338f0 test: more fun with logger leakage.
John Rouillard <rouilj@ieee.org>
parents: 8426
diff changeset
1542
8434
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1543 def test_missing_logging_config_file(self):
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1544 saved_config = self.db.config['LOGGING_CONFIG']
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1545
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1546 self.db.config['LOGGING_CONFIG'] = 'logging.json'
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1547
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1548 with self.assertRaises(configuration.OptionValueError) as cm:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1549 self.db.config.init_logging()
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1550
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1551 self.assertEqual(cm.exception.args[1], "_test_instance/logging.json")
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1552 self.assertEqual(cm.exception.args[2],
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1553 "Unable to find logging config file.")
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1554
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1555 self.db.config['LOGGING_CONFIG'] = 'logging.ini'
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1556
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1557 with self.assertRaises(configuration.OptionValueError) as cm:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1558 self.db.config.init_logging()
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1559
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1560 self.assertEqual(cm.exception.args[1], "_test_instance/logging.ini")
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1561 self.assertEqual(cm.exception.args[2],
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1562 "Unable to find logging config file.")
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1563
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1564 self.db.config['LOGGING_CONFIG'] = saved_config
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1565
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1566 def test_unknown_logging_config_file_type(self):
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1567 saved_config = self.db.config['LOGGING_CONFIG']
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1568
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1569 self.db.config['LOGGING_CONFIG'] = 'schema.py'
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1570
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1571
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1572 with self.assertRaises(configuration.OptionValueError) as cm:
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1573 self.db.config.init_logging()
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1574
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1575 self.assertEqual(cm.exception.args[1], "_test_instance/schema.py")
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1576 self.assertEqual(cm.exception.args[2],
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1577 "Unable to load logging config file. "
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1578 "File extension must be '.ini' or '.json'.\n")
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1579
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1580 self.db.config['LOGGING_CONFIG'] = saved_config

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