annotate test/test_config.py @ 6371:5c1db5d4baed

Fix failing xapian test
author Ralf Schlatterbeck <rsc@runtux.com>
date Thu, 01 Apr 2021 08:58:51 +0200
parents e3ed3ad9e795
children 8687c096a945
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
1 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
3 # This module is free software, and you may redistribute it and/or modify
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
4 # under the same terms as Python, so long as this copyright message and
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
5 # disclaimer are retained in their original form.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
6 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
10 # POSSIBILITY OF SUCH DAMAGE.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
11 #
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
17
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
18 import unittest
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
19 import logging
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
20 import fileinput
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
21
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
22 import os, shutil, errno
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
23
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
24 import pytest
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
25 from roundup import configuration
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
26
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
27 try:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
28 import xapian
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
29 skip_xapian = lambda func, *args, **kwargs: func
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
30 from .pytest_patcher import mark_class
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
31 include_no_xapian = mark_class(pytest.mark.skip(
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
32 "Skipping missing Xapian indexer tests: 'xapian' is installed"))
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
33 except ImportError:
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
34 # FIX: workaround for a bug in pytest.mark.skip():
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
35 # https://github.com/pytest-dev/pytest/issues/568
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
36 from .pytest_patcher import mark_class
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
37 skip_xapian = mark_class(pytest.mark.skip(
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
38 "Skipping Xapian indexer tests: 'xapian' not installed"))
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
39 include_no_xapian = lambda func, *args, **kwargs: func
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
40
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
41
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
42 config = configuration.CoreConfig()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
43 config.DATABASE = "db"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
44 config.RDBMS_NAME = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
45 config.RDBMS_HOST = "localhost"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
46 config.RDBMS_USER = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
47 config.RDBMS_PASSWORD = "rounduptest"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
48 config.RDBMS_TEMPLATE = "template0"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
49 # 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
50 config.MAIL_DOMAIN = "your.tracker.email.domain.example"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
51 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
52 # 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
53 # 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
54 # to 'run_tests.py' script
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
55 #config.LOGGING_FILENAME = "/tmp/logfile"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
56 #config.LOGGING_LEVEL = "DEBUG"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
57 config.init_logging()
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
58 config.options['FOO'] = "value"
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
59
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
60 # for TrackerConfig test class
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
61 from roundup import instance
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
62 from . import db_test_base
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
63
5126
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
64 class ConfigTest(unittest.TestCase):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
65
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
66 def test_badConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
67 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
68 """
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
69 self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName")
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
70
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
71 def test_validConfigKeyword(self):
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
72 """Run configure tests looking for invalid option name
dd642afb4440 starter tests for roundup/configuration.py
John Rouillard <rouilj@ieee.org>
parents:
diff changeset
73 """
5794
95a366d46065 Replace deprecated assertEquals with assertEqual and failUnlessRaises
John Rouillard <rouilj@ieee.org>
parents: 5774
diff changeset
74 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
75
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
76 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
77 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
78
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
79 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
80 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
81 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
82 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
83
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
84 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
85 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
86
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
87 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
88 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
89
f91da208f26b Validate that TRACKER_WEB url starts with https:// or http:// and ends
John Rouillard <rouilj@ieee.org>
parents: 5126
diff changeset
90 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
91 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
92
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
93 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
94 config._get_option('TRACKER_WEB').set, "")
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 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
97 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
98
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
99 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
100 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
101 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
102 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
103
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
104 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
105 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
106
8dbe307bdb57 Finish up login rate limit code. Set config item to 0 disables, make
John Rouillard <rouilj@ieee.org>
parents: 5770
diff changeset
107 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
108 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
109
5774
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('WEB_LOGIN_ATTEMPTS_MIN').set, "")
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 def testTimeZone(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
114 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
115
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
116 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
117 config._get_option('TIMEZONE').set("0"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
118
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
119 # not a valid timezone
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
120 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
121 config._get_option('TIMEZONE').set, "Zot")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
122
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
123 # 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
124 # 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
125 # constrain to this range.
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
126 #self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
127 # config._get_option('TIMEZONE').set, "25")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
128
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
129 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
130 import pytz
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
131 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
132 config._get_option('TIMEZONE').set("UTC"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
133 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
134 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
135 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
136 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
137 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
138 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
139
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
140 except ImportError:
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
141 # 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
142 # 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
143 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
144 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
145 # 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
146 self.assertEqual(None,
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
147 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
148 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
149 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
150
6296
6cf9f2f49b89 Fix UTC timezone test case if pytz not available; add tests
John Rouillard <rouilj@ieee.org>
parents: 5794
diff changeset
151
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
152 def testWebSecretKey(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
153 config = configuration.CoreConfig()
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(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
156 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
157
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
158 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
159 config._get_option('WEB_SECRET_KEY').set, "")
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
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
162 def testStaticFiles(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
163 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
164
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
165 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
166 config._get_option('STATIC_FILES').set("foo /tmp/bar"))
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
167
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
168 self.assertEqual(config.STATIC_FILES,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
169 ["./foo", "/tmp/bar"])
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
170
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
171 self.assertEqual(config['STATIC_FILES'],
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
172 ["./foo", "/tmp/bar"])
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 def testIsolationLevel(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
175 config = configuration.CoreConfig()
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.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
178 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
179 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
180 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
181 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
182 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
183
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
184
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
185 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
186 config._get_option('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
187
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
188 def testConfigSave(self):
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
189
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
190 config = configuration.CoreConfig()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
191 # 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
192
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
193 self.startdir = os.getcwd()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
194
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
195 self.dirname = os.getcwd() + '_test_config'
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
196 os.mkdir(self.dirname)
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 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
199 os.chdir(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
200 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
201 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
202 config.save()
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
203 config.save() # creates .bak file
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
204 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
205 self.assertTrue(os.access("config.bak", os.F_OK))
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
206 config.save() # trigger delete of old .bak file
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
207 # FIXME: this should test to see if a new .bak
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
208 # was created. For now verify .bak still exists
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
209 self.assertTrue(os.access("config.bak", os.F_OK))
5774
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
210
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
211 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
212 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
213 config.save("foo.bar")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
214 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
215 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
216 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
217
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
218 finally:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
219 # cleanup scratch directory and files
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
220 try:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
221 os.chdir(self.startdir)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
222 shutil.rmtree(self.dirname)
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
223 except OSError as error:
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
224 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
225
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
226 def testFloatAndInt_with_update_option(self):
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 config = configuration.CoreConfig()
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 # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
231 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
232 configuration.IntegerNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
233 "0", description="new desc")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
234
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
235 # -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
236 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
237 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
238
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
239 # but can't float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
240 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
241 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
242
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
243 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
244 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
245 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
246
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
247 # Update existing IntegerNumberOption to FloatNumberOption
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
248 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
249 configuration.FloatNumberOption,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
250 "0.0")
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
251
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
252 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
253
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
254 # can float this
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
255 self.assertEqual(None,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
256 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
257
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
258 # but fred is still an issue
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
259 self.assertRaises(configuration.OptionValueError,
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
260 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
261
765f8c0e99ef Sanity checking improvements. All IntegerNumberOption really have to
John Rouillard <rouilj@ieee.org>
parents: 5772
diff changeset
262 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
263 places=6)
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
264
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
265 # test removal of .0 on floats that are integers
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
266 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
267 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("3.0"))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
268
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
269 self.assertEqual("3",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
270 config._get_option('WEB_LOGIN_ATTEMPTS_MIN')._value2str(3.00))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
271
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
272
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
273 def testOptionAsString(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
274
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
275 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
276
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
277 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("2552")
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
278
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
279 v = config._get_option('WEB_LOGIN_ATTEMPTS_MIN').__str__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
280 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
281 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
282
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
283 v = config._get_option('WEB_LOGIN_ATTEMPTS_MIN').__repr__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
284 print(v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
285 self.assertIn("55", v)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
286
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
287 def testBooleanOption(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
288
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
289 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
290
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
291 with self.assertRaises(configuration.OptionValueError) as cm:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
292 config._get_option('INSTANT_REGISTRATION').set("3")
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
293
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
294 # test multiple boolean representations
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
295 for b in [ "yes", "1", "true", "TRUE", "tRue", "on",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
296 "oN", 1, True ]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
297 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
298 config._get_option('INSTANT_REGISTRATION').set(b))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
299 self.assertEqual(1,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
300 config._get_option('INSTANT_REGISTRATION').get())
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
301
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
302 for b in ["no", "0", "false", "FALSE", "fAlse", "off",
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
303 "oFf", 0, False]:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
304 self.assertEqual(None,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
305 config._get_option('INSTANT_REGISTRATION').set(b))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
306 self.assertEqual(0,
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
307 config._get_option('INSTANT_REGISTRATION').get())
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
308
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
309 def testOctalNumberOption(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
310
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
311 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
312
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
313 with self.assertRaises(configuration.OptionValueError) as cm:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
314 config._get_option('UMASK').set("xyzzy")
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
315
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
316 print(type(config._get_option('UMASK')))
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
317
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
318
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
319 class TrackerConfig(unittest.TestCase):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
320
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
321 backend = 'anydbm'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
322
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
323 def setUp(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
324 self.dirname = '_test_instance'
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
325 # 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
326 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
327
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
328 # open the database
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
329 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
330
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
331 self.db.commit()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
332 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
333
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
334 def tearDown(self):
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
335 if self.db:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
336 self.db.close()
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
337 try:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
338 shutil.rmtree(self.dirname)
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
339 except OSError as error:
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
340 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
341
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
342 def munge_configini(self, mods = None):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
343 """ modify config.ini to meet testing requirements
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
344
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
345 mods is a list of tuples:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
346 [ ( "a = ", "b" ), ("c = ", None) ]
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
347 Match line with first tuple element e.g. "a = ". Note specify
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
348 trailing "=" and space to delimit keyword and properly format
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
349 replacement line. If first tuple element matches, the line is
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
350 replaced with the concatenation of the first and second elements.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
351 If second element is None ("" doesn't work), the line will be
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
352 deleted.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
353
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
354 Note the key/first element of tuple must be unique in config.ini.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
355 It is possible to have duplicates in different sections. This
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
356 method doesn't handle that. TBD option third element of tuple
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
357 defining section if needed.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
358 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
359
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
360 if mods is None:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
361 return
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
362
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
363 for line in fileinput.input(os.path.join(self.dirname, "config.ini"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
364 inplace=True):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
365 for match, value in mods:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
366 if line.startswith(match):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
367 if value is not None:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
368 print(match + value)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
369 break
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
370 else:
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
371 print(line[:-1]) # remove trailing \n
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
372
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
373 def testNoDBInConfig(self):
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
374 """Arguably this should be tested in test_instance since it is
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
375 triggered by instance.open. But it raises an error in the
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
376 configuration module with a missing required param in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
377 config.ini.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
378 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
379
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
380 # remove the backend key in config.ini
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
381 self.munge_configini(mods=[ ("backend = ", None) ])
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
382
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
383 # this should fail as backend isn't defined.
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
384 with self.assertRaises(configuration.OptionUnsetError) as cm:
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
385 instance.open(self.dirname)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
386
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
387 self.assertEqual("RDBMS_BACKEND is not set"
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
388 " and has no default", cm.exception.__str__())
6331
c547e05d7a54 Test case where backend is missing from config.ini.
John Rouillard <rouilj@ieee.org>
parents: 6296
diff changeset
389
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
390 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
391 def testInvalidIndexerLanguage_w_empty(self):
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
392 """ make sure we have a reasonable error message if
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
393 invalid indexer language is specified. This uses
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
394 default search path for indexers.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
395 """
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
396
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
397 # SETUP: set indexer_language value to an invalid value.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
398 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
399 ("indexer_language = ", "NO_LANG") ])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
400
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
401 config = configuration.CoreConfig()
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
402
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
403 with self.assertRaises(configuration.OptionValueError) as cm:
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
404 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
405
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
406 print(cm.exception)
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
407 # test repr. The type is right since it passed assertRaises.
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
408 self.assertIn("OptionValueError", repr(cm.exception))
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
409 # look for failing language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
410 self.assertIn("NO_LANG", cm.exception.args[1])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
411 # look for supported language
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
412 self.assertIn("english", cm.exception.args[2])
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
413
6368
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
414 @include_no_xapian
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
415 def testInvalidIndexerLanguage_w_empty_no_xapian(self):
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
416 """ Test case for empty indexer if xapian really isn't installed
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
417
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
418 This should behave like testInvalidIndexerLanguage_xapian_missing
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
419 but without all the sys.modules mangling.
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
420 """
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
421 print("Testing when xapian is not installed")
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
422
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
423 # SETUP: set indexer_language value to an invalid value.
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
424 self.munge_configini(mods=[ ("indexer = ", ""),
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
425 ("indexer_language = ", "NO_LANG") ])
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
426
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
427 config = configuration.CoreConfig()
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
428
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
429 config.load(self.dirname)
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
430
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
431 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
e3ed3ad9e795 issue2551125 Add indexer_lang test that runs if xapian not installed
John Rouillard <rouilj@ieee.org>
parents: 6367
diff changeset
432
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
433 def testInvalidIndexerLanguage_xapian_missing(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
434 """Using default path for indexers, make import of xapian
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
435 fail and prevent exception from happening even though
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
436 the indexer_language would be invalid for xapian.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
437 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
438
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
439 print("Testing xapian not loadable")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
440
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
441 # SETUP: same as testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
442 self.munge_configini(mods=[ ("indexer = ", ""),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
443 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
444
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
445 import sys
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
446 # Set module to Non to prevent xapian from loading
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
447 sys.modules['xapian'] = None
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
448 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
449
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
450 # need to delete both to make python2 not error finding _xapian
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
451 del(sys.modules['xapian'])
6371
5c1db5d4baed Fix failing xapian test
Ralf Schlatterbeck <rsc@runtux.com>
parents: 6368
diff changeset
452 if 'xapian._xapian' in sys.modules:
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
453 del(sys.modules['xapian._xapian'])
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
454
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
455 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
456
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
457 # do a reset here to test reset rather than wasting cycles
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
458 # to do setup in a different test
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
459 config.reset()
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
460 self.assertEqual(config['INDEXER_LANGUAGE'], 'english')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
461
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
462 def testInvalidIndexerLanguage_w_native(self):
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
463 """indexer_language is invalid but indexer is not "" or xapian
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
464 Config load should succeed without exception.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
465 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
466
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
467 print("Testing indexer = native")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
468
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
469 self.munge_configini(mods = [ ("indexer = ", "native"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
470 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
471
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
472 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
473
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
474 self.assertEqual(config['HTML_VERSION'], 'html4')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
475 self.assertEqual(config['INDEXER_LANGUAGE'], 'NO_LANG')
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
476
6367
8a7de159d1a6 issue2551125 Make indexer_lang test work if xapian not installed.
John Rouillard <rouilj@ieee.org>
parents: 6363
diff changeset
477 @skip_xapian
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
478 def testInvalidIndexerLanguage_w_xapian(self):
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
479 """ Use explicit xapian indexer. Verify exception is
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
480 generated.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
481 """
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
482
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
483 print("Testing explicit xapian")
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
484
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
485 self.munge_configini(mods=[ ("indexer = ", "xapian"),
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
486 ("indexer_language = ", "NO_LANG") ])
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
487
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
488 with self.assertRaises(configuration.OptionValueError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
489 config.load(self.dirname)
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
490 # don't test exception content. Done in
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
491 # testInvalidIndexerLanguage_w_empty
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
492 # if exception not generated assertRaises
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
493 # will generate failure.
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
494
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
495 def testLoadConfig(self):
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
496 """ run load to validate config """
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
497
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
498 config = configuration.CoreConfig()
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
499
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
500 config.load(self.dirname)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
501
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
502 # test various ways of accessing config data
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
503 with self.assertRaises(configuration.InvalidOptionError) as cm:
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
504 # using lower case name fails
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
505 c = config['indexer_language']
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
506 print(cm.exception)
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
507 self.assertIn("indexer_language", repr(cm.exception))
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
508
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
509 # uppercase name passes as does tuple index for setting in main
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
510 self.assertEqual(config['HTML_VERSION'], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
511 self.assertEqual(config[('main', 'html_version')], 'html4')
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
512
6357
c985ed52ca2d Add testcases for invalid indexer_language
John Rouillard <rouilj@ieee.org>
parents: 6356
diff changeset
513 # uppercase name passes as does tuple index for setting in web
6356
c26b9ce33ae3 issue2551123 - validate indexer_language in configuration.py
John Rouillard <rouilj@ieee.org>
parents: 6331
diff changeset
514 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
515 self.assertEqual(config[('web','cookie_takes_precedence')], 0)
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
516
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
517
6359
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
518 def testLoadConfigNoConfig(self):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
519 """ run load on a directory missing config.ini """
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
520
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
521 c = os.path.join(self.dirname, configuration.Config.INI_FILE)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
522 if os.path.exists(c):
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
523 os.remove(c)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
524 else:
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
525 self.assertFalse("setup failed missing config.ini")
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
526
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
527 config = configuration.CoreConfig()
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
528
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
529 with self.assertRaises(configuration.NoConfigError) as cm:
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
530 config.load(self.dirname)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
531
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
532 print(cm.exception)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
533 self.assertEqual(cm.exception.args[0], self.dirname)
2d42a308927b Test trying to load missing config.ini file.
John Rouillard <rouilj@ieee.org>
parents: 6358
diff changeset
534
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
535 def testCopyConfig(self):
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
536
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
537 self.munge_configini(mods=[ ("html_version = ", "xhtml") ])
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
538
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
539 config = configuration.CoreConfig()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
540
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
541 # verify config is initalized to defaults
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
542 self.assertEqual(config['HTML_VERSION'], 'html4')
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
543
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
544 # load config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
545 config.load(self.dirname)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
546
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
547 # loaded new option
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
548 self.assertEqual(config['HTML_VERSION'], 'xhtml')
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
549
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
550 # copy config
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
551 config_copy = config.copy()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
552
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
553 # this should work
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
554 self.assertEqual(config_copy['HTML_VERSION'], 'xhtml')
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
555
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
556 def testInvalidIndexerValue(self):
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
557 """ Mistype native indexer. Verify exception is
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
558 generated.
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
559 """
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
560
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
561 print("Testing indexer nati")
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
562
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
563 self.munge_configini(mods=[ ("indexer = ", "nati") ])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
564
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
565 with self.assertRaises(configuration.OptionValueError) as cm:
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
566 config.load(self.dirname)
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
567
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
568 self.assertIn("OptionValueError", repr(cm.exception))
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
569 # look for failing value
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
570 self.assertEqual("nati", cm.exception.args[1])
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
571 # look for supported values
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
572 self.assertIn("'whoosh'", cm.exception.args[2])
6358
42db48c30d31 Validate indexer values
John Rouillard <rouilj@ieee.org>
parents: 6357
diff changeset
573
6363
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
574 # verify that args show up in string representaton
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
575 string_rep = cm.exception.__str__()
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
576 print(string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
577 self.assertIn("nati", string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
578 self.assertIn("'whoosh'", string_rep)
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
579
08e209a7f22b Use OptionValueError for indexer_language error, add configuration tests
John Rouillard <rouilj@ieee.org>
parents: 6359
diff changeset
580

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