Mercurial > p > roundup > code
annotate test/test_config.py @ 6604:0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
back_postgreql.py - schema version changes for schema version 7.
configuration.py - added indexer_language checks for postgresql. Hardcoded
list for now.
Docs admin_guide and upgrading
Tests.
This also restructures the version upgrade tests for the rdbms
backends. They can run all of them now as the proper cascade is
developed to roll back changes to version 6.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 27 Jan 2022 19:48:48 -0500 |
| parents | 770503bd211e |
| children | ab2ed11c021e |
| 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 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
41 _py3 = sys.version_info[0] > 2 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
42 if _py3: |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
43 skip_py2 = lambda func, *args, **kwargs: func |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
44 else: |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
45 # FIX: workaround for a bug in pytest.mark.skip(): |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
46 # https://github.com/pytest-dev/pytest/issues/568 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
47 from .pytest_patcher import mark_class |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
48 skip_py2 = mark_class(pytest.mark.skip( |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
49 reason='Skipping test under python2.')) |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
50 |
|
6367
8a7de159d1a6
issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents:
6363
diff
changeset
|
51 |
|
5126
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
52 config = configuration.CoreConfig() |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
53 config.DATABASE = "db" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
54 config.RDBMS_NAME = "rounduptest" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
55 config.RDBMS_HOST = "localhost" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
56 config.RDBMS_USER = "rounduptest" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
57 config.RDBMS_PASSWORD = "rounduptest" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
58 config.RDBMS_TEMPLATE = "template0" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
59 # 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
|
60 config.MAIL_DOMAIN = "your.tracker.email.domain.example" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
61 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
|
62 # 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
|
63 # 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
|
64 # to 'run_tests.py' script |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
65 #config.LOGGING_FILENAME = "/tmp/logfile" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
66 #config.LOGGING_LEVEL = "DEBUG" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
67 config.init_logging() |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
68 config.options['FOO'] = "value" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
69 |
|
6331
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
70 # for TrackerConfig test class |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
71 from roundup import instance |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
72 from . import db_test_base |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
73 |
|
5126
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
74 class ConfigTest(unittest.TestCase): |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
75 |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
76 def test_badConfigKeyword(self): |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
77 """Run configure tests looking for invalid option name |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
78 """ |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
79 self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName") |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
80 |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
81 def test_validConfigKeyword(self): |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
82 """Run configure tests looking for invalid option name |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
83 """ |
|
5794
95a366d46065
Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents:
5774
diff
changeset
|
84 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
|
85 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
86 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
|
87 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
|
88 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 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
|
93 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
94 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
|
95 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
|
96 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
97 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
|
98 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
|
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.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
|
101 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
|
102 |
|
5774
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
103 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
104 config._get_option('TRACKER_WEB').set, "") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
105 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
106 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
|
107 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
|
108 |
|
8dbe307bdb57
Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents:
5770
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 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
|
113 |
|
8dbe307bdb57
Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents:
5770
diff
changeset
|
114 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
|
115 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
|
116 |
|
8dbe307bdb57
Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents:
5770
diff
changeset
|
117 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
|
118 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
|
119 |
|
5774
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
120 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
121 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
|
122 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
123 def testTimeZone(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
124 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
125 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
126 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
127 config._get_option('TIMEZONE').set("0")) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
128 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
129 # not a valid timezone |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
130 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
131 config._get_option('TIMEZONE').set, "Zot") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
132 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
133 # 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
|
134 # 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
|
135 # constrain to this range. |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
136 #self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
137 # config._get_option('TIMEZONE').set, "25") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
138 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
139 try: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
140 import pytz |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
141 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
142 config._get_option('TIMEZONE').set("UTC")) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
143 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
144 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
|
145 self.assertEqual(None, |
|
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
150 except ImportError: |
|
6296
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
151 # 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
|
152 # 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
|
153 self.assertEqual(None, |
|
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
154 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
|
155 # 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
|
156 self.assertEqual(None, |
|
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
157 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
|
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, "America/New_York") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
160 |
|
6296
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
161 |
|
5774
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
162 def testWebSecretKey(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
163 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
164 |
|
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('WEB_SECRET_KEY').set("skskskd")) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
167 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
168 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
169 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
|
170 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
171 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
172 def testStaticFiles(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
173 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
174 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
175 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
176 config._get_option('STATIC_FILES').set("foo /tmp/bar")) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
177 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
178 self.assertEqual(config.STATIC_FILES, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
179 ["./foo", "/tmp/bar"]) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
180 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
181 self.assertEqual(config['STATIC_FILES'], |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
182 ["./foo", "/tmp/bar"]) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
183 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
184 def testIsolationLevel(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('RDBMS_ISOLATION_LEVEL').set("read uncommitted")) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
189 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
190 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
|
191 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
192 config._get_option('RDBMS_ISOLATION_LEVEL').set("repeatable read")) |
|
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 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
195 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
196 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
|
197 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
198 def testConfigSave(self): |
|
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 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
201 # 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
|
202 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
203 self.startdir = os.getcwd() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
204 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
205 self.dirname = os.getcwd() + '_test_config' |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
206 os.mkdir(self.dirname) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
207 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
208 try: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
209 os.chdir(self.dirname) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
210 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
|
211 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
|
212 config.save() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
213 config.save() # creates .bak file |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 # 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
|
218 # 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
|
219 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
|
220 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
221 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
|
222 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
|
223 config.save("foo.bar") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
228 finally: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
229 # cleanup scratch directory and files |
|
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.startdir) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
232 shutil.rmtree(self.dirname) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
233 except OSError as error: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
234 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
|
235 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
236 def testFloatAndInt_with_update_option(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
237 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
238 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
239 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
240 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
241 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
|
242 configuration.IntegerNumberOption, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
243 "0", description="new desc") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
244 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
245 # -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
|
246 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
247 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
|
248 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
249 # but can't float this |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
250 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
251 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
|
252 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
253 # but fred is still an issue |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
254 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
255 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
|
256 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
257 # Update existing IntegerNumberOption to FloatNumberOption |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
258 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
|
259 configuration.FloatNumberOption, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
260 "0.0") |
|
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 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
|
263 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
264 # can float this |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
265 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
266 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
|
267 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
268 # but fred is still an issue |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
269 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
270 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
|
271 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
272 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
|
273 places=6) |
|
6331
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
274 |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
275 # 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
|
276 self.assertEqual(None, |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
277 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
|
278 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
279 self.assertEqual("3", |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
280 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
|
281 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
282 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
283 def testOptionAsString(self): |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
284 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
285 config = configuration.CoreConfig() |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
286 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
287 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
|
288 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
289 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
|
290 print(v) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
291 self.assertIn("55", v) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
292 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
293 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
|
294 print(v) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
295 self.assertIn("55", v) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
296 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
297 def testBooleanOption(self): |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
298 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
299 config = configuration.CoreConfig() |
|
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 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
|
302 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
|
303 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
304 # test multiple boolean representations |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
305 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
|
306 "oN", 1, True ]: |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
307 self.assertEqual(None, |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
308 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
|
309 self.assertEqual(1, |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
310 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
|
311 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
312 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
|
313 "oFf", 0, False]: |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
314 self.assertEqual(None, |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
315 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
|
316 self.assertEqual(0, |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
317 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
|
318 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
319 def testOctalNumberOption(self): |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
320 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
321 config = configuration.CoreConfig() |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
322 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
323 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
|
324 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
|
325 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
326 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
|
327 |
|
6331
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
328 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
329 class TrackerConfig(unittest.TestCase): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
330 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
331 backend = 'anydbm' |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
332 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
333 def setUp(self): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
334 self.dirname = '_test_instance' |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
335 # 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
|
336 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
|
337 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
338 # open the database |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
339 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
|
340 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
341 self.db.commit() |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
342 self.db.close() |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
343 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
344 def tearDown(self): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
345 if self.db: |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
346 self.db.close() |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
347 try: |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
348 shutil.rmtree(self.dirname) |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
349 except OSError as error: |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
350 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
|
351 |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
352 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
|
353 """ modify config.ini to meet testing requirements |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
354 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
355 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
|
356 [ ( "a = ", "b" ), ("c = ", None), ("d = ", "b", "z = ") ] |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 elements (used to replace commented out parameters). |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
366 |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
367 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
|
368 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
|
369 section name. |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
370 """ |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
371 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
372 if mods is None: |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
373 return |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
374 |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
375 # 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
|
376 # 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
|
377 in_section = True |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
378 |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
379 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
|
380 inplace=True): |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
381 if section: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
382 if line.startswith('['): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
383 in_section = False |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
384 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
385 if line.startswith(section): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
386 in_section = True |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
387 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
388 if in_section: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
389 for rule in mods: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
390 if len(rule) == 3: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
391 match, value, repl = rule |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
392 else: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
393 match, value = rule |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
394 repl = None |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
395 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
396 if line.startswith(match): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
397 if value is not None: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
398 if repl: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
399 print(repl + value) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
400 else: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
401 print(match + value) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
402 break |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
403 else: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
404 print(line[:-1]) # remove trailing \n |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
405 else: |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
406 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
|
407 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
408 def testNoDBInConfig(self): |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
409 """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
|
410 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
|
411 configuration module with a missing required param in |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
412 config.ini. |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
413 """ |
|
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 # remove the backend key in config.ini |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
416 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
|
417 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
418 # 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
|
419 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
|
420 instance.open(self.dirname) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
421 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
422 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
|
423 " 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
|
424 |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
425 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
|
426 """ 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
|
427 [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
|
428 """ |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
429 # SETUP: set mail username |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
430 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
|
431 section="[mail]") |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
432 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
433 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
434 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
435 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
|
436 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
437 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
438 print(cm.exception) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
439 # 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
|
440 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
|
441 # look for 'not defined' |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
442 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
|
443 |
|
6584
770503bd211e
Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents:
6578
diff
changeset
|
444 |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
445 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
|
446 """ 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
|
447 [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
|
448 """ |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
449 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
450 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
451 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
452 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
453 self.assertEqual(config['MAIL_USERNAME'], '') |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
454 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
455 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
|
456 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
|
457 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
458 def testSecretMandatory_missing_file(self): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
459 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
460 # SETUP: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
461 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
|
462 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
463 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
464 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
465 with self.assertRaises(configuration.OptionValueError) as cm: |
|
6584
770503bd211e
Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents:
6578
diff
changeset
|
466 config.load(self.dirname) |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
467 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
468 print(cm.exception) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
469 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
|
470 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
471 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
|
472 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
473 # SETUP: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
474 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
|
475 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
476 secret = "ASDQWEZXCRFVBGTYHNMJU" |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
477 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
|
478 f.write(secret + "\n") |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
479 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
480 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
481 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
482 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
483 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
484 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
|
485 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
486 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
487 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
|
488 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
489 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
|
490 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
491 # SETUP: |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
492 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
|
493 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
494 secret = "ASDQWEZXCRFVBGTYHNMJU" |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
495 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
|
496 f.write(secret + "\n") |
|
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 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
499 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
500 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
501 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
502 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
|
503 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
504 os.remove(abs_file) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
505 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
506 def testSecretMandatory_empty_file(self): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
507 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
508 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
|
509 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
510 # 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
|
511 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
|
512 f.write("\n") |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
513 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
514 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
515 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
516 with self.assertRaises(configuration.OptionValueError) as cm: |
|
6584
770503bd211e
Validate SecretOption and support validate method
John Rouillard <rouilj@ieee.org>
parents:
6578
diff
changeset
|
517 config.load(self.dirname) |
|
6578
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
518 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
519 print(cm.exception.args) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
520 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
|
521 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
522 def testNullableSecret_empty_file(self): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
523 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
524 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
|
525 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
526 # 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
|
527 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
|
528 f.write("\n") |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
529 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
530 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
531 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
532 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
533 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
534 v = config['RDBMS_PASSWORD'] |
|
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 self.assertEqual(v, None) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
537 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
538 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
|
539 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
540 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
|
541 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
542 # 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
|
543 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
|
544 f.write("test\n") |
|
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 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
547 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
548 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
549 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
550 v = config['RDBMS_PASSWORD'] |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
551 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
552 self.assertEqual(v, "test") |
|
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 def testNullableSecret_with_value(self): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
555 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
556 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
|
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 v = config['RDBMS_PASSWORD'] |
|
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 self.assertEqual(v, "test") |
|
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 testSetMailPassword_with_set_username(self): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
567 """ 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
|
568 Should have both values set. |
|
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 # SETUP: set mail username |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
571 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
|
572 ("#password = ", "passwordfoo", |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
573 "password = ") ], |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
574 section="[mail]") |
|
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 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
577 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
578 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
579 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
580 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
|
581 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
|
582 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
583 def testSetMailPassword_from_file(self): |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
584 """ 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
|
585 Should have both values set. |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
586 """ |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
587 # SETUP: set mail username |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
588 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
|
589 ("#password = ", "file://password", |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
590 "password = ") ], |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
591 section="[mail]") |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
592 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
|
593 f.write("passwordfoo\n") |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
594 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
595 config = configuration.CoreConfig() |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
596 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
597 config.load(self.dirname) |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
598 |
|
b1f1539c6a31
issue2551182 - ... allow loading values from external file. flake8 cleanups
John Rouillard <rouilj@ieee.org>
parents:
6560
diff
changeset
|
599 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
|
600 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
|
601 |
|
6367
8a7de159d1a6
issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents:
6363
diff
changeset
|
602 @skip_xapian |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
603 def testInvalidIndexerLanguage_w_empty(self): |
|
6356
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
604 """ 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
|
605 invalid indexer language is specified. This uses |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
606 default search path for indexers. |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
607 """ |
|
6356
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
608 |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
609 # 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
|
610 self.munge_configini(mods=[ ("indexer = ", ""), |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
611 ("indexer_language = ", "NO_LANG") ]) |
|
6356
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
612 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
613 config = configuration.CoreConfig() |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
614 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
615 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
|
616 config.load(self.dirname) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
617 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
618 print(cm.exception) |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
619 # 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
|
620 self.assertIn("OptionValueError", repr(cm.exception)) |
|
6356
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
621 # look for failing language |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
622 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
|
623 # look for supported language |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
624 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
|
625 |
|
6368
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
626 @include_no_xapian |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
627 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
|
628 """ 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
|
629 |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
630 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
|
631 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
|
632 """ |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
633 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
|
634 |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
635 # 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
|
636 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
|
637 ("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
|
638 |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
639 config = configuration.CoreConfig() |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
640 |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
641 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
|
642 |
|
e3ed3ad9e795
issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents:
6367
diff
changeset
|
643 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
|
644 |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
645 def testInvalidIndexerLanguage_xapian_missing(self): |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
646 """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
|
647 fail and prevent exception from happening even though |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
648 the indexer_language would be invalid for xapian. |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
649 """ |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
650 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
651 print("Testing xapian not loadable") |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
652 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
653 # SETUP: same as testInvalidIndexerLanguage_w_empty |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
654 self.munge_configini(mods=[ ("indexer = ", ""), |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
655 ("indexer_language = ", "NO_LANG") ]) |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
656 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
657 import sys |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
658 # 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
|
659 sys.modules['xapian'] = None |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
660 config.load(self.dirname) |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
661 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
662 # 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
|
663 del(sys.modules['xapian']) |
|
6371
5c1db5d4baed
Fix failing xapian test
Ralf Schlatterbeck <rsc@runtux.com>
parents:
6368
diff
changeset
|
664 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
|
665 del(sys.modules['xapian._xapian']) |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
666 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
667 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG') |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
668 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
669 # 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
|
670 # to do setup in a different test |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
671 config.reset() |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
672 self.assertEqual(config['INDEXER_LANGUAGE'], 'english') |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
673 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
674 def testInvalidIndexerLanguage_w_native(self): |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
675 """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
|
676 Config load should succeed without exception. |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
677 """ |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
678 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
679 print("Testing indexer = native") |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
680 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
681 self.munge_configini(mods = [ ("indexer = ", "native"), |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
682 ("indexer_language = ", "NO_LANG") ]) |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
683 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
684 config.load(self.dirname) |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
685 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
686 self.assertEqual(config['HTML_VERSION'], 'html4') |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
687 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG') |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
688 |
|
6367
8a7de159d1a6
issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents:
6363
diff
changeset
|
689 @skip_xapian |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
690 def testInvalidIndexerLanguage_w_xapian(self): |
| 6358 | 691 """ Use explicit xapian indexer. Verify exception is |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
692 generated. |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
693 """ |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
694 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
695 print("Testing explicit xapian") |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
696 |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
697 self.munge_configini(mods=[ ("indexer = ", "xapian"), |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
698 ("indexer_language = ", "NO_LANG") ]) |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
699 |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
700 with self.assertRaises(configuration.OptionValueError) as cm: |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
701 config.load(self.dirname) |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
702 # don't test exception content. Done in |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
703 # testInvalidIndexerLanguage_w_empty |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
704 # if exception not generated assertRaises |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
705 # will generate failure. |
|
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
706 |
|
6604
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
707 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
|
708 """ 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
|
709 generated. |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
710 """ |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
711 |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
712 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
|
713 ("indexer_language = ", "NO_LANG") ]) |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
714 |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
715 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
|
716 config.load(self.dirname) |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
717 |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
718 # 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
|
719 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
|
720 # look for failing language |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
721 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
|
722 # look for supported language |
|
0d99ae7c8de6
Allow Roundup to use PostgreSQL database native full text search
John Rouillard <rouilj@ieee.org>
parents:
6584
diff
changeset
|
723 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
|
724 |
|
6356
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
725 def testLoadConfig(self): |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
726 """ run load to validate config """ |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
727 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
728 config = configuration.CoreConfig() |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
729 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
730 config.load(self.dirname) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
731 |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
732 # 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
|
733 with self.assertRaises(configuration.InvalidOptionError) as cm: |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
734 # using lower case name fails |
|
6356
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
735 c = config['indexer_language'] |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
736 print(cm.exception) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
737 self.assertIn("indexer_language", repr(cm.exception)) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
738 |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
739 # 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
|
740 self.assertEqual(config['HTML_VERSION'], 'html4') |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
741 self.assertEqual(config[('main', 'html_version')], 'html4') |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
742 |
|
6357
c985ed52ca2d
Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents:
6356
diff
changeset
|
743 # 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
|
744 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
|
745 self.assertEqual(config[('web','cookie_takes_precedence')], 0) |
| 6358 | 746 |
| 747 | |
|
6359
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
748 def testLoadConfigNoConfig(self): |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
749 """ 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
|
750 |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
751 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
|
752 if os.path.exists(c): |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
753 os.remove(c) |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
754 else: |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
755 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
|
756 |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
757 config = configuration.CoreConfig() |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
758 |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
759 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
|
760 config.load(self.dirname) |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
761 |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
762 print(cm.exception) |
|
2d42a308927b
Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents:
6358
diff
changeset
|
763 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
|
764 |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
765 def testCopyConfig(self): |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
766 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
767 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
|
768 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
769 config = configuration.CoreConfig() |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
770 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
771 # 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
|
772 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
|
773 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
774 # load config |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
775 config.load(self.dirname) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
776 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
777 # loaded new option |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
778 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
|
779 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
780 # copy config |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
781 config_copy = config.copy() |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
782 |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
783 # this should work |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
784 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
|
785 |
|
6557
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
786 @skip_py2 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
787 def testConfigValueInterpolateError(self): |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
788 ''' error is not raised using ConfigParser under Python 2. |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
789 Unknown cause, so skip it if running python 2. |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
790 ''' |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
791 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
792 self.munge_configini(mods=[ ("admin_email = ", "a bare % is invalid") ]) |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
793 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
794 config = configuration.CoreConfig() |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
795 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
796 # load config generates: |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
797 ''' |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
798 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
|
799 ''' |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
800 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
801 with self.assertRaises(configuration.ParsingOptionError) as cm: |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
802 config.load(self.dirname) |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
803 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
804 print(cm.exception) |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
805 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
|
806 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
|
807 |
|
8687c096a945
Handle configparser.InterpolationSyntaxError
John Rouillard <rouilj@ieee.org>
parents:
6371
diff
changeset
|
808 |
|
6560
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
809 from roundup.admin import AdminTool |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
810 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
|
811 |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
812 admin=AdminTool() |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
813 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
|
814 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
|
815 ret = admin.main() |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
816 |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
817 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
|
818 |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
819 self.assertEqual(ret, 1) |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
820 out = out.getvalue().strip() |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
821 self.assertEqual(out, expected_err) |
|
fdfe3b7387ea
Add test for config parse error by running AdminTool.
John Rouillard <rouilj@ieee.org>
parents:
6557
diff
changeset
|
822 |
| 6358 | 823 def testInvalidIndexerValue(self): |
| 824 """ Mistype native indexer. Verify exception is | |
| 825 generated. | |
| 826 """ | |
| 827 | |
| 828 print("Testing indexer nati") | |
| 829 | |
| 830 self.munge_configini(mods=[ ("indexer = ", "nati") ]) | |
| 831 | |
| 832 with self.assertRaises(configuration.OptionValueError) as cm: | |
| 833 config.load(self.dirname) | |
| 834 | |
| 835 self.assertIn("OptionValueError", repr(cm.exception)) | |
| 836 # look for failing value | |
| 837 self.assertEqual("nati", cm.exception.args[1]) | |
| 838 # look for supported values | |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
839 self.assertIn("'whoosh'", cm.exception.args[2]) |
| 6358 | 840 |
|
6363
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
841 # 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
|
842 string_rep = cm.exception.__str__() |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
843 print(string_rep) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
844 self.assertIn("nati", string_rep) |
|
08e209a7f22b
Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents:
6359
diff
changeset
|
845 self.assertIn("'whoosh'", string_rep) |
