def test_get_from_fallback(self):
        cf = JSONConfigParser()
        cf.add_section('section')

        # returns from fallback if section exists
        self.assertEqual(cf.get('section', 'unset', 'fallback'), 'fallback')

        try:
            cf.get('nosection', 'unset', 'fallback')
        except NoSectionError:
            pass
        else:
            self.fail()
예제 #2
0
    def test_get_from_fallback(self):
        cf = JSONConfigParser()
        cf.add_section('section')

        # returns from fallback if section exists
        self.assertEqual(cf.get('section', 'unset', 'fallback'), 'fallback')

        try:
            cf.get('nosection', 'unset', 'fallback')
        except NoSectionError:
            pass
        else:  # pragma: no cover
            self.fail()
    def test_get_from_vars(self):
        cf = JSONConfigParser()
        cf.add_section('section')
        cf.set('section', 'option', 'set-in-section')

        self.assertEqual(cf.get('section', 'option',
                                vars={'option': 'set-in-vars'}),
                         'set-in-vars',
                         msg="vars should take priority over options in \
                              section")

        self.assertEqual(cf.get('section', 'option', vars={}),
                         'set-in-section',
                         msg="get should fall back to section if option not \
                              in vars")
예제 #4
0
    def test_get_from_vars(self):
        cf = JSONConfigParser()
        cf.add_section('section')
        cf.set('section', 'option', 'set-in-section')

        self.assertEqual(cf.get('section', 'option',
                                vars={'option': 'set-in-vars'}),
                         'set-in-vars',
                         msg="vars should take priority over options in \
                              section")

        self.assertEqual(cf.get('section', 'option', vars={}),
                         'set-in-section',
                         msg="get should fall back to section if option not \
                              in vars")
    def test_get_from_defaults(self):
        cf = JSONConfigParser()

        cf.set(cf.default_section, 'option', 'set-in-defaults')
        try:
            cf.get('section', 'option')
        except NoSectionError:
            pass
        else:
            self.fail("Only fall back to defaults if section exists")

        cf.add_section('section')
        self.assertEqual(cf.get('section', 'option'), 'set-in-defaults',
                         msg="get should fall back to defaults if value not \
                              set in section")

        cf.set('section', 'option', 'set-normally')
        self.assertEqual(cf.get('section', 'option'), 'set-normally',
                         msg="get shouldn't fall back if option is set \
                              normally")
예제 #6
0
    def test_get_from_defaults(self):
        cf = JSONConfigParser()

        cf.set(cf.default_section, 'option', 'set-in-defaults')
        try:
            cf.get('section', 'option')
        except NoSectionError:
            pass
        else:  # pragma: no cover
            self.fail("Only fall back to defaults if section exists")

        cf.add_section('section')
        self.assertEqual(cf.get('section', 'option'), 'set-in-defaults',
                         msg="get should fall back to defaults if value not \
                              set in section")

        cf.set('section', 'option', 'set-normally')
        self.assertEqual(cf.get('section', 'option'), 'set-normally',
                         msg="get shouldn't fall back if option is set \
                              normally")
    def test_read_file(self):
        string = '[section]\n' + \
                 'foo = "bar"'

        fp = tempfile.NamedTemporaryFile('w+')
        fp.write(string)
        fp.seek(0)

        cf = JSONConfigParser()
        cf.read_file(fp)

        self.assertEqual(cf.get('section', 'foo'), 'bar')
예제 #8
0
    def test_read_file(self):
        string = '[section]\n' + \
                 'foo = "bar"'

        fp = tempfile.NamedTemporaryFile('w+')
        fp.write(string)
        fp.seek(0)

        cf = JSONConfigParser()
        cf.read_file(fp)

        self.assertEqual(cf.get('section', 'foo'), 'bar')
    def test_read_string(self):
        cf = JSONConfigParser()

        cf.read_string((
            '[section]\n'
            '# comment comment\n'
            'foo = "bar"\n'
            '\n'
            '[section2]\n'
            'bar = "baz"\n'
        ))

        self.assertEqual(cf.get('section', 'foo'), 'bar')
