Exemplo n.º 1
0
    def test_get_mail_backend(self):
        with self.options({'mail.backend': 'smtp'}):
            assert get_mail_backend() == 'django.core.mail.backends.smtp.EmailBackend'

        with self.options({'mail.backend': 'dummy'}):
            assert get_mail_backend() == 'django.core.mail.backends.dummy.EmailBackend'

        with self.options({'mail.backend': 'console'}):
            assert get_mail_backend() == 'django.core.mail.backends.console.EmailBackend'

        with self.options({'mail.backend': 'something.else'}):
            assert get_mail_backend() == 'something.else'
Exemplo n.º 2
0
    def test_get_mail_backend(self):
        with self.options({"mail.backend": "smtp"}):
            assert get_mail_backend() == "django.core.mail.backends.smtp.EmailBackend"

        with self.options({"mail.backend": "dummy"}):
            assert get_mail_backend() == "django.core.mail.backends.dummy.EmailBackend"

        with self.options({"mail.backend": "console"}):
            assert get_mail_backend() == "django.core.mail.backends.console.EmailBackend"

        with self.options({"mail.backend": "something.else"}):
            assert get_mail_backend() == "something.else"
Exemplo n.º 3
0
    def get(self, request):
        query = request.GET.get('query')
        if query == 'is:required':
            option_list = options.filter(flag=options.FLAG_REQUIRED)
        elif query:
            return Response('{} is not a supported search query'.format(query), status=400)
        else:
            option_list = options.all()

        # This is a fragile, hardcoded list of mail backends, but the likelihood of
        # someone using something custom here is slim, and even if they did, the worst
        # is they'd be prompted for SMTP information. These backends are guaranteed
        # to not need SMTP information.
        smtp_disabled = get_mail_backend() in (
            'django.core.mail.backends.dummy.EmailBackend',
            'django.core.mail.backends.console.EmailBackend',
            'django.core.mail.backends.locmem.EmailBackend',
            'django.core.mail.backends.filebased.EmailBackend',
            'sentry.utils.email.PreviewBackend',
        )

        results = {}
        for k in option_list:
            disabled, disabled_reason = False, None

            if smtp_disabled and k.name[:5] == 'mail.':
                disabled_reason, disabled = 'smtpDisabled', True
            elif bool(k.flags & options.FLAG_PRIORITIZE_DISK and settings.SENTRY_OPTIONS.get(k.name)):
                # TODO(mattrobenolt): Expose this as a property on Key.
                disabled_reason, disabled = 'diskPriority', True

            # TODO(mattrobenolt): help, placeholder, title, type
            results[k.name] = {
                'value': options.get(k.name),
                'field': {
                    'default': k.default(),
                    'required': bool(k.flags & options.FLAG_REQUIRED),
                    'disabled': disabled,
                    'disabledReason': disabled_reason,
                    'isSet': options.isset(k.name),
                    'allowEmpty': bool(k.flags & options.FLAG_ALLOW_EMPTY),
                }
            }

        return Response(results)