Exemplo n.º 1
0
    def test_parse_configs_validators(self):
        settings = parse_configs()

        setting = settings.BOOLEAN_SETTING
        self.assertEqual(setting.validators, [])

        setting = settings.VALIDATOR_SETTING
        self.assertIn(abc_validator, setting.validators)
        self.assertIn(xyz_validator, setting.validators)
        self.assertEqual(setting.validators, [abc_validator, xyz_validator])
Exemplo n.º 2
0
    def test_parse_configs_validators(self):
        settings = parse_configs()

        setting = settings.BOOLEAN_SETTING
        self.assertEqual(setting.validators, [])

        setting = settings.VALIDATOR_SETTING
        self.assertIn(abc_validator, setting.validators)
        self.assertIn(xyz_validator, setting.validators)
        self.assertEqual(setting.validators, [abc_validator, xyz_validator])
Exemplo n.º 3
0
    def test_parse_configs_default_path(self):
        settings = parse_configs()

        self.assertEqual(len(settings), 15)
        self.assertEqual(settings.path,
                         os.path.join(django_settings.DIRNAME, 'settings.cfg'))

        setting = settings.BOOLEAN_SETTING
        self.assertEqual(setting.default, False)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.CHOICE_SETTING
        self.assertEqual(setting.default, 'pear')
        self.assertEqual(
            setting.choices,
            (('apple', 'apple'), ('grape', 'grape'), ('peach', 'peach'),
             ('pear', 'pear'), ('waterlemon', 'waterlemon'))
        )
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.DECIMAL_SETTING
        self.assertEqual(setting.default, Decimal('8.5'))
        self.assertEqual(setting.max_digits, 4)
        self.assertEqual(setting.decimal_places, 2)
        self.assertEqual(setting.min_value, Decimal('0'))
        self.assertEqual(setting.max_value, Decimal('10'))
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.INT_SETTING
        self.assertEqual(setting.default, 24)
        self.assertEqual(setting.min_value, 16)
        self.assertEqual(setting.max_value, 32)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.FLOAT_SETTING
        self.assertEqual(setting.default, 80.4)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)
        self.assertFalse(
            hasattr(setting, 'wrong_arg'), '%r has wrong_arg attr' % setting
        )

        setting = settings.STRING_SETTING
        self.assertEqual(setting.default, 'String String String')
        self.assertTrue(
            hasattr(setting, 'regex'), '%r has not regex attr' % setting
        )
        self.assertIsNotNone(setting.regex)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)
Exemplo n.º 4
0
    def test_parse_configs_default_path(self):
        settings = parse_configs()

        self.assertEqual(len(settings), 15)
        self.assertEqual(settings.path,
                         os.path.join(django_settings.DIRNAME, 'settings.cfg'))

        setting = settings.BOOLEAN_SETTING
        self.assertEqual(setting.default, False)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.CHOICE_SETTING
        self.assertEqual(setting.default, 'pear')
        self.assertEqual(setting.choices,
                         (('apple', 'apple'), ('grape', 'grape'),
                          ('peach', 'peach'), ('pear', 'pear'),
                          ('waterlemon', 'waterlemon')))
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.DECIMAL_SETTING
        self.assertEqual(setting.default, Decimal('8.5'))
        self.assertEqual(setting.max_digits, 4)
        self.assertEqual(setting.decimal_places, 2)
        self.assertEqual(setting.min_value, Decimal('0'))
        self.assertEqual(setting.max_value, Decimal('10'))
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.INT_SETTING
        self.assertEqual(setting.default, 24)
        self.assertEqual(setting.min_value, 16)
        self.assertEqual(setting.max_value, 32)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)

        setting = settings.FLOAT_SETTING
        self.assertEqual(setting.default, 80.4)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)
        self.assertFalse(hasattr(setting, 'wrong_arg'),
                         '%r has wrong_arg attr' % setting)

        setting = settings.STRING_SETTING
        self.assertEqual(setting.default, 'String String String')
        self.assertTrue(hasattr(setting, 'regex'),
                        '%r has not regex attr' % setting)
        self.assertIsNotNone(setting.regex)
        self.assertIsNotNone(setting.label)
        self.assertIsNotNone(setting.help_text)
Exemplo n.º 5
0
    def test_parse_configs_additional_type(self):
        settings = parse_configs()

        setting = settings.IP_SETTING
        self.assertEqual(setting.type, 'ip')
        self.assertEqual(setting.default, '127.0.0.1')
Exemplo n.º 6
0
    def test_parse_configs_additional_type(self):
        settings = parse_configs()

        setting = settings.IP_SETTING
        self.assertEqual(setting.type, 'ip')
        self.assertEqual(setting.default, '127.0.0.1')