示例#1
0
    def test_detect_already_exists(self):
        config = EveConfig()

        config.set('ALREADY_EXIST', True)
        os.environ['ALREADY_EXIST'] = 'no'

        self.assertTrue(config.detect('ALREADY_EXIST'))
示例#2
0
    def test_set(self):
        config = EveConfig()
        config.set('VALID_KEY', '123')
        config['ANOTHER_KEY'] = True

        self.assertEqual('123', config.get('VALID_KEY'))
        self.assertTrue(config['ANOTHER_KEY'])
示例#3
0
    def test_set(self):
        config = EveConfig()
        config.set('VALID_KEY', '123')
        config['ANOTHER_KEY'] = True

        self.assertEqual('123', config.get('VALID_KEY'))
        self.assertTrue(config['ANOTHER_KEY'])
示例#4
0
    def test_detect_already_exists(self):
        config = EveConfig()

        config.set('ALREADY_EXIST', True)
        os.environ['ALREADY_EXIST'] = 'no'

        self.assertTrue(config.detect('ALREADY_EXIST'))
示例#5
0
    def test_resource(self):
        config = EveConfig()
        config.resource('example1', {'a': 123})

        self.assertEqual({'example1': {
            'a': 123
        }}, config.settings.get('DOMAIN'))
示例#6
0
    def test_detect(self):
        config = EveConfig()
        os.environ['TEST_1_DETECT'] = 'abc'

        result = config.detect('TEST_1_DETECT')

        self.assertEqual('abc', result)
        self.assertEqual('abc', config.get('TEST_1_DETECT'))
示例#7
0
    def test_detect(self):
        config = EveConfig()
        os.environ['TEST_1_DETECT'] = 'abc'

        result = config.detect('TEST_1_DETECT')

        self.assertEqual('abc', result)
        self.assertEqual('abc', config.get('TEST_1_DETECT'))
示例#8
0
    def test_get(self):
        config = EveConfig()

        config.set('ITEM_A', 1)
        config['ITEM_B'] = 2

        def invalid_get():
            return config['ITEM_C']

        self.assertEqual(1, config['ITEM_A'])
        self.assertEqual(2, config['ITEM_B'])
        self.assertRaises(IndexError, invalid_get)
示例#9
0
    def test_get(self):
        config = EveConfig()

        config.set('ITEM_A', 1)
        config['ITEM_B'] = 2

        def invalid_get():
            return config['ITEM_C']

        self.assertEqual(1, config['ITEM_A'])
        self.assertEqual(2, config['ITEM_B'])
        self.assertRaises(IndexError, invalid_get)
示例#10
0
    def test_detect_required(self):
        config = EveConfig()

        self.assertRaises(MissingConfigurationValue,
                          config.detect,
                          'NOT_FOUND',
                          required=True)
示例#11
0
    def test_item_methods_wrong_type(self):
        config = EveConfig()

        self.assertRaises(AttributeError, config.item_methods, False)
        self.assertRaises(AttributeError, config.item_methods, '')
        self.assertRaises(AttributeError, config.item_methods, None)
        self.assertRaises(AttributeError, config.item_methods, 1)
示例#12
0
    def test_resource(self):
        config = EveConfig()
        config.resource('example1', {'a': 123})

        self.assertEqual({'example1': {'a': 123}}, config.settings.get('DOMAIN'))
示例#13
0
    def test_apply(self):
        config = EveConfig()
        config.apply({'KEY_1': 123, 'KEY_2': 345})

        self.assertEqual(123, config.get('KEY_1'))
        self.assertEqual(345, config.get('KEY_2'))
示例#14
0
    def test_apply_invalid_type(self):
        config = EveConfig()

        self.assertRaises(AttributeError, config.apply, True)
        self.assertRaises(AttributeError, config.apply, '')
        self.assertRaises(AttributeError, config.apply, [])
