annotate test/test_config.py @ 8434:66284037142e

refactor: also error on missing file or invalid extension Refactored the code to reuse check that logging config file is set and that the file exists. Now throws error and exits if file name does not end in .ini or .json. Now throws error if file doesn't exist. Before it would just configure default logging as though file wasn't specified. Added tests for these two cases.
author John Rouillard <rouilj@ieee.org>
date Tue, 26 Aug 2025 23:06:40 -0400
parents de1dac9abcb6
children 39a6825d10ca
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
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
421 @pytest.fixture(scope="class")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
422 def save_restore_logging(self):
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
423 """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
424 this class have finished.
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
425
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
426 The primary test is testDictLoggerConfigViaJson which
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
427 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
428 """
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
429 # 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
430 loggernames = ("", "roundup")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
431
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
432 # 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
433 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
434
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
435 logger_state = {}
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
436 for name in loggernames:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
437 logger_state[name] = {}
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
438 roundup_logger = logging.getLogger(name)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
439
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
440 for i in state_to_save:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
441 attr = getattr(roundup_logger, i)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
442 if isinstance(attr, list):
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
443 logger_state[name][i] = attr.copy()
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
444 else:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
445 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
446
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
447 # run all class tests here
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
448 yield
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
449
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
450 # 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
451 # to stdout.
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
452 # 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
453 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
454 logging.root.manager.loggerDict
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
455 if name.startswith("roundup")]
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
456
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
457 # cribbed from configuration.py:init_loggers
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
458 hdlr = logging.StreamHandler(sys.stdout)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
459 formatter = logging.Formatter(
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
460 '%(asctime)s %(levelname)s %(message)s')
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
461 hdlr.setFormatter(formatter)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
462
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
463 for logger in roundup_loggers:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
464 # 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
465 for h in logger.handlers:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
466 h.close()
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
467 logger.removeHandler(h)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
468 logger.handlers = [hdlr]
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
469 logger.setLevel("WARNING")
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
470 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
471
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
472 # 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
473 for name in loggernames:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
474 local_logger = logging.getLogger(name)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
475 for attr in logger_state[name]:
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
476 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
477
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
478 # reset logging as well
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
479 from importlib import reload
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
480 logging.shutdown()
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
481 reload(logging)
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
482
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
483 backend = 'anydbm'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
484
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
485 def setUp(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
486 self.dirname = '_test_instance'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
487 # 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
488 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
489
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
490 # open the database
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
491 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
492
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
493 self.db.commit()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
494 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
495
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
496 def tearDown(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
497 if self.db:
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 try:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
500 shutil.rmtree(self.dirname)
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
501 except OSError as error:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
502 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
503
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
504 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
505 """ modify config.ini to meet testing requirements
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
506
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
507 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
508 [ ( "a = ", "b" ), ("c = ", None), ("d = ", "b", "z = ") ]
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
509 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
510 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
511 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
512 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
513 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
514 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
515 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
516 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
517 elements (used to replace commented out parameters).
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
518
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
519 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
520 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
521 section name.
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
522 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
523
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
524 if mods is None:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
525 return
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
526
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
527 # 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
528 # 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
529 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
530
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
531 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
532 inplace=True):
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
533 if section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
534 if line.startswith('['):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
535 in_section = False
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
536
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
537 if line.startswith(section):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
538 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
539
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
540 if in_section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
541 for rule in mods:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
542 if len(rule) == 3:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
543 match, value, repl = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
544 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
545 match, value = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
546 repl = None
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
547
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
548 if line.startswith(match):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
549 if value is not None:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
550 if repl:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
551 print(repl + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
552 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
553 print(match + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
554 break
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
555 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
556 print(line[:-1]) # remove trailing \n
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
557 else:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
558 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
559
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
560 def testNoDBInConfig(self):
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
561 """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
562 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
563 configuration module with a missing required param in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
564 config.ini.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
565 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
566
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
567 # remove the backend key in config.ini
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
568 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
569
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
570 # 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
571 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
572 instance.open(self.dirname)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
573
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
574 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
575 " 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
576
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
577 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
578 """ 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
579 [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
580 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
581 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
582 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
583 section="[mail]")
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 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
586
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
587 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
588 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
589
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
590 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
591 # 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
592 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
593 # look for 'not defined'
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
594 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
595
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
596
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
597 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
598 """ 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
599 [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
600 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
601 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
602
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
603 config.load(self.dirname)
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 self.assertEqual(config['MAIL_USERNAME'], '')
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 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
608 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
609
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
610 def testSecretMandatory_missing_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
611
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
612 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
613 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
614
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
615 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
616
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
617 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
618 config.load(self.dirname)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
619
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
620 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
621 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
622
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
623 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
624
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
625 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
626 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
627
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
628 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
629 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
630 f.write(secret + "\n")
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 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
633
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
634 config.load(self.dirname)
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 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
637
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
638
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
639 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
640
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
641 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
642
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
643 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
644 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
645
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
646 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
647 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
648 f.write(secret + "\n")
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 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
651
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
652 config.load(self.dirname)
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 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
655
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
656 os.remove(abs_file)
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 def testSecretMandatory_empty_file(self):
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 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
661
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
662 # 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
663 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
664 f.write("\n")
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 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
667
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
668 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
669 config.load(self.dirname)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
670
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
671 print(cm.exception.args)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
672 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
673
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
674 def testNullableSecret_empty_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
675
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
676 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
677
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
678 # 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
679 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
680 f.write("\n")
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 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
683
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
684 config.load(self.dirname)
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 v = config['RDBMS_PASSWORD']
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 self.assertEqual(v, None)
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 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
691
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
692 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
693
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
694 # 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
695 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
696 f.write("test\n")
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 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
699
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
700 config.load(self.dirname)
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 v = config['RDBMS_PASSWORD']
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 self.assertEqual(v, "test")
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 def testNullableSecret_with_value(self):
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.munge_configini(mods=[ ("password = ", "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 config = configuration.CoreConfig()
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 config.load(self.dirname)
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 v = config['RDBMS_PASSWORD']
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 self.assertEqual(v, "test")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
717
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
718 def testListSecret_for_jwt_invalid_secret(self):
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
719 """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
720 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
721 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
722 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
723 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
724 """
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
725 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
726
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
727 config = configuration.CoreConfig()
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 with self.assertRaises(configuration.OptionValueError) as cm:
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
730 config.load(self.dirname)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
731
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
732 print(cm.exception.args)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
733 self.assertEqual(
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
734 cm.exception.args[2],
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
735 "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
736
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
737 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
738 """ 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
739 Should have both values set.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
740 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
741 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
742 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
743 ("#password = ", "passwordfoo",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
744 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
745 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
746
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
747 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
748
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
749 config.load(self.dirname)
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 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
752 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
753
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
754 def testSetMailPassword_from_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
755 """ 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
756 Should have both values set.
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 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
759 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
760 ("#password = ", "file://password",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
761 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
762 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
763 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
764 f.write("passwordfoo\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
765
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
766 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
767
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
768 config.load(self.dirname)
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 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
771 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
772
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
773 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
774 def testInvalidIndexerLanguage_w_empty(self):
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
775 """ 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
776 invalid indexer language is specified. This uses
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
777 default search path for indexers.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
778 """
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
779
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
780 # 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
781 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
782 ("indexer_language = ", "NO_LANG") ])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
783
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
784 config = configuration.CoreConfig()
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
785
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
786 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
787 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
788
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
789 print(cm.exception)
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
790 # 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
791 self.assertIn("OptionValueError", repr(cm.exception))
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
792 # look for failing language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
793 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
794 # look for supported language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
795 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
796
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
797 @include_no_xapian
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
798 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
799 """ 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
800
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
801 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
802 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
803 """
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
804 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
805
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
806 # 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
807 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
808 ("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
809
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
810 config = configuration.CoreConfig()
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
811
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
812 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
813
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
814 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
815
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
816 def testInvalidIndexerLanguage_xapian_missing(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
817 """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
818 fail and prevent exception from happening even though
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
819 the indexer_language would be invalid for xapian.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
820 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
821
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
822 print("Testing xapian not loadable")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
823
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
824 # SETUP: same as testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
825 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
826 ("indexer_language = ", "NO_LANG") ])
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 import sys
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
829 # 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
830 sys.modules['xapian'] = None
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
831 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
832
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
833 # 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
834 del(sys.modules['xapian'])
6371
5c1db5d4baed Fix failing xapian test
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6368
diff changeset
835 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
836 del(sys.modules['xapian._xapian'])
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
837
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
838 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
839
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
840 # 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
841 # to do setup in a different test
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
842 config.reset()
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
843 self.assertEqual(config['INDEXER_LANGUAGE'], 'english')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
844
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
845 def testInvalidIndexerLanguage_w_native(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
846 """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
847 Config load should succeed without exception.
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
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
850 print("Testing indexer = native")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
851
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
852 self.munge_configini(mods = [ ("indexer = ", "native"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
853 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
854
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
855 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
856
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
857 self.assertEqual(config['HTML_VERSION'], 'html4')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
858 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
859
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
860 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
861 def testInvalidIndexerLanguage_w_xapian(self):
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
862 """ Use explicit xapian indexer. Verify exception is
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
863 generated.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
864 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
865
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
866 print("Testing explicit xapian")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
867
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
868 self.munge_configini(mods=[ ("indexer = ", "xapian"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
869 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
870
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
871 with self.assertRaises(configuration.OptionValueError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
872 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
873 # don't test exception content. Done in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
874 # testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
875 # if exception not generated assertRaises
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
876 # will generate failure.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
877
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
878 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
879 """ 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
880 generated.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
881 """
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
882
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
883 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
884 ("indexer_language = ", "NO_LANG") ])
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 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
887 config.load(self.dirname)
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
888
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
889 # 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
890 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
891 # look for failing language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
892 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
893 # look for supported language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
894 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
895
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
896 @skip_redis
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
897 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
898 """ 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
899
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
900 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
901
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
902 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
903 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
904 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
905
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
906 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
907
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
908 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
909 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
910 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
911
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
912 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
913
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
914 @skip_redis
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
915 @skip_postgresql
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
916 def testLoadSessionDbRedisIncompatible(self):
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
917 """ 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
918 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
919 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
920 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
921
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
922 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
923 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
924
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
925 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
926 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
927
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
928 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
929 """ 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
930
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
931 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
932
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
933 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
934 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
935 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
936
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
937 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
938 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
939
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
940 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
941 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
942
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
943 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
944 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
945 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
946
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
947 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
948
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
949 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
950 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
951
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
952 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
953
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
954 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
955 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
956
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
957 # 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
958 try:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
959 del(sys.modules['redis'])
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
960 except KeyError:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
961 # redis is not available anyway.
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
962 pass
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
963
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
964 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
965 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
966 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
967 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
968
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
969 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
970 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
971
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
972 def testLoadConfig(self):
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
973 """ run load to validate config """
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
974
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
975 config = configuration.CoreConfig()
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
976
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
977 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
978
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
979 # 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
980 with self.assertRaises(configuration.InvalidOptionError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
981 # using lower case name fails
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
982 c = config['indexer_language']
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
983 print(cm.exception)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
984 self.assertIn("indexer_language", repr(cm.exception))
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
985
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
986 # 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
987 self.assertEqual(config['HTML_VERSION'], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
988 self.assertEqual(config[('main', 'html_version')], 'html4')
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 web
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
991 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
992 self.assertEqual(config[('web','cookie_takes_precedence')], 0)
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
993
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
994
6359
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
995 def testLoadConfigNoConfig(self):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
996 """ 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
997
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
998 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
999 if os.path.exists(c):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1000 os.remove(c)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1001 else:
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1002 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
1003
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1004 config = configuration.CoreConfig()
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1005
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1006 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
1007 config.load(self.dirname)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1008
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1009 print(cm.exception)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
1010 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
1011
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1012
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1013 def testXhtmlRaisesOptionError(self):
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1014 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
1015
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1016 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1017
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1018 # 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
1019 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
1020
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1021
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1022 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
1023 # load config
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1024 config.load(self.dirname)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1025
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1026 print(cm.exception)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1027 self.assertEqual(str(cm.exception),
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1028 "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
1029 "Allowed values: html4")
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1030
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1031 def testCopyConfig(self):
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1032
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1033 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
1034
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1035 config = configuration.CoreConfig()
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1036
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1037 # verify config is initalized to defaults
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1038 self.assertEqual(config['STATIC_FILES'], None)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1039
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1040 # load config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1041 config.load(self.dirname)
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1042 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
1043
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1044 # copy config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1045 config_copy = config.copy()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1046
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1047 # this should work
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
1048 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
1049
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1050 @skip_py2
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1051 def testConfigValueInterpolateError(self):
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1052 ''' error is not raised using ConfigParser under Python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1053 Unknown cause, so skip it if running python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1054 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1055
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1056 self.munge_configini(mods=[ ("admin_email = ", "a bare % is invalid") ])
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1057
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1058 config = configuration.CoreConfig()
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1059
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1060 # load config generates:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1061 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1062 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
1063 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1064
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1065 with self.assertRaises(configuration.ParsingOptionError) as cm:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1066 config.load(self.dirname)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1067
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1068 print(cm.exception)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1069 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
1070 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
1071
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1072
6560
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1073 from roundup.admin import AdminTool
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1074 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
1075
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1076 admin=AdminTool()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1077 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
1078 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
1079 ret = admin.main()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1080
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1081 expected_err = ("Error in " +
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1082 normpath("_test_instance/config.ini") +
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1083 " with section [main] at option admin_email: '%' "
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1084 "must be followed by '%' or '(', found: "
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1085 "'% is invalid'")
6560
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1086
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1087 self.assertEqual(ret, 1)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1088 out = out.getvalue().strip()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1089 self.assertEqual(out, expected_err)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1090
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1091 def testInvalidIndexerValue(self):
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1092 """ Mistype native indexer. Verify exception is
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1093 generated.
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1094 """
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1095
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1096 print("Testing indexer nati")
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1097
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1098 self.munge_configini(mods=[ ("indexer = ", "nati") ])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1099
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1100 with self.assertRaises(configuration.OptionValueError) as cm:
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1101 config.load(self.dirname)
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1102
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1103 self.assertIn("OptionValueError", repr(cm.exception))
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1104 # look for failing value
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1105 self.assertEqual("nati", cm.exception.args[1])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1106 # look for supported values
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1107 self.assertIn("'whoosh'", cm.exception.args[2])
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1108
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1109 # 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
1110 string_rep = cm.exception.__str__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1111 print(string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1112 self.assertIn("nati", string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1113 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
1114
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1115 def testDictLoggerConfigViaJson(self):
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1116
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1117 # good base test case
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1118 config1 = dedent("""
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1119 {
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1120 "version": 1, // only supported version
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1121 "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
1122
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1123 "formatters": {
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1124 // 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
1125 "standard": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1126 "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
1127 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1128 // 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
1129 "http": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1130 "format": "%(message)s"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1131 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1132 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1133 "handlers": {
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1134 // 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
1135 "access": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1136 "level": "INFO",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1137 "formatter": "http",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1138 "class": "logging.FileHandler",
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1139 "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
1140 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1141 // logging for roundup.* loggers
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1142 "roundup": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1143 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1144 "formatter": "standard",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1145 "class": "logging.FileHandler",
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1146 "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
1147 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1148 // 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
1149 "default": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1150 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1151 "formatter": "standard",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1152 "class": "logging.StreamHandler",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1153 "stream": "ext://sys.stdout"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1154 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1155 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1156 "loggers": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1157 "": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1158 "handlers": [
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1159 "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
1160 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1161 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1162 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1163 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1164 // used by roundup.* loggers
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1165 "roundup": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1166 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1167 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1168 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1169 "level": "DEBUG",
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1170 "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
1171 // this to be true
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1172 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1173 "roundup.hyperdb": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1174 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1175 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1176 ],
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1177 "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
1178 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1179 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1180 "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
1181 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1182 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1183 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1184 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1185 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1186 },
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1187 "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
1188 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1189 "access"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1190 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1191 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1192 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1193 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1194 "root": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1195 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1196 "default"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1197 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1198 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1199 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1200 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1201 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1202 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1203 """)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1204
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1205 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
1206 "_test_log_config.json")
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1207
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1208 # happy path
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1209 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
1210 log_config_file.write(config1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1211
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1212 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
1213 log_config_filename)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1214 self.assertIn("version", config)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1215 self.assertEqual(config['version'], 1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1216
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1217 # broken inline comment misformatted
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1218 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
1219 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
1220 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
1221
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1222 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
1223 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
1224 log_config_filename)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1225 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1226 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1227 ('Error parsing json logging dict '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1228 '(%s) near \n\n '
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1229 '"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
1230 '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
1231 '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
1232 log_config_filename)
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1233 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1234
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1235 # 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
1236 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
1237 ' "ext://sys.stdout",'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1238 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1239 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
1240 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
1241
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1242 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
1243 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
1244 log_config_filename)
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1245 #pre 3.12??
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1246 # 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
1247 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
1248 self.assertEqual(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1249 cm.exception.args[0],
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1250 ('Error parsing json logging dict '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1251 '(%s) near \n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1252 ' }\n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1253 'Expecting property name enclosed in double '
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1254 '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
1255 )
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1256
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1257 # 3.13+ diags FIXME
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1258 print('FINDME')
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1259 print(cm.exception.args[0])
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1260 _junk = '''
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1261 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
1262 self.assertEqual(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1263 cm.exception.args[0],
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1264 ('Error parsing json logging dict '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1265 '(%s) near \n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1266 ' "stream": "ext://sys.stdout"\n\n'
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1267 'Expecting property name enclosed in double '
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1268 '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
1269 )
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1270 '''
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1271 # happy path for init_logging()
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1272
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1273 # verify preconditions
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1274 logger = logging.getLogger("roundup")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1275 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
1276 self.assertEqual(logger.filters, [])
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1277
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1278 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
1279 log_config_file.write(config1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1280
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1281 # 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
1282 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
1283 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
1284 self.assertIs(config, None)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1285
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1286 logger = logging.getLogger("roundup")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1287 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
1288 self.assertEqual(logger.filters, [])
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1289
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1290 # 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
1291 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
1292 '"format": 1234',)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1293 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
1294 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
1295
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1296 # 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
1297 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
1298
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1299
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1300 # 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
1301 # (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
1302 # 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
1303 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
1304 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
1305 config = self.db.config.init_logging()
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1306
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1307 # 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
1308 # 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
1309 self.assertEqual(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1310 cm.exception.args[0].replace(
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1311 "object\n", "object, got 'int'\n"),
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1312 ('Error loading logging dict from '
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1313 '%s.\n'
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1314 "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
1315 "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
1316 log_config_filename)
8426
cd0edc091b97 test: more fixes for variations among python versions.
John Rouillard <rouilj@ieee.org>
parents: 8424
diff changeset
1317 )
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1318
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1319 # broken invalid level MANGO
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1320 test_config = config1.replace(
8433
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1321 ': "INFO", // can',
de1dac9abcb6 feat: change comment in dictConfig json file to // from #
John Rouillard <rouilj@ieee.org>
parents: 8429
diff changeset
1322 ': "MANGO", // can')
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1323 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
1324 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
1325
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1326 # 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
1327 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
1328 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
1329 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
1330 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1331 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1332 ("Error loading logging dict from "
8428
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1333 "%s.\nValueError: "
8423
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1334 "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
1335 "'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
1336
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1337 )
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1338
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1339 # broken invalid output directory
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1340 test_config = config1.replace(
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1341 ' "_test_instance/access.log"',
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1342 ' "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
1343 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
1344
8424
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1345 with open(log_config_filename, "w") as log_config_file:
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1346 log_config_file.write(test_config)
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1347
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1348 # file is made relative to tracker dir.
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1349 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json'
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1350 with self.assertRaises(configuration.LoggingConfigError) as cm:
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1351 config = self.db.config.init_logging()
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1352
4a948ad46579 test: fix testDictLoggerConfigViaJson
John Rouillard <rouilj@ieee.org>
parents: 8423
diff changeset
1353 # 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
1354 # 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
1355 # 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
1356 # 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
1357 # E.G.
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1358 # ("Error loading logging dict from '
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1359 # '_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
1360 # "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
1361 # "or directory: "
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1362 # "'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
1363 # sigh.....
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1364 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
1365 cm.exception.args[0].replace(r'\\','\\'))
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1366 target = ("Error loading logging dict from "
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1367 "%s.\n"
cdf876bcd370 test: test dictLoggerConfig - working logging reset and windows
John Rouillard <rouilj@ieee.org>
parents: 8427
diff changeset
1368 "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
1369 "[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
1370 "%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
1371 self.assertEqual(output, target)
8427
b34c3b8338f0 test: more fun with logger leakage.
John Rouillard <rouilj@ieee.org>
parents: 8426
diff changeset
1372
8434
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1373 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
1374 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
1375
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1376 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
1377
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1378 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
1379 self.db.config.init_logging()
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1380
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1381 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
1382 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
1383 "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
1384
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1385 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
1386
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1387 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
1388 self.db.config.init_logging()
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1389
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1390 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
1391 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
1392 "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
1393
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1394 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
1395
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1396 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
1397 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
1398
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1399 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
1400
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1401
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1402 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
1403 self.db.config.init_logging()
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1404
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1405 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
1406 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
1407 "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
1408 "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
1409
66284037142e refactor: also error on missing file or invalid extension
John Rouillard <rouilj@ieee.org>
parents: 8433
diff changeset
1410 self.db.config['LOGGING_CONFIG'] = saved_config

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