annotate test/test_config.py @ 7859:9a74dfeb8620

feat: can use escaped tokens inside quotes including quotes. Change tokenizer to support: cmd with arg "string with embedded \" double quote" works for single quotes too. Mixed quotes can skip the \" or \' escaping. Also: quoted cmds args "can include \n newline, \t tab and \r return" Added a doc example, also tests for new feature.
author John Rouillard <rouilj@ieee.org>
date Sat, 06 Apr 2024 20:37:45 -0400
parents be6cb2e0d471
children 011941fcb598
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
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
18 import unittest
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
19 import logging
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
20 import fileinput
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
21
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
22 import os, shutil, errno, sys
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
23
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
24 import pytest
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
25 from roundup import configuration
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
26
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
27 try:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
28 import xapian
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
29 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
30 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
31 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
32 "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
33 except ImportError:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
34 # 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
35 # 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
36 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
37 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
38 "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
39 include_no_xapian = lambda func, *args, **kwargs: func
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
40
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
41
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
42 try:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
43 import redis
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
44 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
45 except ImportError:
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
46 # 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
47 # 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
48 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
49 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
50 "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
51
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
52 _py3 = sys.version_info[0] > 2
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
53 if _py3:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
54 skip_py2 = lambda func, *args, **kwargs: func
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
55 else:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
56 # FIX: workaround for a bug in pytest.mark.skip():
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
57 # https://github.com/pytest-dev/pytest/issues/568
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
58 from .pytest_patcher import mark_class
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
59 skip_py2 = mark_class(pytest.mark.skip(
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
60 reason='Skipping test under python2.'))
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
61
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
62
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
63 config = configuration.CoreConfig()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
64 config.DATABASE = "db"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
65 config.RDBMS_NAME = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
66 config.RDBMS_HOST = "localhost"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
67 config.RDBMS_USER = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
68 config.RDBMS_PASSWORD = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
69 config.RDBMS_TEMPLATE = "template0"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
70 # 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
71 config.MAIL_DOMAIN = "your.tracker.email.domain.example"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
72 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
73 # 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
74 # 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
75 # to 'run_tests.py' script
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
76 #config.LOGGING_FILENAME = "/tmp/logfile"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
77 #config.LOGGING_LEVEL = "DEBUG"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
78 config.init_logging()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
79 config.options['FOO'] = "value"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
80
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
81 # for TrackerConfig test class
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
82 from roundup import instance
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
83 from . import db_test_base
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
84
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
85 class ConfigTest(unittest.TestCase):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
86
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
87 def test_badConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
88 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
89 """
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
90 self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName")
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
91
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
92 def test_validConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
93 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
94 """
5794
95a366d46065 Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
95 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
96
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
97 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
98 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
99
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
100 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
101 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
102 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
103 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
104
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
105 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
106 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
107
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
108 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
109 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
110
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
111 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
112 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
113
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
114 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
115 config._get_option('TRACKER_WEB').set, "")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
116
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
117 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
118 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
119
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
120 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
121 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
122 "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
123 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
124
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
125 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
126 "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
127
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
128 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
129 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
130
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
131 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
132 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
133 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
134 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
135
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
136 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
137 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
138
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
139 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
140 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
141
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
142 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
143 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
144
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
145 def testTimeZone(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
146 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
147
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
148 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
149 config._get_option('TIMEZONE').set("0"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
150
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
151 # not a valid timezone
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
152 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
153 config._get_option('TIMEZONE').set, "Zot")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
154
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
155 # 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
156 # 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
157 # constrain to this range.
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
158 #self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
159 # config._get_option('TIMEZONE').set, "25")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
160
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
161 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
162 import pytz
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
163 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
164 config._get_option('TIMEZONE').set("UTC"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
165 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
166 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
167 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
168 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
169 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
170 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
171
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
172 except ImportError:
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
173 # 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
174 # 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
175 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
176 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
177 # 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
178 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
179 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
180 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
181 config._get_option('TIMEZONE').set, "America/New_York")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
182
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
183
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
184 def testWebSecretKey(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
185 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
186
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
187 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
188 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
189
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
190 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
191 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
192
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
193
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
194 def testStaticFiles(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
195 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
196
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
197 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
198 config._get_option('STATIC_FILES').set("foo /tmp/bar"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
199
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
200 self.assertEqual(config.STATIC_FILES,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
201 ["./foo", "/tmp/bar"])
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
202
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
203 self.assertEqual(config['STATIC_FILES'],
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
204 ["./foo", "/tmp/bar"])
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
205
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
206 def testIsolationLevel(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
207 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
208
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
209 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
210 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
211 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
212 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
213 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
214 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
215
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('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
219
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
220 def testConfigSave(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
221
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
222 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
223 # 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
224
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
225 self.startdir = os.getcwd()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
226
7584
a5629f6e7ec2 test: fix mising / in directory spec.
John Rouillard <rouilj@ieee.org>
parents: 7556
diff changeset
227 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
228 os.mkdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
229
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
230 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
231 os.chdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
232 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
233 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
234 config.save()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
235 config.save() # creates .bak file
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
236 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
237 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
238 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
239 # 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
240 # 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
241 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
242
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
243 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
244 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
245 config.save("foo.bar")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
246 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
247 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
248 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
249
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
250 finally:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
251 # cleanup scratch directory and files
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
252 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
253 os.chdir(self.startdir)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
254 shutil.rmtree(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
255 except OSError as error:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
256 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
257
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
258 def testFloatAndInt_with_update_option(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
259
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
260 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
261
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
262 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
263 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
264 configuration.IntegerNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
265 "0", description="new desc")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
266
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
267 # -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
268 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
269 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
270
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
271 # but can't float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
272 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
273 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
274
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
275 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
276 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
277 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
278
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
279 # Update existing IntegerNumberOption to FloatNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
280 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
281 configuration.FloatNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
282 "0.0")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
283
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
284 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
285
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
286 # can float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
287 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
288 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
289
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
290 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
291 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
292 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
293
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
294 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
295 places=6)
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
296
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
297 # 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
298 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
299 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
300
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
301 self.assertEqual("3",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
302 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
303
7556
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
304 def testIntegerNumberGtZeroOption(self):
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
305
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
306 config = configuration.CoreConfig()
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
307
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
308 # 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
309 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
310 configuration.IntegerNumberGtZeroOption,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
311 "1", description="new desc")
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
312
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
313 self.assertEqual(None,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
314 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
315
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
316 # -1 is not allowed
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
317 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
318 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
319
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
320 # 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
321 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
322 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
323
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
324 # 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
325 self.assertRaises(configuration.OptionValueError,
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
326 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
327
273c8c2b5042 fix(api): - issue2551063 - Rest/Xmlrpc interfaces needs failed login protection.
John Rouillard <rouilj@ieee.org>
parents: 7155
diff changeset
328
6681
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
329 def testOriginHeader(self):
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
330 config = configuration.CoreConfig()
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
331
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
332 with self.assertRaises(configuration.OptionValueError) as cm:
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
333 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
334
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
335 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
336
7155
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
337 self.assertEqual(config['WEB_ALLOWED_API_ORIGINS'][0], '*')
89a59e46b3af improve REST interface security
John Rouillard <rouilj@ieee.org>
parents: 6821
diff changeset
338 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
339 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
340
ab2ed11c021e issue2551205: Add support for specifying valid origins for api: xmlrpc/rest
John Rouillard <rouilj@ieee.org>
parents: 6604
diff changeset
341
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
342
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
343 def testOptionAsString(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
344
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
345 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
346
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
347 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
348
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
349 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
350 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
351 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
352
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
353 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
354 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
355 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
356
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
357 def testBooleanOption(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
358
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
359 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
360
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
361 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
362 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
363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
364 # test multiple boolean representations
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
365 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
366 "oN", 1, True ]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
367 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
368 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
369 self.assertEqual(1,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
370 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
371
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
372 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
373 "oFf", 0, False]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
374 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
375 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
376 self.assertEqual(0,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
377 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
378
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
379 def testOctalNumberOption(self):
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 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
382
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
383 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
384 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
385
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
386 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
387
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
388
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
389 class TrackerConfig(unittest.TestCase):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
390
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
391 backend = 'anydbm'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
392
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
393 def setUp(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
394 self.dirname = '_test_instance'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
395 # 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
396 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
397
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
398 # open the database
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
399 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
400
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
401 self.db.commit()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
402 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
403
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
404 def tearDown(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
405 if self.db:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
406 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
407 try:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
408 shutil.rmtree(self.dirname)
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
409 except OSError as error:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
410 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
411
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
412 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
413 """ modify config.ini to meet testing requirements
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
414
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
415 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
416 [ ( "a = ", "b" ), ("c = ", None), ("d = ", "b", "z = ") ]
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
417 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
418 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
419 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
420 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
421 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
422 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
423 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
424 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
425 elements (used to replace commented out parameters).
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
426
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
427 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
428 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
429 section name.
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
430 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
431
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
432 if mods is None:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
433 return
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
434
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
435 # 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
436 # 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
437 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
438
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
439 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
440 inplace=True):
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
441 if section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
442 if line.startswith('['):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
443 in_section = False
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
444
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
445 if line.startswith(section):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
446 in_section = True
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
447
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
448 if in_section:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
449 for rule in mods:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
450 if len(rule) == 3:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
451 match, value, repl = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
452 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
453 match, value = rule
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
454 repl = None
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
455
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
456 if line.startswith(match):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
457 if value is not None:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
458 if repl:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
459 print(repl + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
460 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
461 print(match + value)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
462 break
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
463 else:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
464 print(line[:-1]) # remove trailing \n
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
465 else:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
466 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
467
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
468 def testNoDBInConfig(self):
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
469 """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
470 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
471 configuration module with a missing required param in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
472 config.ini.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
473 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
474
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
475 # remove the backend key in config.ini
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
476 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
477
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
478 # 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
479 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
480 instance.open(self.dirname)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
481
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
482 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
483 " 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
484
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
485 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
486 """ 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
487 [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
488 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
489 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
490 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
491 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
492
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
493 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
494
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
495 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
496 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
497
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
498 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
499 # 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
500 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
501 # look for 'not defined'
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
502 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
503
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
504
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
505 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
506 """ 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
507 [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
508 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
509 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
510
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
511 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
512
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
513 self.assertEqual(config['MAIL_USERNAME'], '')
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
514
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
515 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
516 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
517
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
518 def testSecretMandatory_missing_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
519
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
520 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
521 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
522
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
523 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
524
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
525 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
526 config.load(self.dirname)
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
527
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
528 print(cm.exception)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
529 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
530
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
531 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
532
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
533 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
534 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
535
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
536 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
537 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
538 f.write(secret + "\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
539
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
540 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
541
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
542 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
543
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
544 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
545
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
546
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
547 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
548
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
549 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
550
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
551 # SETUP:
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
552 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
553
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
554 secret = "ASDQWEZXCRFVBGTYHNMJU"
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
555 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
556 f.write(secret + "\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
557
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
558 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
559
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
560 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
561
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
562 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
563
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
564 os.remove(abs_file)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
565
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
566 def testSecretMandatory_empty_file(self):
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 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
569
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
570 # 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
571 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
572 f.write("\n")
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 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
575
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
576 with self.assertRaises(configuration.OptionValueError) as cm:
6584
770503bd211e Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents: 6578
diff changeset
577 config.load(self.dirname)
6578
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 print(cm.exception.args)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
580 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
581
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
582 def testNullableSecret_empty_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
583
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
584 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
585
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
586 # 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
587 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
588 f.write("\n")
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 config = configuration.CoreConfig()
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 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
593
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
594 v = config['RDBMS_PASSWORD']
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.assertEqual(v, None)
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 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
599
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
600 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
601
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
602 # 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
603 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
604 f.write("test\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
605
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
606 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
607
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
608 config.load(self.dirname)
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 v = config['RDBMS_PASSWORD']
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.assertEqual(v, "test")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
613
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
614 def testNullableSecret_with_value(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
615
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
616 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
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, "test")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
625
7809
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
626 def testListSecret_for_jwt_invalid_secret(self):
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
627 """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
628 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
629 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
630 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
631 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
632 """
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
633 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
634
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
635 config = configuration.CoreConfig()
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
636
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
637 with self.assertRaises(configuration.OptionValueError) as cm:
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
638 config.load(self.dirname)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
639
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
640 print(cm.exception.args)
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
641 self.assertEqual(
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
642 cm.exception.args[2],
be6cb2e0d471 feat: add support for rotating jwt keys
John Rouillard <rouilj@ieee.org>
parents: 7584
diff changeset
643 "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
644
6578
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
645 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
646 """ 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
647 Should have both values set.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
648 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
649 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
650 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
651 ("#password = ", "passwordfoo",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
652 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
653 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
654
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
655 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
656
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
657 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
658
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
659 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
660 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
661
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
662 def testSetMailPassword_from_file(self):
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
663 """ 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
664 Should have both values set.
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
665 """
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
666 # SETUP: set mail username
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
667 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
668 ("#password = ", "file://password",
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
669 "password = ") ],
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
670 section="[mail]")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
671 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
672 f.write("passwordfoo\n")
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
673
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
674 config = configuration.CoreConfig()
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
675
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
676 config.load(self.dirname)
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
677
b1f1539c6a31 issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents: 6560
diff changeset
678 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
679 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
680
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
681 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
682 def testInvalidIndexerLanguage_w_empty(self):
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
683 """ 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
684 invalid indexer language is specified. This uses
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
685 default search path for indexers.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
686 """
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
687
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
688 # 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
689 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
690 ("indexer_language = ", "NO_LANG") ])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
691
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
692 config = configuration.CoreConfig()
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
693
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
694 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
695 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
696
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
697 print(cm.exception)
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
698 # 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
699 self.assertIn("OptionValueError", repr(cm.exception))
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
700 # look for failing language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
701 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
702 # look for supported language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
703 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
704
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
705 @include_no_xapian
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
706 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
707 """ 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
708
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
709 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
710 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
711 """
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
712 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
713
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
714 # 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
715 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
716 ("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
717
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
718 config = configuration.CoreConfig()
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
719
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
720 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
721
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
722 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
723
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
724 def testInvalidIndexerLanguage_xapian_missing(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
725 """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
726 fail and prevent exception from happening even though
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
727 the indexer_language would be invalid for xapian.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
728 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
729
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
730 print("Testing xapian not loadable")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
731
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
732 # SETUP: same as testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
733 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
734 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
735
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
736 import sys
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
737 # 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
738 sys.modules['xapian'] = None
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
739 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
740
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
741 # 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
742 del(sys.modules['xapian'])
6371
5c1db5d4baed Fix failing xapian test
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6368
diff changeset
743 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
744 del(sys.modules['xapian._xapian'])
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
745
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
746 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
747
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
748 # 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
749 # to do setup in a different test
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
750 config.reset()
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
751 self.assertEqual(config['INDEXER_LANGUAGE'], 'english')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
752
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
753 def testInvalidIndexerLanguage_w_native(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
754 """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
755 Config load should succeed without exception.
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 indexer = native")
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 self.munge_configini(mods = [ ("indexer = ", "native"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
761 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
762
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
763 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
764
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
765 self.assertEqual(config['HTML_VERSION'], 'html4')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
766 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
767
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
768 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
769 def testInvalidIndexerLanguage_w_xapian(self):
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
770 """ Use explicit xapian indexer. Verify exception is
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
771 generated.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
772 """
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 print("Testing explicit xapian")
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 self.munge_configini(mods=[ ("indexer = ", "xapian"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
777 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
778
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
779 with self.assertRaises(configuration.OptionValueError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
780 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
781 # don't test exception content. Done in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
782 # testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
783 # if exception not generated assertRaises
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
784 # will generate failure.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
785
6604
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
786 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
787 """ 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
788 generated.
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
789 """
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
790
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
791 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
792 ("indexer_language = ", "NO_LANG") ])
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
793
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
794 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
795 config.load(self.dirname)
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
796
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
797 # 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
798 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
799 # look for failing language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
800 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
801 # look for supported language
0d99ae7c8de6 Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents: 6584
diff changeset
802 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
803
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
804 @skip_redis
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
805 def testLoadSessionDbRedis(self):
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
806 """ 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
807
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
808 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
809
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
810 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
811 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
812 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
813
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
814 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
815
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
816 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
817 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
818 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
819
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
820 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
821
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
822 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
823 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
824 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
825
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
826 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
827 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
828
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
829 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
830 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
831
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
832 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
833 """ 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
834
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
835 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
836
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
837 # incompatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
838 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
839 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
840
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
841 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
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 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
845 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
846
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
847 # compatible pair
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
848 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
849 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
850
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
851 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
852
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
853 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
854 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
855
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
856 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
857
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
858 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
859 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
860
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
861 # 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
862 try:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
863 del(sys.modules['redis'])
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
864 except KeyError:
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
865 # redis is not available anyway.
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
866 pass
e0f0aed72097 Fix test if redis is not loaded
John Rouillard <rouilj@ieee.org>
parents: 6814
diff changeset
867
6814
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
868 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
869 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
870 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
871 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
872
3f60a71b0812 Summary: Support selecion session/otk data store. Add redis as data store.
John Rouillard <rouilj@ieee.org>
parents: 6681
diff changeset
873 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
874 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
875
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
876 def testLoadConfig(self):
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
877 """ run load to validate config """
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
878
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
879 config = configuration.CoreConfig()
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
880
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
881 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
882
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
883 # 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
884 with self.assertRaises(configuration.InvalidOptionError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
885 # using lower case name fails
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
886 c = config['indexer_language']
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
887 print(cm.exception)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
888 self.assertIn("indexer_language", repr(cm.exception))
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
889
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
890 # 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
891 self.assertEqual(config['HTML_VERSION'], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
892 self.assertEqual(config[('main', 'html_version')], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
893
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
894 # 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
895 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
896 self.assertEqual(config[('web','cookie_takes_precedence')], 0)
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
897
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
898
6359
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
899 def testLoadConfigNoConfig(self):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
900 """ 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
901
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
902 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
903 if os.path.exists(c):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
904 os.remove(c)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
905 else:
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
906 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
907
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
908 config = configuration.CoreConfig()
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
909
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
910 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
911 config.load(self.dirname)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
912
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
913 print(cm.exception)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
914 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
915
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
916 def testCopyConfig(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
917
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
918 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
919
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
920 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
921
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
922 # 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
923 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
924
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
925 # load config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
926 config.load(self.dirname)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
927
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
928 # loaded new option
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
929 self.assertEqual(config['HTML_VERSION'], 'xhtml')
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
930
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
931 # copy config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
932 config_copy = config.copy()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
933
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
934 # this should work
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
935 self.assertEqual(config_copy['HTML_VERSION'], 'xhtml')
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
936
6557
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
937 @skip_py2
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
938 def testConfigValueInterpolateError(self):
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
939 ''' error is not raised using ConfigParser under Python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
940 Unknown cause, so skip it if running python 2.
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
941 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
942
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
943 self.munge_configini(mods=[ ("admin_email = ", "a bare % is invalid") ])
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
944
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
945 config = configuration.CoreConfig()
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
946
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
947 # load config generates:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
948 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
949 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
950 '''
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
951
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
952 with self.assertRaises(configuration.ParsingOptionError) as cm:
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
953 config.load(self.dirname)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
954
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
955 print(cm.exception)
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
956 self.assertIn("'%' must be followed by '%' or '(', found: '% is invalid'", cm.exception.args[0])
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
957 self.assertIn("_test_instance/config.ini with section [main] at option admin_email", cm.exception.args[0])
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
958
8687c096a945 Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents: 6371
diff changeset
959
6560
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
960 from roundup.admin import AdminTool
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
961 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
962
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
963 admin=AdminTool()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
964 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
965 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
966 ret = admin.main()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
967
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
968 expected_err = "Error in _test_instance/config.ini with section [main] at option admin_email: '%' must be followed by '%' or '(', found: '% is invalid'"
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
969
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
970 self.assertEqual(ret, 1)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
971 out = out.getvalue().strip()
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
972 self.assertEqual(out, expected_err)
fdfe3b7387ea Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents: 6557
diff changeset
973
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
974 def testInvalidIndexerValue(self):
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
975 """ Mistype native indexer. Verify exception is
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
976 generated.
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
977 """
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
978
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
979 print("Testing indexer nati")
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
980
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
981 self.munge_configini(mods=[ ("indexer = ", "nati") ])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
982
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
983 with self.assertRaises(configuration.OptionValueError) as cm:
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
984 config.load(self.dirname)
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
985
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
986 self.assertIn("OptionValueError", repr(cm.exception))
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
987 # look for failing value
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
988 self.assertEqual("nati", cm.exception.args[1])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
989 # look for supported values
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
990 self.assertIn("'whoosh'", cm.exception.args[2])
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
991
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
992 # 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
993 string_rep = cm.exception.__str__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
994 print(string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
995 self.assertIn("nati", string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
996 self.assertIn("'whoosh'", string_rep)

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