def test_string_boolean_setting_from_environ_false_value(self):
        bool_lower = appsettings.BooleanSetting(name="bool_lower")
        bool_lower.check()
        assert bool_lower.value is False

        bool_upper = appsettings.BooleanSetting(name="bool_upper")
        bool_upper.check()
        assert bool_upper.value is False

        bool_num = appsettings.BooleanSetting(name="bool_num")
        bool_num.check()
        assert bool_num.value is False

        bool_word = appsettings.BooleanSetting(name="bool_word")
        bool_word.check()
        assert bool_word.value is False
Esempio n. 2
0
    def test_nested_setting(self):
        setting = appsettings.NestedSetting(settings=dict())
        assert setting.value == {}
        setting.transform_default = True
        assert setting.value == {}

        setting = appsettings.NestedSetting(
            name="setting",
            default={},
            settings=dict(
                bool1=appsettings.BooleanSetting(default=False),
                bool2=appsettings.BooleanSetting(name="bool3", default=True),
            ),
        )
        assert setting.value == {}

        with override_settings(SETTING={"BOOL3": False}):
            assert setting.value == {"bool1": False, "bool2": False}
Esempio n. 3
0
class PainSettings(appsettings.AppSettings):
    """Specific settings for django-pain app."""

    # Dictionary of names and dotted paths to processor classes setting.
    processors = NamedClassSetting(
        'django_pain.processors.AbstractPaymentProcessor',
        required=True,
        key_type=str,
        value_type=str)

    # A card payment handler classes.
    card_payment_handlers = NamedClassSetting(
        'django_pain.card_payment_handlers.AbstractCardPaymentHandler',
        key_type=str,
        value_type=str)

    # Location of process_payments command lock file.
    process_payments_lock_file = appsettings.StringSetting(
        default='/tmp/pain_process_payments.lock')

    # Whether variable symbol should be trimmed of leading zeros.
    trim_varsym = appsettings.BooleanSetting(default=False)

    # List of dotted paths to callables that takes BankPayment object as their argument and return (possibly) changed
    # BankPayment.
    #
    # These callables are called right before the payment is saved during the import. Especially, these callable can
    # raise ValidationError in order to avoid saving payment to the database.
    import_callbacks = CallableListSetting(item_type=str)

    downloaders = NamedDictSetting(
        dict(DOWNLOADER=appsettings.ObjectSetting(
            required=True,
            validators=[ClassPathValidator(BankStatementDownloader)]),
             PARSER=appsettings.ObjectSetting(
                 required=True,
                 validators=[ClassPathValidator(BankStatementParser)]),
             DOWNLOADER_PARAMS=appsettings.DictSetting(required=True,
                                                       key_type=str)))

    # CSOB card settings
    csob_card = appsettings.NestedDictSetting(dict(
        api_url=appsettings.StringSetting(
            default='https://api.platebnibrana.csob.cz/api/v1.7/'),
        api_public_key=appsettings.FileSetting(required=True),
        merchant_id=appsettings.StringSetting(required=True),
        merchant_private_key=appsettings.FileSetting(required=True),
        account_name=appsettings.StringSetting(required=True),
    ),
                                              default=None)

    class Meta:
        """Meta class."""

        setting_prefix = 'pain_'
Esempio n. 4
0
class AppSettings(aps.AppSettings):
    """
    Application settings class.

    Settings:
    - default_response (bool):
    - skip_implicit (bool):
    - log_access (bool):
    - log_privileges (bool):
    - log_hierarchy (bool):
    - mapping (tuple):
    - namespace (str):
    """

    allow_update_own_privileges = aps.BooleanSetting(default=False)
    default_response = aps.BooleanSetting(default=False)
    skip_implicit = aps.BooleanSetting(default=False)
    log_access = aps.BooleanSetting(default=True)
    log_privileges = aps.BooleanSetting(default=True)
    log_hierarchy = aps.BooleanSetting(default=True)
    namespace = aps.StringSetting(default='')
    mapping = MappingSetting(default=())
    access_permission = aps.StringSetting(default='read')

    class Meta:
        setting_prefix = 'CERBERUS_'
