annotate test/test_config.py @ 8423:94eed885e958

feat: add support for using dictConfig to configure logging. Basic logging config (one level and one output file non-rotating) was always possible from config.ini. However the LOGGING_CONFIG setting could be used to load an ini fileConfig style file to set various channels (e.g. roundup.hyperdb) (also called qualname or tags) with their own logging level, destination (rotating file, socket, /dev/null) and log format. This is now a deprecated method in newer logging modules. The dictConfig format is preferred and allows disabiling other loggers as well as invoking new loggers in local code. This commit adds support for it reading the dict from a .json file. It also implements a comment convention so you can document the dictConfig. configuration.py: new code test_config.py: test added for the new code. admin_guide.txt, upgrading.txt CHANGES.txt: docs added upgrading references the section in admin_guid.
author John Rouillard <rouilj@ieee.org>
date Tue, 19 Aug 2025 22:32:46 -0400
parents 1e38ca6fb16e
children 4a948ad46579
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
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
23 import shutil
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
24 import sys
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
25 import unittest
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
26
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
27 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
28 from textwrap import dedent
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
29
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
30 from roundup import configuration
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
31 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
32 from roundup.hyperdb import DatabaseError
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
33
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
34 from .db_test_base import config
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
35
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
36 if not have_backend('postgresql'):
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
37 # 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
38 # 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
39 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
40 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
41 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
42 else:
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
43 try:
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
44 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
45 get_database_schema_names
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
46 db_command(config, 'select 1')
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
47 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
48 except( DatabaseError ) as msg:
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
49 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
50 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
51 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
52
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
53
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
54 try:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
55 import xapian
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
56 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
57 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
58 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
59 "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
60 except ImportError:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
61 # 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
62 # 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
63 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
64 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
65 "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
66 include_no_xapian = lambda func, *args, **kwargs: func
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
67
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
68
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
69 try:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
70 import redis
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
71 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
72 except ImportError:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
73 # 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
74 # 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
75 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
76 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
77 "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
78
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
79 _py3 = sys.version_info[0] > 2
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
80 if _py3:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
81 skip_py2 = lambda func, *args, **kwargs: func
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
82 else:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
83 # FIX: workaround for a bug in pytest.mark.skip():
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
84 # https://github.com/pytest-dev/pytest/issues/568
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
85 from .pytest_patcher import mark_class
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
86 skip_py2 = mark_class(pytest.mark.skip(
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
87 reason='Skipping test under python2.'))
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
88
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
89
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
90 config = configuration.CoreConfig()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
91 config.DATABASE = "db"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
92 config.RDBMS_NAME = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
93 config.RDBMS_HOST = "localhost"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
94 config.RDBMS_USER = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
95 config.RDBMS_PASSWORD = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
96 config.RDBMS_TEMPLATE = "template0"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
97 # 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
98 config.MAIL_DOMAIN = "your.tracker.email.domain.example"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
99 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
100 # 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
101 # 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
102 # to 'run_tests.py' script
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
103 #config.LOGGING_FILENAME = "/tmp/logfile"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
104 #config.LOGGING_LEVEL = "DEBUG"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
105 config.init_logging()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
106 config.options['FOO'] = "value"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
107
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
108 # for TrackerConfig test class
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
109 from roundup import instance
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
110 from . import db_test_base
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
111
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
112 class ConfigTest(unittest.TestCase):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
113
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
114 def test_badConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
115 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
116 """
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
117 self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName")
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
118
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
119 def test_validConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
120 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
121 """
5794
95a366d46065 Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
122 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
123
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
124 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
125 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
126
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
127 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
128 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
129 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
130 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
131
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
132 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
133 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
134
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
135 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
136 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
137
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
138 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
139 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
140
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
141 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
142 config._get_option('TRACKER_WEB').set, "")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
143
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
144 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
145 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
146
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
147 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
148 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
149 "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
150 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
151
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
152 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
153 "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
154
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
155 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
156 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
157
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
158 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
159 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
160 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
161 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
162
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
163 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
164 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
165
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
166 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
167 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
168
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
169 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
170 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
171
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
172 def testTimeZone(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
173 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
174
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
175 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
176 config._get_option('TIMEZONE').set("0"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
177
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
178 # not a valid timezone
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
179 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
180 config._get_option('TIMEZONE').set, "Zot")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
181
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
182 # 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
183 # 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
184 # constrain to this range.
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
185 #self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
186 # config._get_option('TIMEZONE').set, "25")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
187
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
188 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
189 import pytz
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
190 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
191 config._get_option('TIMEZONE').set("UTC"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
192 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
193 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
194 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
195 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
196 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
197 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
198
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
199 except ImportError:
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
200 # 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
201 # 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
202 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
203 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
204 # 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
205 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
206 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
207 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
208 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
209
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
210
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
211 def testWebSecretKey(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
212 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
213
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
214 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
215 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
216
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
217 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
218 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
219
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 def testStaticFiles(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
222 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
223
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
224
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
225 if ("/tmp/bar" == normpath("/tmp/bar/")):
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
226 result_list = ["./foo", "/tmp/bar"]
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
227 else:
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
228 result_list = [".\\foo", "\\tmp\\bar"]
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
229 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
230 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
231 print(config.STATIC_FILES)
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
232 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
233
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
234 def testIsolationLevel(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
235 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
236
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
237 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
238 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
239 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
240 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
241 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
242 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
243
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 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
246 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
247
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
248 def testConfigSave(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
249
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
250 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
251 # 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
252
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
253 self.startdir = os.getcwd()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
254
7584
a5629f6e7ec2 test: fix mising / in directory spec.
John Rouillard <rouilj@ieee.org>
parents: 7556
diff changeset
255 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
256 os.mkdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
257
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
258 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
259 os.chdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
260 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
261 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
262 config.save()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
263 config.save() # creates .bak file
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
264 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
265 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
266 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
267 # 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
268 # 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
269 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
270
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
271 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
272 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
273 config.save("foo.bar")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
274 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
275 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
276 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
277
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
278 finally:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
279 # cleanup scratch directory and files
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
280 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
281 os.chdir(self.startdir)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
282 shutil.rmtree(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
283 except OSError as error:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
284 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
285
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
286 def testFloatAndInt_with_update_option(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
287
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
288 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
289
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
290 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
291 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
292 configuration.IntegerNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
293 "0", description="new desc")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
294
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
295 # -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
296 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
297 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
298
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
299 # but can't float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
300 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
301 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
302
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
303 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
304 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
305 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
306
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
307 # Update existing IntegerNumberOption to FloatNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
308 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
309 configuration.FloatNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
310 "0.0")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
311
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
312 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
313
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
314 # can float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
315 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
316 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
317
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
318 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
319 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
320 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
321
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
322 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
323 places=6)
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
324
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
325 # 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
326 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
327 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
328
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
329 self.assertEqual("3",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
330 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
331
7556
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
332 def testIntegerNumberGtZeroOption(self):
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
333
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
334 config = configuration.CoreConfig()
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
335
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
336 # 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
337 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
338 configuration.IntegerNumberGtZeroOption,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
339 "1", description="new desc")
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
340
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
341 self.assertEqual(None,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
342 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
343
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
344 # -1 is not allowed
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
345 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
346 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
347
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
348 # 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
349 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
350 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
351
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
352 # 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
353 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
354 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
355
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
356
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
357 def testOriginHeader(self):
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
358 config = configuration.CoreConfig()
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
359
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
360 with self.assertRaises(configuration.OptionValueError) as cm:
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
361 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
362
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
363 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
364
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
365 self.assertEqual(config['WEB_ALLOWED_API_ORIGINS'][0], '*')
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
366 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
367 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
368
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
369
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
370
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
371 def testOptionAsString(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
372
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
373 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
374
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
375 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
376
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
377 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
378 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
379 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
380
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
381 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
382 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
383 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
384
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
385 def testBooleanOption(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
386
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
387 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
388
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
389 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
390 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
391
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
392 # test multiple boolean representations
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
393 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
394 "oN", 1, True ]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
395 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
396 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
397 self.assertEqual(1,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
398 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
399
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
400 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
401 "oFf", 0, False]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
402 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
403 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
404 self.assertEqual(0,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
405 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
406
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
407 def testOctalNumberOption(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
408
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
409 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
410
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
411 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
412 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
413
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
414 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
415
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
416
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
417 class TrackerConfig(unittest.TestCase):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
418
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
419 backend = 'anydbm'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
420
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
421 def setUp(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
422 self.dirname = '_test_instance'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
423 # 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
424 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
425
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
426 # open the database
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
427 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
428
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
429 self.db.commit()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
430 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
431
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
432 def tearDown(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
433 if self.db:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
434 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
435 try:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
436 shutil.rmtree(self.dirname)
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
437 except OSError as error:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
438 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
439
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
440 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
441 """ modify config.ini to meet testing requirements
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
442
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
443 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
444 [ ( "a = ", "b" ), ("c = ", None), ("d = ", "b", "z = ") ]
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
445 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
446 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
447 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
448 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
449 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
450 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
451 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
452 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
453 elements (used to replace commented out parameters).
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
454
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
455 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
456 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
457 section name.
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
458 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
459
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
460 if mods is None:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
461 return
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
462
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
463 # 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
464 # 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
465 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
466
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
467 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
468 inplace=True):
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
469 if section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
470 if line.startswith('['):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
471 in_section = False
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
472
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
473 if line.startswith(section):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
474 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
475
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
476 if in_section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
477 for rule in mods:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
478 if len(rule) == 3:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
479 match, value, repl = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
480 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
481 match, value = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
482 repl = None
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
483
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
484 if line.startswith(match):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
485 if value is not None:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
486 if repl:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
487 print(repl + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
488 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
489 print(match + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
490 break
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
491 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
492 print(line[:-1]) # remove trailing \n
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
493 else:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
494 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
495
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
496 def testNoDBInConfig(self):
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
497 """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
498 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
499 configuration module with a missing required param in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
500 config.ini.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
501 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
502
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
503 # remove the backend key in config.ini
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
504 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
505
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
506 # 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
507 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
508 instance.open(self.dirname)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
509
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
510 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
511 " 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
512
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
513 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
514 """ 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
515 [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
516 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
517 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
518 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
519 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
520
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
521 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
522
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
523 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
524 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
525
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
526 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
527 # 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
528 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
529 # look for 'not defined'
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
530 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
531
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
532
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
533 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
534 """ 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
535 [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
536 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
537 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
538
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
539 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
540
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
541 self.assertEqual(config['MAIL_USERNAME'], '')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
542
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
543 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
544 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
545
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
546 def testSecretMandatory_missing_file(self):
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 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
549 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
550
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
551 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
552
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
553 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
554 config.load(self.dirname)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
555
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
556 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
557 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
558
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
559 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
560
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
561 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
562 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
563
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
564 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
565 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
566 f.write(secret + "\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
567
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
568 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
569
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
570 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
571
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
572 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
573
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
574
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
575 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
576
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
577 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
578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
579 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
580 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
581
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
582 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
583 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
584 f.write(secret + "\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
585
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
586 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
587
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 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
591
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
592 os.remove(abs_file)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
593
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
594 def testSecretMandatory_empty_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
595
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
596 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
597
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
598 # 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
599 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
600 f.write("\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
601
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
602 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
603
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
604 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
605 config.load(self.dirname)
6578
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 print(cm.exception.args)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
608 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
609
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
610 def testNullableSecret_empty_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 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
613
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
614 # 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
615 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
616 f.write("\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
617
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
618 config = configuration.CoreConfig()
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 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
621
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
622 v = config['RDBMS_PASSWORD']
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
623
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
624 self.assertEqual(v, None)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
625
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
626 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
627
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
628 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
629
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
630 # 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
631 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
632 f.write("test\n")
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 = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
635
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
636 config.load(self.dirname)
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 v = config['RDBMS_PASSWORD']
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
639
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
640 self.assertEqual(v, "test")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
641
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
642 def testNullableSecret_with_value(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
643
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
644 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
645
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
646 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
647
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
648 config.load(self.dirname)
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 v = config['RDBMS_PASSWORD']
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 self.assertEqual(v, "test")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
653
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
654 def testListSecret_for_jwt_invalid_secret(self):
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
655 """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
656 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
657 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
658 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
659 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
660 """
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
661 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
662
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
663 config = configuration.CoreConfig()
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
664
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
665 with self.assertRaises(configuration.OptionValueError) as cm:
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
666 config.load(self.dirname)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
667
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
668 print(cm.exception.args)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
669 self.assertEqual(
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
670 cm.exception.args[2],
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
671 "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
672
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
673 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
674 """ 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
675 Should have both values set.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
676 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
677 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
678 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
679 ("#password = ", "passwordfoo",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
680 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
681 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
682
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
683 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
684
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
685 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
686
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
687 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
688 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
689
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
690 def testSetMailPassword_from_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
691 """ 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
692 Should have both values set.
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 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
695 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
696 ("#password = ", "file://password",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
697 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
698 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
699 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
700 f.write("passwordfoo\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
701
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
702 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
703
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
704 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
705
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
706 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
707 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
708
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
709 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
710 def testInvalidIndexerLanguage_w_empty(self):
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
711 """ 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
712 invalid indexer language is specified. This uses
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
713 default search path for indexers.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
714 """
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
715
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
716 # 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
717 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
718 ("indexer_language = ", "NO_LANG") ])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
719
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
720 config = configuration.CoreConfig()
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
721
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
722 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
723 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
724
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
725 print(cm.exception)
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
726 # 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
727 self.assertIn("OptionValueError", repr(cm.exception))
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
728 # look for failing language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
729 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
730 # look for supported language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
731 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
732
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
733 @include_no_xapian
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
734 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
735 """ 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
736
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
737 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
738 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
739 """
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
740 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
741
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
742 # 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
743 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
744 ("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
745
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
746 config = configuration.CoreConfig()
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
747
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
748 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
749
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
750 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
751
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
752 def testInvalidIndexerLanguage_xapian_missing(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
753 """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
754 fail and prevent exception from happening even though
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
755 the indexer_language would be invalid for xapian.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
756 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
757
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
758 print("Testing xapian not loadable")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
759
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
760 # SETUP: same as testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
761 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
762 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
763
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
764 import sys
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
765 # 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
766 sys.modules['xapian'] = None
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
767 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
768
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
769 # 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
770 del(sys.modules['xapian'])
6371
5c1db5d4baed Fix failing xapian test
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6368
diff changeset
771 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
772 del(sys.modules['xapian._xapian'])
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
773
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
774 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
775
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
776 # 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
777 # to do setup in a different test
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
778 config.reset()
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
779 self.assertEqual(config['INDEXER_LANGUAGE'], 'english')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
780
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
781 def testInvalidIndexerLanguage_w_native(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
782 """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
783 Config load should succeed without exception.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
784 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
785
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
786 print("Testing indexer = native")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
787
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
788 self.munge_configini(mods = [ ("indexer = ", "native"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
789 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
790
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
791 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
792
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
793 self.assertEqual(config['HTML_VERSION'], 'html4')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
794 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
795
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
796 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
797 def testInvalidIndexerLanguage_w_xapian(self):
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
798 """ Use explicit xapian indexer. Verify exception is
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
799 generated.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
800 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
801
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
802 print("Testing explicit xapian")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
803
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
804 self.munge_configini(mods=[ ("indexer = ", "xapian"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
805 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
806
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
807 with self.assertRaises(configuration.OptionValueError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
808 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
809 # don't test exception content. Done in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
810 # testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
811 # if exception not generated assertRaises
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
812 # will generate failure.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
813
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
814 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
815 """ 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
816 generated.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
817 """
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
818
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
819 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
820 ("indexer_language = ", "NO_LANG") ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
821
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
822 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
823 config.load(self.dirname)
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
824
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
825 # 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
826 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
827 # look for failing language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
828 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
829 # look for supported language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
830 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
831
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
832 @skip_redis
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
833 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
834 """ 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
835
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
836 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
837
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
838 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
839 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
840 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
841
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
842 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
843
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
844 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
845 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
846 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
847
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
848 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
849
7900
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
850 @skip_redis
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
851 @skip_postgresql
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
852 def testLoadSessionDbRedisIncompatible(self):
011941fcb598 test: skip test requiring postgresql backend if not present
John Rouillard <rouilj@ieee.org>
parents: 7809
diff changeset
853 """ 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
854 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
855 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
856 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
857
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
858 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
859 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
860
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
861 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
862 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
863
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
864 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
865 """ 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
866
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
867 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
868
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
869 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
870 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
871 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
872
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
873 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
874 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
875
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
876 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
877 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
878
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
879 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
880 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
881 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
882
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
883 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
884
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
885 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
886 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
887
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
888 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
889
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
890 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
891 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
892
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
893 # 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
894 try:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
895 del(sys.modules['redis'])
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
896 except KeyError:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
897 # redis is not available anyway.
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
898 pass
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
899
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
900 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
901 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
902 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
903 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
904
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
905 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
906 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
907
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
908 def testLoadConfig(self):
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
909 """ run load to validate config """
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
910
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
911 config = configuration.CoreConfig()
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
912
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
913 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
914
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
915 # 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
916 with self.assertRaises(configuration.InvalidOptionError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
917 # using lower case name fails
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
918 c = config['indexer_language']
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
919 print(cm.exception)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
920 self.assertIn("indexer_language", repr(cm.exception))
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
921
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
922 # 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
923 self.assertEqual(config['HTML_VERSION'], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
924 self.assertEqual(config[('main', 'html_version')], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
925
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
926 # 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
927 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
928 self.assertEqual(config[('web','cookie_takes_precedence')], 0)
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
929
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
930
6359
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
931 def testLoadConfigNoConfig(self):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
932 """ 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
933
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
934 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
935 if os.path.exists(c):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
936 os.remove(c)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
937 else:
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
938 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
939
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
940 config = configuration.CoreConfig()
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
941
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
942 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
943 config.load(self.dirname)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
944
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
945 print(cm.exception)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
946 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
947
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
948
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
949 def testXhtmlRaisesOptionError(self):
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
950 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
951
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
952 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
953
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
954 # 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
955 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
956
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
957
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
958 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
959 # load config
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
960 config.load(self.dirname)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
961
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
962 print(cm.exception)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
963 self.assertEqual(str(cm.exception),
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
964 "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
965 "Allowed values: html4")
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
967 def testCopyConfig(self):
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
968
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
969 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
970
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
971 config = configuration.CoreConfig()
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
972
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
973 # verify config is initalized to defaults
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
974 self.assertEqual(config['STATIC_FILES'], None)
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
975
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
976 # load config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
977 config.load(self.dirname)
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
978 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
979
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
980 # copy config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
981 config_copy = config.copy()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
982
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
983 # this should work
7966
1e38ca6fb16e test: clean up test for deprecation of xhtml.
John Rouillard <rouilj@ieee.org>
parents: 7913
diff changeset
984 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
985
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
986 @skip_py2
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
987 def testConfigValueInterpolateError(self):
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
988 ''' error is not raised using ConfigParser under Python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
989 Unknown cause, so skip it if running python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
990 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
991
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
992 self.munge_configini(mods=[ ("admin_email = ", "a bare % is invalid") ])
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
993
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
994 config = configuration.CoreConfig()
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
995
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
996 # load config generates:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
997 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
998 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
999 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1000
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1001 with self.assertRaises(configuration.ParsingOptionError) as cm:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1002 config.load(self.dirname)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1003
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1004 print(cm.exception)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1005 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
1006 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
1007
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
1008
6560
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1009 from roundup.admin import AdminTool
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1010 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
1011
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1012 admin=AdminTool()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1013 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
1014 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
1015 ret = admin.main()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1016
7913
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1017 expected_err = ("Error in " +
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1018 normpath("_test_instance/config.ini") +
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1019 " with section [main] at option admin_email: '%' "
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1020 "must be followed by '%' or '(', found: "
6102ae426390 issue2551334 - get test suite running under windows
John Rouillard <rouilj@ieee.org>
parents: 7900
diff changeset
1021 "'% is invalid'")
6560
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1022
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1023 self.assertEqual(ret, 1)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1024 out = out.getvalue().strip()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1025 self.assertEqual(out, expected_err)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
1026
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1027 def testInvalidIndexerValue(self):
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1028 """ Mistype native indexer. Verify exception is
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1029 generated.
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1030 """
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1031
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1032 print("Testing indexer nati")
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1033
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1034 self.munge_configini(mods=[ ("indexer = ", "nati") ])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1035
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1036 with self.assertRaises(configuration.OptionValueError) as cm:
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1037 config.load(self.dirname)
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1038
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1039 self.assertIn("OptionValueError", repr(cm.exception))
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1040 # look for failing value
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1041 self.assertEqual("nati", cm.exception.args[1])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1042 # look for supported values
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1043 self.assertIn("'whoosh'", cm.exception.args[2])
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
1044
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1045 # 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
1046 string_rep = cm.exception.__str__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1047 print(string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1048 self.assertIn("nati", string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
1049 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
1050
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1051 def testDictLoggerConfigViaJson(self):
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1052
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1053 # test case broken, comment on version line misformatted
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1054 config1 = dedent("""
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1055 {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1056 "version": 1, # only supported version
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1057 "disable_existing_loggers": false, # keep the wsgi loggers
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1058
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1059 "formatters": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1060 # standard Roundup formatter including context id.
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1061 "standard": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1062 "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
1063 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1064 # used for waitress wsgi server to produce httpd style logs
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1065 "http": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1066 "format": "%(message)s"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1067 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1068 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1069 "handlers": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1070 # create an access.log style http log file
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1071 "access": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1072 "level": "INFO",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1073 "formatter": "http",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1074 "class": "logging.FileHandler",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1075 "filename": "demo/access.log"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1076 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1077 # logging for roundup.* loggers
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1078 "roundup": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1079 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1080 "formatter": "standard",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1081 "class": "logging.FileHandler",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1082 "filename": "demo/roundup.log"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1083 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1084 # print to stdout - fall through for other logging
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1085 "default": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1086 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1087 "formatter": "standard",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1088 "class": "logging.StreamHandler",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1089 "stream": "ext://sys.stdout"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1090 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1091 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1092 "loggers": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1093 "": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1094 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1095 "default" # used by wsgi/usgi
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1096 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1097 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1098 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1099 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1100 # used by roundup.* loggers
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1101 "roundup": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1102 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1103 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1104 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1105 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1106 "propagate": false # note pytest testing with caplog requires
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1107 # this to be true
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1108 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1109 "roundup.hyperdb": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1110 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1111 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1112 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1113 "level": "INFO", # can be a little noisy INFO for production
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1114 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1115 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1116 "roundup.wsgi": { # using the waitress framework
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1117 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1118 "roundup"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1119 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1120 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1121 "propagate": false
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 "roundup.wsgi.translogger": { # httpd style logging
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1124 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1125 "access"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1126 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1127 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1128 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1129 },
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1130 "root": {
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1131 "handlers": [
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1132 "default"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1133 ],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1134 "level": "DEBUG",
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1135 "propagate": false
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1136 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1137 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1138 }
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1139 """)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1140
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1141 log_config_filename = self.instance.tracker_home \
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1142 + "/_test_log_config.json"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1143
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1144 # happy path
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1145 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
1146 log_config_file.write(config1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1147
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1148 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
1149 log_config_filename)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1150 self.assertIn("version", config)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1151 self.assertEqual(config['version'], 1)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1152
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1153 # broken inline comment misformatted
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1154 test_config = config1.replace(": 1, #", ": 1, #")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1155 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
1156 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
1157
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1158 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
1159 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
1160 log_config_filename)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1161 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1162 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1163 ('Error parsing json logging dict '
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1164 '(_test_instance/_test_log_config.json) near \n\n '
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1165 '"version": 1, # only supported version\n\nExpecting '
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1166 'property name enclosed in double quotes: line 3 column 18.\n'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1167 'Maybe bad inline comment, 3 spaces needed before #.')
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
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1170 # 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
1171 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
1172 ' "ext://sys.stdout",'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1173 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1174 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
1175 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
1176
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1177 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
1178 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
1179 log_config_filename)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1180 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1181 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1182 ('Error parsing json logging dict '
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1183 '(_test_instance/_test_log_config.json) near \n\n'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1184 ' }\n\nExpecting property name enclosed in double '
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1185 'quotes: line 37 column 6.')
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1186 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1187
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1188 # happy path for init_logging()
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1189
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1190 # verify preconditions
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1191 logger = logging.getLogger("roundup")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1192 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
1193 self.assertEqual(logger.filters, [])
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1194
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1195 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
1196 log_config_file.write(config1)
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 # 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
1199 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
1200 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
1201 self.assertIs(config, None)
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 logger = logging.getLogger("roundup")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1204 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
1205 self.assertEqual(logger.filters, [])
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1206
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1207 # 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
1208 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
1209 '"format": 1234',)
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1210 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
1211 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
1212
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1213 # 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
1214 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
1215 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
1216 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
1217 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1218 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1219 ('Error loading logging dict from '
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1220 '_test_instance/_test_log_config.json.\n'
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1221 "ValueError: Unable to configure formatter 'http'\n"
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1222 'expected string or bytes-like object\n')
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1223 )
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1224
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1225 # broken invalid level MANGO
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1226 test_config = config1.replace(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1227 ': "INFO", # can',
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1228 ': "MANGO", # can')
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1229 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
1230 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
1231
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1232 # 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
1233 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
1234 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
1235 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
1236 self.assertEqual(
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1237 cm.exception.args[0],
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1238 ("Error loading logging dict from "
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1239 "_test_instance/_test_log_config.json.\nValueError: "
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1240 "Unable to configure logger 'roundup.hyperdb'\nUnknown level: "
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1241 "'MANGO'\n")
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1242
94eed885e958 feat: add support for using dictConfig to configure logging.
John Rouillard <rouilj@ieee.org>
parents: 7966
diff changeset
1243 )

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