예제 #10
0
    def test_read_string(self):
        cf = JSONConfigParser()

        cf.read_string((
            '[section]\n'
            '# comment comment\n'
            'foo = "bar"\n'
            '\n'
            '[section2]\n'
            'bar = "baz"\n'
        ))

        self.assertEqual(cf.get('section', 'foo'), 'bar')
    def test_remove_option(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'normal', 'set-normally')
        cf.set(cf.default_section, 'default', 'set-in-defaults')

        # can remove normal options
        self.assertTrue(cf.remove_option('section', 'normal'))
        self.assertFalse(cf.has_option('section', 'normal'))

        # can't remove defaults accidentally (maybe there should be shadowing)
        self.assertFalse(cf.remove_option('section', 'default'))
        self.assertEqual(cf.get('section', 'default'), 'set-in-defaults')
예제 #12
0
    def test_remove_option(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'normal', 'set-normally')
        cf.set(cf.default_section, 'default', 'set-in-defaults')

        # can remove normal options
        self.assertTrue(cf.remove_option('section', 'normal'))
        self.assertFalse(cf.has_option('section', 'normal'))

        # can't remove defaults accidentally (maybe there should be shadowing)
        self.assertFalse(cf.remove_option('section', 'default'))
        self.assertEqual(cf.get('section', 'default'), 'set-in-defaults')
    def test_get(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'section', 'set-in-section')
        self.assertEqual(cf.get('section', 'section'), 'set-in-section')
예제 #14
0
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

# STATIC_URL = '/static/'

# media files
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'
"""
    Import site-specifc stuff from config.ini.
"""
config = JSONConfigParser()
config.read(os.path.join(BASE_DIR, "config.ini"))

# Django [django] block
SECRET_KEY = config.get('django', 'SECRET_KEY')
ALLOWED_HOSTS = config.get('django', 'ALLOWED_HOSTS')
DEBUG = config.get('django', 'DEBUG')
# ADMINS = config.get('django', 'ADMINS')

# Parse meeting types
ORGANIZER_NAME = config.get('meetings', 'ORGANIZER_NAME')
ORGANIZER_EMAIL = config.get('meetings', 'ORGANIZER_EMAIL')
ORGANIZER_GREETING = config.get('meetings', 'ORGANIZER_GREETING')
BOOKING_TYPES = config.get('meetings', 'BOOKING_TYPES')

# Email settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_USE_SSL = config.get('email', 'USE_SSL')
EMAIL_USE_TLS = True
EMAIL_ADDRESS = config.get('email', 'ADDRESS')
예제 #15
0
    def test_get(self):
        cf = JSONConfigParser()

        cf.add_section('section')
        cf.set('section', 'section', 'set-in-section')
        self.assertEqual(cf.get('section', 'section'), 'set-in-section')
예제 #16
0
USE_TZ = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

##
## Import site-specifc stuff from config.ini.
##

config = JSONConfigParser()
config.read(os.path.join(BASE_DIR, "config.ini"))

# Django [django] block
SECRET_KEY = config.get('django', 'SECRET_KEY')
ALLOWED_HOSTS = config.get('django', 'ALLOWED_HOSTS')
DEBUG = config.get('django', 'DEBUG') # have set debug to false for the development mode
ADMINS = config.get('django', 'ADMINS')

# Parse meeting types
ORGANIZER_NAME = config.get('meetings', 'ORGANIZER_NAME')
ORGANIZER_EMAIL = config.get('meetings', 'ORGANIZER_EMAIL')
ORGANIZER_GREETING = config.get('meetings', 'ORGANIZER_GREETING')
BOOKING_TYPES = config.get('meetings', 'BOOKING_TYPES')

# Email settings
EMAIL_USE_SSL = config.get('email', 'USE_SSL')
EMAIL_ADDRESS = config.get('email', 'ADDRESS')
EMAIL_HOST = config.get('email', 'HOST')
EMAIL_PORT = config.get('email', 'PORT')