示例#15
0
    def test_resource_duplicate(self):
        config = EveConfig()
        config.resource('example1', {})

        self.assertRaises(KeyError, config.resource, 'example1', {'a': 'b'})
示例#16
0
    def test_set_invalid_key(self):
        config = EveConfig()

        self.assertRaises(InvalidSettingKeyException, config.set,
                          'invalid key', '123')
示例#17
0
    def test_settings(self):
        config = EveConfig()
        config.set('ABC', 'def')

        self.assertEqual('def', config.settings.get('ABC'))
示例#18
0
    def test_apply(self):
        config = EveConfig()
        config.apply({'KEY_1': 123, 'KEY_2': 345})

        self.assertEqual(123, config.get('KEY_1'))
        self.assertEqual(345, config.get('KEY_2'))
示例#19
0
    def test_construct_with_kwargs(self):
        config = EveConfig(secret_key='chocolate')

        self.assertIsNotNone(config)
        self.assertEqual('chocolate', config['SECRET_KEY'])
示例#20
0
    def test_detect_default(self):
        config = EveConfig()

        self.assertEqual('abc', config.detect('STILL_MISSING', default='abc'))
示例#21
0
    def test_item_methods_invalid_verb(self):
        config = EveConfig()

        self.assertRaises(AttributeError, config.item_methods, ['JUMP'])
示例#22
0
    def test_set_cache(self):
        config = EveConfig()

        config.set_cache(60)
        self.assertEqual('max-age=60', config.get('CACHE_CONTROL'))
        self.assertEqual(60, config.get('CACHE_EXPIRES'))

        config.set_cache(45, 30)
        self.assertEqual('max-age=45', config.get('CACHE_CONTROL'))
        self.assertEqual(30, config.get('CACHE_EXPIRES'))

        config.set_cache(-1, -1)
        self.assertEqual('max-age=20', config.get('CACHE_CONTROL'))
        self.assertEqual(20, config.get('CACHE_EXPIRES'))
示例#23
0
 def test_item_methods(self):
     config = EveConfig()
     config.item_methods(['GET', 'POST', 'DELETE', 'PUT'])
示例#24
0
    def test_construct(self):
        config = EveConfig()

        self.assertIsNotNone(config)
        self.assertTrue(isinstance(config.configuration, dict))
示例#25
0
 def test_resource_methods(self):
     config = EveConfig()
     config.resource_methods(['GET', 'POST', 'PATCH', 'DELETE'])
示例#26
0
    def test_set_cache(self):
        config = EveConfig()

        config.set_cache(60)
        self.assertEqual('max-age=60', config.get('CACHE_CONTROL'))
        self.assertEqual(60, config.get('CACHE_EXPIRES'))

        config.set_cache(45, 30)
        self.assertEqual('max-age=45', config.get('CACHE_CONTROL'))
        self.assertEqual(30, config.get('CACHE_EXPIRES'))

        config.set_cache(-1, -1)
        self.assertEqual('max-age=20', config.get('CACHE_CONTROL'))
        self.assertEqual(20, config.get('CACHE_EXPIRES'))
示例#27
0
    def test_resource_duplicate(self):
        config = EveConfig()
        config.resource('example1', {})

        self.assertRaises(KeyError, config.resource, 'example1', {'a': 'b'})
示例#28
0
 def test_item_methods(self):
     config = EveConfig()
     config.item_methods(['GET', 'POST', 'DELETE', 'PUT'])
示例#29
0
    def test_settings(self):
        config = EveConfig()
        config.set('ABC', 'def')

        self.assertEqual('def', config.settings.get('ABC'))
示例#30
0
    def test_detect_default(self):
        config = EveConfig()

        self.assertEqual('abc', config.detect('STILL_MISSING', default='abc'))
示例#31
0
 def test_resource_methods(self):
     config = EveConfig()
     config.resource_methods(['GET', 'POST', 'PATCH', 'DELETE'])