Mercurial > p > roundup > code
annotate test/test_config.py @ 6356:c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
Was validated in backends/indexer_xapian.py which would throw
an error on access rather than on start.
Added validator function to CoreConfig class that runs after
config.ini is read. At this time we have access to the indexer setting
so can determine if xapian is actually going to be used.
Moved test into test/test_config.py and pulled validation code from
indexer_xapian.py and test/test_indexer.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 29 Mar 2021 22:47:54 -0400 |
| parents | c547e05d7a54 |
| children | c985ed52ca2d |
| 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 |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
20 |
|
5774
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
21 import os, shutil, errno |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
22 |
|
5126
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
23 import pytest |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
24 from roundup import configuration |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
25 |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
26 config = configuration.CoreConfig() |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
27 config.DATABASE = "db" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
28 config.RDBMS_NAME = "rounduptest" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
29 config.RDBMS_HOST = "localhost" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
30 config.RDBMS_USER = "rounduptest" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
31 config.RDBMS_PASSWORD = "rounduptest" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
32 config.RDBMS_TEMPLATE = "template0" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
33 # 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
|
34 config.MAIL_DOMAIN = "your.tracker.email.domain.example" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
35 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
|
36 # 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
|
37 # 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
|
38 # to 'run_tests.py' script |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
39 #config.LOGGING_FILENAME = "/tmp/logfile" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
40 #config.LOGGING_LEVEL = "DEBUG" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
41 config.init_logging() |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
42 config.options['FOO'] = "value" |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
43 |
|
6331
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
44 # for TrackerConfig test class |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
45 from roundup import instance |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
46 from . import db_test_base |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
47 |
|
5126
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
48 class ConfigTest(unittest.TestCase): |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
49 |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
50 def test_badConfigKeyword(self): |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
51 """Run configure tests looking for invalid option name |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
52 """ |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
53 self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName") |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
54 |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
55 def test_validConfigKeyword(self): |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
56 """Run configure tests looking for invalid option name |
|
dd642afb4440
starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
57 """ |
|
5794
95a366d46065
Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents:
5774
diff
changeset
|
58 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
|
59 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
60 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
|
61 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
|
62 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
68 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
|
69 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
|
70 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
71 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
|
72 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
|
73 |
|
f91da208f26b
Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents:
5126
diff
changeset
|
74 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
|
75 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
|
76 |
|
5774
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
77 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
78 config._get_option('TRACKER_WEB').set, "") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
79 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
80 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
|
81 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
|
82 |
|
8dbe307bdb57
Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents:
5770
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 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
|
87 |
|
8dbe307bdb57
Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents:
5770
diff
changeset
|
88 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
|
89 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
|
90 |
|
8dbe307bdb57
Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents:
5770
diff
changeset
|
91 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
|
92 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
|
93 |
|
5774
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
94 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
95 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
|
96 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
97 def testTimeZone(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
98 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
99 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
100 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
101 config._get_option('TIMEZONE').set("0")) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
102 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
103 # not a valid timezone |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
104 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
105 config._get_option('TIMEZONE').set, "Zot") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
106 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
107 # 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
|
108 # 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
|
109 # constrain to this range. |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
110 #self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
111 # config._get_option('TIMEZONE').set, "25") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
112 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
113 try: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
114 import pytz |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
115 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
116 config._get_option('TIMEZONE').set("UTC")) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
117 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
118 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
|
119 self.assertEqual(None, |
|
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
124 except ImportError: |
|
6296
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
125 # 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
|
126 # 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
|
127 self.assertEqual(None, |
|
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
128 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
|
129 # 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
|
130 self.assertEqual(None, |
|
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
131 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
|
132 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
133 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
|
134 |
|
6296
6cf9f2f49b89
Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents:
5794
diff
changeset
|
135 |
|
5774
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
136 def testWebSecretKey(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
137 config = configuration.CoreConfig() |
|
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 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
140 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
|
141 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
142 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
143 config._get_option('WEB_SECRET_KEY').set, "") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
144 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
145 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
146 def testStaticFiles(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
147 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
148 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
149 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
150 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
|
151 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
152 self.assertEqual(config.STATIC_FILES, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
153 ["./foo", "/tmp/bar"]) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
154 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
155 self.assertEqual(config['STATIC_FILES'], |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
156 ["./foo", "/tmp/bar"]) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
157 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
158 def testIsolationLevel(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
159 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
160 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
161 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
162 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
|
163 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
164 config._get_option('RDBMS_ISOLATION_LEVEL').set("read committed")) |
|
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('RDBMS_ISOLATION_LEVEL').set("repeatable read")) |
|
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 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
169 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
170 config._get_option('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
|
171 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
172 def testConfigSave(self): |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
173 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
174 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
175 # 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
|
176 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
177 self.startdir = os.getcwd() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
178 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
179 self.dirname = os.getcwd() + '_test_config' |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
180 os.mkdir(self.dirname) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
181 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
182 try: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
183 os.chdir(self.dirname) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
184 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
|
185 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
|
186 config.save() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
187 config.save() # creates .bak file |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
188 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
|
189 self.assertTrue(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
|
190 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
191 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
|
192 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
|
193 config.save("foo.bar") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
198 finally: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
199 # cleanup scratch directory and files |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
200 try: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
201 os.chdir(self.startdir) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
202 shutil.rmtree(self.dirname) |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
203 except OSError as error: |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
204 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
|
205 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
206 def testFloatAndInt_with_update_option(self): |
|
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 config = configuration.CoreConfig() |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
209 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
210 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
211 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
|
212 configuration.IntegerNumberOption, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
213 "0", description="new desc") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
214 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
215 # -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
|
216 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
217 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
|
218 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
219 # but can't float this |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
220 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
221 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
|
222 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
223 # but fred is still an issue |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
224 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
225 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
|
226 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
227 # Update existing IntegerNumberOption to FloatNumberOption |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
228 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
|
229 configuration.FloatNumberOption, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
230 "0.0") |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
231 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
232 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
|
233 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
234 # can float this |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
235 self.assertEqual(None, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
236 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
|
237 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
238 # but fred is still an issue |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
239 self.assertRaises(configuration.OptionValueError, |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
240 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
|
241 |
|
765f8c0e99ef
Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents:
5772
diff
changeset
|
242 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
|
243 places=6) |
|
6331
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
244 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
245 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
246 class TrackerConfig(unittest.TestCase): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
247 """ Arguably this should be tested in test_instance since it is triggered |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
248 by instance.open. But it raises an error in the configuration module |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
249 with a missing required param in config.ini.""" |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
250 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
251 backend = 'anydbm' |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
252 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
253 def setUp(self): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
254 self.dirname = '_test_instance' |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
255 # 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
|
256 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
|
257 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
258 # open the database |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
259 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
|
260 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
261 self.db.commit() |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
262 self.db.close() |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
263 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
264 def tearDown(self): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
265 if self.db: |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
266 self.db.close() |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
267 try: |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
268 shutil.rmtree(self.dirname) |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
269 except OSError as error: |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
270 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
|
271 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
272 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
273 def testNoDBInConfig(self): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
274 # comment out the backend key in config.ini |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
275 import fileinput |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
276 for line in fileinput.input(os.path.join(self.dirname, "config.ini"), |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
277 inplace=True): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
278 if line.startswith("backend = "): |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
279 continue |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
280 print(line) |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
281 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
282 # this should fail as backend isn't defined. |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
283 self.assertRaises(configuration.OptionUnsetError, instance.open, |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
284 self.dirname) |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
285 |
|
c547e05d7a54
Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents:
6296
diff
changeset
|
286 |
|
6356
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
287 def testInvalidIndexer_language(self): |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
288 """ make sure we have a reasonable error message if |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
289 invalid language is specified """ |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
290 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
291 # change the indexer_language value to an invalid value. |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
292 import fileinput |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
293 for line in fileinput.input(os.path.join(self.dirname, "config.ini"), |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
294 inplace=True): |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
295 if line.startswith("indexer_language = "): |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
296 print("indexer_language = NO_LANG") |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
297 continue |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
298 print(line[:-1]) # remove trailing \n |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
299 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
300 config = configuration.CoreConfig() |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
301 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
302 # Note this should raise OptionValueError, but |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
303 # the test fot this error occurs too late to have |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
304 # a valid option still available. So raise ValueError. |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
305 with self.assertRaises(ValueError) as cm: |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
306 config.load(self.dirname) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
307 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
308 print(cm.exception) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
309 self.assertIn("ValueError", repr(cm.exception)) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
310 # look for failing language |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
311 self.assertIn("NO_LANG", cm.exception.args[0]) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
312 # look for supported language |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
313 self.assertIn("english", cm.exception.args[0]) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
314 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
315 def testLoadConfig(self): |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
316 """ run load to validate config """ |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
317 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
318 config = configuration.CoreConfig() |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
319 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
320 config.load(self.dirname) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
321 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
322 with self.assertRaises(configuration.InvalidOptionError) as cm: |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
323 c = config['indexer_language'] |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
324 print(cm.exception) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
325 self.assertIn("indexer_language", repr(cm.exception)) |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
326 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
327 self.assertEqual(config['HTML_VERSION'], 'html4') |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
328 self.assertEqual(config[('main', 'html_version')], 'html4') |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
329 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
330 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
|
331 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
|
332 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
333 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
334 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
335 |
|
c26b9ce33ae3
issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents:
6331
diff
changeset
|
336 |
