annotate test/test_config.py @ 6296:6cf9f2f49b89

Fix UTC timezone test case if pytz not available; add tests UTC is a special known timezone so it doesn't raise an exception even if pytz is missing. Added test case with bogus timezone that raises exception. Added testcase for EST that is known with and without pytz.
author John Rouillard <rouilj@ieee.org>
date Mon, 14 Dec 2020 21:25:56 -0500
parents 95a366d46065
children c547e05d7a54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
1 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
3 # This module is free software, and you may redistribute it and/or modify
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
4 # under the same terms as Python, so long as this copyright message and
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
5 # disclaimer are retained in their original form.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
6 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
10 # POSSIBILITY OF SUCH DAMAGE.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
11 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
17
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
18 import unittest
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
19 import logging
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
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
44 class ConfigTest(unittest.TestCase):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
45
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
46 def test_badConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
47 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
48 """
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
49 self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName")
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
50
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
51 def test_validConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
52 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
53 """
5794
95a366d46065 Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
54 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
55
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
56 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
57 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
58
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
59 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
60 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
61 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
62 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
63
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
64 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
65 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
66
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
67 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
68 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
69
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
70 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
71 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
72
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
73 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
74 config._get_option('TRACKER_WEB').set, "")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
75
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
76 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
77 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
78
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
79 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
80 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
81 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
82 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
83
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
84 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
85 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
86
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
87 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
88 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
89
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
90 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
91 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
92
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
93 def testTimeZone(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
94 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
95
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
96 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
97 config._get_option('TIMEZONE').set("0"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
98
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
99 # not a valid timezone
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
100 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
101 config._get_option('TIMEZONE').set, "Zot")
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 # 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
104 # 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
105 # constrain to this range.
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
106 #self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
107 # config._get_option('TIMEZONE').set, "25")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
108
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
109 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
110 import pytz
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
111 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
112 config._get_option('TIMEZONE').set("UTC"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
113 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
114 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
115 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
116 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
117 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
118 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
119
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
120 except ImportError:
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
121 # 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
122 # 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
123 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
124 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
125 # 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
126 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
127 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
128 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
129 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
130
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
131
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
132 def testWebSecretKey(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
133 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
134
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
135 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
136 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
137
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
138 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
139 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
140
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 def testStaticFiles(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
143 config = configuration.CoreConfig()
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 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
146 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
147
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
148 self.assertEqual(config.STATIC_FILES,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
149 ["./foo", "/tmp/bar"])
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
150
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
151 self.assertEqual(config['STATIC_FILES'],
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
152 ["./foo", "/tmp/bar"])
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
153
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
154 def testIsolationLevel(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
155 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
156
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
157 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
158 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
159 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
160 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
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("repeatable read"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
163
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.assertRaises(configuration.OptionValueError,
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, "not a level")
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 def testConfigSave(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
169
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
170 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
171 # 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
172
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
173 self.startdir = os.getcwd()
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.dirname = os.getcwd() + '_test_config'
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
176 os.mkdir(self.dirname)
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 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
179 os.chdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
180 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
181 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
182 config.save()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
183 config.save() # creates .bak file
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
184 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
185 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
186
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
187 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
188 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
189 config.save("foo.bar")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
190 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
191 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
192 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
193
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
194 finally:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
195 # cleanup scratch directory and files
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
196 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
197 os.chdir(self.startdir)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
198 shutil.rmtree(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
199 except OSError as error:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
200 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
201
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
202 def testFloatAndInt_with_update_option(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
203
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
204 config = configuration.CoreConfig()
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 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
207 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
208 configuration.IntegerNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
209 "0", description="new desc")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
210
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
211 # -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
212 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
213 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
214
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
215 # but can't float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
216 self.assertRaises(configuration.OptionValueError,
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, "2.4")
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 fred is still an issue
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, "fred")
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 # Update existing IntegerNumberOption to FloatNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
224 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
225 configuration.FloatNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
226 "0.0")
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 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
229
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
230 # can float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
231 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
232 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
233
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
234 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
235 self.assertRaises(configuration.OptionValueError,
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, "fred")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
237
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
238 self.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
239 places=6)

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