Esempio n. 5
0
class AppSettings(aps.AppSettings):
    archan_dsm = ArchanPackagesSetting(default={
        'framework': ('Django', ['django']),
        'django-apps': ('Django Apps', ['meerkat']),
        'project-apps': ('Project Apps', []),
        'project-modules': ('Project Modules', []),
        'broker': ('Broker', []),
        'data': ('Data', [])
    }, name='ARCHAN_PACKAGES')

    logs_file_path_regex = RegexSetting()
    logs_format_regex = RegexSetting()
    logs_top_dir = aps.StringSetting(default=None)
    logs_start_daemon = aps.BooleanSetting(default=False)
    logs_url_whitelist = URLWhitelistSetting(default={
        'ASSET': {
            'PREFIXES': (
                'media/', 'static/', 'assets/', 'cache/',
            )
        },
        'COMMON_ASSET': {
            'CONSTANTS': (
                'favicon.ico', 'robots.txt', 'apple-touch-icon.png',
                'apple-touch-icon-precomposed.png',
                'apple-touch-icon-120x120.png',
                'apple-touch-icon-120x120-precomposed.png'
            )
        },
        'OLD_ASSET': {},
        'OLD_PROJECT': {},
        'FALSE_NEGATIVE': {},
        'IGNORED': {
            'PREFIXES': (
                'assets/flash/ZeroClipboard.swf',
            )
        }
    })

    class Meta:
        setting_prefix = 'MEERKAT_'
Esempio n. 6
0
class Settings(appsettings.AppSettings):
    DJANGO_LIVE_DASHBOARD = appsettings.NestedDictSetting(
        settings=dict(
            ENABLED=appsettings.BooleanSetting(default=False),
            WEBSOCKET_HOST=appsettings.StringSetting(default="localhost:8000"),
            TOTAL_TIME_CUTOFF=appsettings.FloatSetting(default=0.5),
            REDIS=appsettings.NestedDictSetting(
                settings=dict(
                    HOST=appsettings.StringSetting(default=REDIS_DEFAULTS["HOST"]),
                    PORT=appsettings.IntegerSetting(default=REDIS_DEFAULTS["PORT"]),
                    DB=appsettings.IntegerSetting(default=REDIS_DEFAULTS["DB"]),
                    PUBSUB_CHANNEL=appsettings.StringSetting(
                        default=REDIS_DEFAULTS["PUBSUB_CHANNEL"]
                    ),
                ),
                default=REDIS_DEFAULTS,
            ),
            CHART=appsettings.NestedDictSetting(
                settings=dict(
                    REFRESH=appsettings.IntegerSetting(
                        default=CHART_DEFAULTS["REFRESH"]
                    ),
                    DELAY=appsettings.IntegerSetting(default=CHART_DEFAULTS["DELAY"]),
                    DURATION=appsettings.IntegerSetting(
                        default=CHART_DEFAULTS["DURATION"]
                    ),
                ),
                default=CHART_DEFAULTS,
            ),
        ),
        default={
            "ENABLED": False,
            "WEBSOCKET_HOST": "localhost:8000",
            "TOTAL_TIME_CUTOFF": 0.5,
            "REDIS": REDIS_DEFAULTS,
            "CHART": CHART_DEFAULTS,
        },
    )
Esempio n. 7
0
 def test_boolean_setting(self):
     setting = appsettings.BooleanSetting()
     assert setting.value is True
 def test_string_boolean_setting_from_environ_invalid_value(self):
     bool_setting = appsettings.BooleanSetting(name="bool_setting")
     with pytest.raises(ValueError, match="Invalid boolean setting BOOL_SETTING"):
         bool_setting.check()
 def test_json_boolean_setting_from_environ_true_value(self):
     setting = appsettings.BooleanSetting(name="setting")
     setting.check()
     assert setting.value is True