"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/test/test_config.py" (26 Aug 2019, 8772 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_config.py": 1.6.1_vs_2.0.0.

    1 #
    2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
    3 # This module is free software, and you may redistribute it and/or modify
    4 # under the same terms as Python, so long as this copyright message and
    5 # disclaimer are retained in their original form.
    6 #
    7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
    8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
    9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
   10 # POSSIBILITY OF SUCH DAMAGE.
   11 #
   12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
   13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   14 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
   15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
   16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
   17 
   18 import unittest
   19 import logging
   20 
   21 import os, shutil, errno
   22 
   23 import pytest
   24 from roundup import configuration
   25 
   26 config = configuration.CoreConfig()
   27 config.DATABASE = "db"
   28 config.RDBMS_NAME = "rounduptest"
   29 config.RDBMS_HOST = "localhost"
   30 config.RDBMS_USER = "rounduptest"
   31 config.RDBMS_PASSWORD = "rounduptest"
   32 config.RDBMS_TEMPLATE = "template0"
   33 # these TRACKER_WEB and MAIL_DOMAIN values are used in mailgw tests
   34 config.MAIL_DOMAIN = "your.tracker.email.domain.example"
   35 config.TRACKER_WEB = "http://tracker.example/cgi-bin/roundup.cgi/bugs/"
   36 # uncomment the following to have excessive debug output from test cases
   37 # FIXME: tracker logging level should be increased by -v arguments
   38 #   to 'run_tests.py' script
   39 #config.LOGGING_FILENAME = "/tmp/logfile"
   40 #config.LOGGING_LEVEL = "DEBUG"
   41 config.init_logging()
   42 config.options['FOO'] = "value"
   43 
   44 class ConfigTest(unittest.TestCase):
   45 
   46     def test_badConfigKeyword(self):
   47         """Run configure tests looking for invalid option name
   48         """
   49         self.assertRaises(configuration.InvalidOptionError, config._get_option, "BadOptionName")
   50 
   51     def test_validConfigKeyword(self):
   52         """Run configure tests looking for invalid option name
   53         """
   54         self.assertEqual(config._get_option("FOO"), "value")
   55 
   56     def testTrackerWeb(self):
   57         config = configuration.CoreConfig()
   58 
   59         self.assertEqual(None,
   60              config._get_option('TRACKER_WEB').set("http://foo.example/bar/"))
   61         self.assertEqual(None,
   62              config._get_option('TRACKER_WEB').set("https://foo.example/bar/"))
   63 
   64         self.assertRaises(configuration.OptionValueError,
   65              config._get_option('TRACKER_WEB').set, "https://foo.example/bar")
   66 
   67         self.assertRaises(configuration.OptionValueError,
   68              config._get_option('TRACKER_WEB').set, "htt://foo.example/bar/")
   69 
   70         self.assertRaises(configuration.OptionValueError,
   71              config._get_option('TRACKER_WEB').set, "htt://foo.example/bar")
   72 
   73         self.assertRaises(configuration.OptionValueError,
   74              config._get_option('TRACKER_WEB').set, "")
   75 
   76     def testLoginAttemptsMin(self):
   77         config = configuration.CoreConfig()
   78 
   79         self.assertEqual(None,
   80                    config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("0"))
   81         self.assertEqual(None,
   82                     config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("200"))
   83 
   84         self.assertRaises(configuration.OptionValueError,
   85                    config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred")
   86 
   87         self.assertRaises(configuration.OptionValueError,
   88                    config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "-1")
   89 
   90         self.assertRaises(configuration.OptionValueError,
   91                    config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "")
   92 
   93     def testTimeZone(self):
   94         config = configuration.CoreConfig()
   95 
   96         self.assertEqual(None,
   97                 config._get_option('TIMEZONE').set("0"))
   98 
   99         # not a valid timezone
  100         self.assertRaises(configuration.OptionValueError,
  101                 config._get_option('TIMEZONE').set, "Zot")
  102 
  103         # 25 is not a valid UTC offset: -12 - +14 is range
  104         # possibly +/- 1 for DST. But roundup.date doesn't
  105         # constrain to this range.
  106         #self.assertRaises(configuration.OptionValueError,
  107         #        config._get_option('TIMEZONE').set, "25")
  108 
  109         try:
  110             import pytz
  111             self.assertEqual(None,
  112                     config._get_option('TIMEZONE').set("UTC"))
  113             self.assertEqual(None,
  114                     config._get_option('TIMEZONE').set("America/New_York"))
  115 
  116         except ImportError:
  117             self.assertRaises(configuration.OptionValueError,
  118                     config._get_option('TIMEZONE').set, "UTC")
  119             self.assertRaises(configuration.OptionValueError,
  120                     config._get_option('TIMEZONE').set, "America/New_York")
  121 
  122     def testWebSecretKey(self):
  123         config = configuration.CoreConfig()
  124 
  125         self.assertEqual(None,
  126                 config._get_option('WEB_SECRET_KEY').set("skskskd"))
  127 
  128         self.assertRaises(configuration.OptionValueError,
  129                 config._get_option('WEB_SECRET_KEY').set, "")
  130 
  131 
  132     def testStaticFiles(self):
  133         config = configuration.CoreConfig()
  134 
  135         self.assertEqual(None,
  136                 config._get_option('STATIC_FILES').set("foo /tmp/bar"))
  137 
  138         self.assertEqual(config.STATIC_FILES,
  139                          ["./foo", "/tmp/bar"])
  140 
  141         self.assertEqual(config['STATIC_FILES'],
  142                          ["./foo", "/tmp/bar"])
  143 
  144     def testIsolationLevel(self):
  145         config = configuration.CoreConfig()
  146 
  147         self.assertEqual(None,
  148             config._get_option('RDBMS_ISOLATION_LEVEL').set("read uncommitted"))
  149         self.assertEqual(None,
  150             config._get_option('RDBMS_ISOLATION_LEVEL').set("read committed"))
  151         self.assertEqual(None,
  152             config._get_option('RDBMS_ISOLATION_LEVEL').set("repeatable read"))
  153 
  154 
  155         self.assertRaises(configuration.OptionValueError,
  156             config._get_option('RDBMS_ISOLATION_LEVEL').set, "not a level")
  157 
  158     def testConfigSave(self):
  159 
  160         config = configuration.CoreConfig()
  161         # make scratch directory to create files in
  162 
  163         self.startdir = os.getcwd()
  164 
  165         self.dirname = os.getcwd() + '_test_config'
  166         os.mkdir(self.dirname)
  167 
  168         try:
  169             os.chdir(self.dirname)
  170             self.assertFalse(os.access("config.ini", os.F_OK))
  171             self.assertFalse(os.access("config.bak", os.F_OK))
  172             config.save()
  173             config.save() # creates .bak file
  174             self.assertTrue(os.access("config.ini", os.F_OK))
  175             self.assertTrue(os.access("config.bak", os.F_OK))
  176 
  177             self.assertFalse(os.access("foo.bar", os.F_OK))
  178             self.assertFalse(os.access("foo.bak", os.F_OK))
  179             config.save("foo.bar")
  180             config.save("foo.bar") # creates .bak file
  181             self.assertTrue(os.access("foo.bar", os.F_OK))
  182             self.assertTrue(os.access("foo.bak", os.F_OK))
  183 
  184         finally:
  185             # cleanup scratch directory and files
  186             try:
  187                 os.chdir(self.startdir)
  188                 shutil.rmtree(self.dirname)
  189             except OSError as error:
  190                 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
  191 
  192     def testFloatAndInt_with_update_option(self):
  193 
  194        config = configuration.CoreConfig()
  195 
  196        # Update existing IntegerNumberGeqZeroOption to IntegerNumberOption
  197        config.update_option('WEB_LOGIN_ATTEMPTS_MIN',
  198                             configuration.IntegerNumberOption,
  199                             "0", description="new desc")
  200 
  201        # -1 is allowed now that it is an int.
  202        self.assertEqual(None,
  203                     config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("-1"))
  204 
  205        # but can't float this
  206        self.assertRaises(configuration.OptionValueError,
  207                     config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "2.4")
  208 
  209        # but fred is still an issue
  210        self.assertRaises(configuration.OptionValueError,
  211                     config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred")
  212        
  213        # Update existing IntegerNumberOption to FloatNumberOption
  214        config.update_option('WEB_LOGIN_ATTEMPTS_MIN',
  215                             configuration.FloatNumberOption,
  216                             "0.0")
  217 
  218        self.assertEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], -1)
  219 
  220        # can float this
  221        self.assertEqual(None,
  222                 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set("3.1415926"))
  223 
  224        # but fred is still an issue
  225        self.assertRaises(configuration.OptionValueError,
  226                     config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred")
  227 
  228        self.assertAlmostEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], 3.1415926,
  229                               places=6)