예제 #1
0
    def test_file_content_may_be_invalid(self):
        with tempfile.NamedTemporaryFile() as tags_file:
            os.environ['RAVEN_TAGS_FILE'] = tags_file.name
            self.assertEquals({'RAVEN_TAGS_FILE': 'invalid content'},
                              get_raven_config().tags)

            tags_file.write('not json at all')
            tags_file.seek(0)
            self.assertEquals({'RAVEN_TAGS_FILE': 'invalid content'},
                              get_raven_config().tags)
예제 #2
0
    def test_file_content_may_be_invalid(self):
        with tempfile.NamedTemporaryFile() as tags_file:
            os.environ['RAVEN_TAGS_FILE'] = tags_file.name
            self.assertEquals({'RAVEN_TAGS_FILE': 'invalid content'},
                              get_raven_config().tags)

            tags_file.write('not json at all')
            tags_file.seek(0)
            self.assertEquals({'RAVEN_TAGS_FILE': 'invalid content'},
                              get_raven_config().tags)
예제 #3
0
    def test_disabling_custom_exceptions(self):
        self.assertNotIn('RandomError',
                         get_raven_config().ignored_exception_classnames)

        os.environ['RAVEN_DISABLE_EXCEPTIONS'] = 'RandomError'
        self.assertIn('RandomError',
                      get_raven_config().ignored_exception_classnames)

        os.environ['RAVEN_DISABLE_EXCEPTIONS'] = 'Foo, RandomError, Bar'
        self.assertIn('RandomError',
                      get_raven_config().ignored_exception_classnames)
예제 #4
0
    def test_custom_tags_by_file(self):
        with tempfile.NamedTemporaryFile() as tags_file:
            os.environ['RAVEN_TAGS_FILE'] = tags_file.name
            tags_file.write('{"status": "testing"}')
            tags_file.seek(0)

            self.assertEquals({'status': 'testing'}, get_raven_config().tags)
예제 #5
0
    def test_custom_tags_by_file(self):
        with tempfile.NamedTemporaryFile() as tags_file:
            os.environ['RAVEN_TAGS_FILE'] = tags_file.name
            tags_file.write('{"status": "testing"}')
            tags_file.seek(0)

            self.assertEquals({'status': 'testing'},
                              get_raven_config().tags)
예제 #6
0
 def test_custom_tags_with_env_variable(self):
     os.environ['RAVEN_TAGS'] = ('{"deployment_type": "production",'
                                 ' "maintainer": "peter"}')
     self.assertEquals(
         {
             "deployment_type": "production",
             "maintainer": "peter"
         },
         get_raven_config().tags)
예제 #7
0
    def test_combining_tags_from_file_and_env_variable(self):
        os.environ['RAVEN_TAGS'] = '{"maintainer": "hans", "priority": "env"}'
        with tempfile.NamedTemporaryFile() as tags_file:
            os.environ['RAVEN_TAGS_FILE'] = tags_file.name
            tags_file.write('{"purpose": "demo", "priority": "file"}')
            tags_file.seek(0)

            self.assertEquals({'purpose': 'demo',
                               'maintainer': 'hans',
                               'priority': 'env'},
                              get_raven_config().tags)
예제 #8
0
def get_raven_client():
    config = get_raven_config()
    if not config.enabled:
        return None

    if globals().get('_client_cache', None) is not None:
        return globals()['_client_cache']

    globals()['_client_cache'] = raven_client_class(
        dsn=config.dsn,
        install_sys_hook=False)
    return globals()['_client_cache']
예제 #9
0
    def test_ignored_exception_classnames(self):
        self.assertEquals(
            set(['Redirect', 'NotFound', 'Unauthorized', 'Intercepted']),
            set(get_raven_config().ignored_exception_classnames))

        os.environ['RAVEN_ENABLE_EXCEPTIONS'] = 'NotFound'
        self.assertEquals(set(['Redirect', 'Unauthorized', 'Intercepted']),
                          set(get_raven_config().ignored_exception_classnames))

        os.environ['RAVEN_ENABLE_EXCEPTIONS'] = 'Unauthorized, Redirect'
        self.assertEquals(set(['NotFound', 'Intercepted']),
                          set(get_raven_config().ignored_exception_classnames))

        os.environ[
            'RAVEN_ENABLE_EXCEPTIONS'] = 'Unauthorized, Redirect, NotFound'
        self.assertEquals(set(['Intercepted']),
                          set(get_raven_config().ignored_exception_classnames))

        os.environ[
            'RAVEN_ENABLE_EXCEPTIONS'] = 'Unauthorized, Redirect, NotFound, Intercepted'
        self.assertEquals(set(),
                          set(get_raven_config().ignored_exception_classnames))
예제 #10
0
    def __call__(self):
        if not get_raven_config().enabled:
            return ''

        config = {
            'dsn': self._get_dsn_without_private_key(),
            'options': self._get_install_args(),
            'user_context': reporter.prepare_user_infos(
                self.context, self.request,
                include_roles=False)}

        return 'var raven_config = {};'.format(
            json.dumps(config, sort_keys=True, indent=4))
예제 #11
0
    def test_combining_tags_from_file_and_env_variable(self):
        os.environ['RAVEN_TAGS'] = '{"maintainer": "hans", "priority": "env"}'
        with tempfile.NamedTemporaryFile() as tags_file:
            os.environ['RAVEN_TAGS_FILE'] = tags_file.name
            tags_file.write('{"purpose": "demo", "priority": "file"}')
            tags_file.seek(0)

            self.assertEquals(
                {
                    'purpose': 'demo',
                    'maintainer': 'hans',
                    'priority': 'env'
                },
                get_raven_config().tags)
예제 #12
0
    def test_ignored_exception_classnames(self):
        self.assertEquals(
            set(['Redirect', 'NotFound', 'Unauthorized', 'Intercepted']),
            set(get_raven_config().ignored_exception_classnames))

        os.environ['RAVEN_ENABLE_EXCEPTIONS'] = 'NotFound'
        self.assertEquals(
            set(['Redirect', 'Unauthorized', 'Intercepted']),
            set(get_raven_config().ignored_exception_classnames))

        os.environ['RAVEN_ENABLE_EXCEPTIONS'] = 'Unauthorized, Redirect'
        self.assertEquals(
            set(['NotFound', 'Intercepted']),
            set(get_raven_config().ignored_exception_classnames))

        os.environ['RAVEN_ENABLE_EXCEPTIONS'] = 'Unauthorized, Redirect, NotFound'
        self.assertEquals(
            set(['Intercepted']),
            set(get_raven_config().ignored_exception_classnames))

        os.environ['RAVEN_ENABLE_EXCEPTIONS'] = 'Unauthorized, Redirect, NotFound, Intercepted'
        self.assertEquals(
            set(),
            set(get_raven_config().ignored_exception_classnames))
예제 #13
0
def get_release():
    config = get_raven_config()
    if config.project_dist:
        try:
            return get_distribution(config.project_dist).version
        except DistributionNotFound:
            LOG.error('The distribution "{}" could not be found.'.format(config.project_dist))
            return None

    if config.buildout_root:
        try:
            return fetch_git_sha(config.buildout_root)
        except InvalidGitRepository:
            LOG.error("The path {} does not exist or is not" " a git repository".format(config.buildout_root))
            return None

    return None
예제 #14
0
    def __call__(self):
        if not get_raven_config().enabled:
            return ''

        config = {
            'dsn':
            self._get_dsn_without_private_key(),
            'options':
            self._get_install_args(),
            'user_context':
            reporter.prepare_user_infos(self.context,
                                        self.request,
                                        include_roles=False)
        }

        return 'var raven_config = {};'.format(
            json.dumps(config, sort_keys=True, indent=4))
예제 #15
0
def get_release():
    config = get_raven_config()
    if config.project_dist:
        try:
            return get_distribution(config.project_dist).version
        except DistributionNotFound:
            LOG.error('The distribution "{}" could not be found.'.format(
                config.project_dist))
            return None

    if config.buildout_root:
        try:
            return fetch_git_sha(config.buildout_root)
        except InvalidGitRepository:
            LOG.error('The path {} does not exist or is not'
                      ' a git repository'.format(config.buildout_root))
            return None

    return None
예제 #16
0
 def test_project_dist(self):
     os.environ['RAVEN_PROJECT_DIST'] = 'my.project'
     self.assertEquals('my.project', get_raven_config().project_dist)
예제 #17
0
 def test_dsn_is_accessible_as_attribute(self):
     os.environ['RAVEN_DSN'] = 'https://*****:*****@sentry.local/3'
     self.assertEquals('https://*****:*****@sentry.local/3',
                       get_raven_config().dsn)
예제 #18
0
 def test_enabled_when_dsn_configured(self):
     os.environ['RAVEN_DSN'] = 'https://*****:*****@sentry.local/2'
     self.assertTrue(get_raven_config().enabled)
예제 #19
0
 def test_buildout_root(self):
     parent_dir = os.path.dirname(__file__)
     os.environ['RAVEN_BUILDOUT_ROOT'] = parent_dir
     self.assertEquals(parent_dir, get_raven_config().buildout_root)
예제 #20
0
 def test_file_may_not_exist(self):
     os.environ['RAVEN_TAGS_FILE'] = '/foo/br'
     self.assertEquals({'RAVEN_TAGS_FILE': 'missing file'},
                       get_raven_config().tags)
예제 #21
0
 def test_enabled_when_dsn_configured(self):
     os.environ['RAVEN_DSN'] = 'https://*****:*****@sentry.local/2'
     self.assertTrue(get_raven_config().enabled)
예제 #22
0
 def test_project_dist(self):
     os.environ['RAVEN_PROJECT_DIST'] = 'my.project'
     self.assertEquals('my.project', get_raven_config().project_dist)
예제 #23
0
 def test_no_tags_by_default(self):
     self.assertEquals({}, get_raven_config().tags)
예제 #24
0
 def _get_dsn_without_private_key(self):
     dsn = get_raven_config().dsn
     return re.sub(r'(://[^:]*):[^@]*(@)', '\g<1>\g<2>', dsn)
예제 #25
0
 def test_not_enabled_when_not_configured(self):
     self.assertFalse(get_raven_config().enabled)
예제 #26
0
 def _get_dsn_without_private_key(self):
     dsn = get_raven_config().dsn
     return re.sub(r'(threaded\+requests\+)?([^:]*://[^:]*):[^@]*(@)',
                   '\g<2>\g<3>', dsn)
예제 #27
0
 def test_dsn_is_accessible_as_attribute(self):
     os.environ['RAVEN_DSN'] = 'https://*****:*****@sentry.local/3'
     self.assertEquals('https://*****:*****@sentry.local/3',
                       get_raven_config().dsn)
예제 #28
0
 def test_buildout_root(self):
     parent_dir = os.path.dirname(__file__)
     os.environ['RAVEN_BUILDOUT_ROOT'] = parent_dir
     self.assertEquals(parent_dir, get_raven_config().buildout_root)
예제 #29
0
 def test_custom_tags_may_be_invalid(self):
     os.environ['RAVEN_TAGS'] = '{"something completely wrong":}'
     self.assertEquals({'RAVEN_TAGS': 'invalid configuration'},
                       get_raven_config().tags)
예제 #30
0
 def test_custom_tags_may_be_invalid(self):
     os.environ['RAVEN_TAGS'] = '{"something completely wrong":}'
     self.assertEquals({'RAVEN_TAGS': 'invalid configuration'},
                       get_raven_config().tags)
예제 #31
0
 def test_custom_tags_with_env_variable(self):
     os.environ['RAVEN_TAGS'] = ('{"deployment_type": "production",'
                                 ' "maintainer": "peter"}')
     self.assertEquals({"deployment_type": "production",
                        "maintainer": "peter"},
                       get_raven_config().tags)
예제 #32
0
def is_exception_type_ignored(exc_type):
    if exc_type is None:
        return True
    ignored_classnames = get_raven_config().ignored_exception_classnames
    return exc_type.__name__ in ignored_classnames
예제 #33
0
 def test_file_may_not_exist(self):
     os.environ['RAVEN_TAGS_FILE'] = '/foo/br'
     self.assertEquals({'RAVEN_TAGS_FILE': 'missing file'},
                       get_raven_config().tags)
예제 #34
0
def get_default_tags():
    return get_raven_config().tags.copy()
예제 #35
0
 def test_not_enabled_when_not_configured(self):
     self.assertFalse(get_raven_config().enabled)
예제 #36
0
def is_exception_type_ignored(exc_type):
    if exc_type is None:
        return True
    ignored_classnames = get_raven_config().ignored_exception_classnames
    return exc_type.__name__ in ignored_classnames
예제 #37
0
def get_default_tags():
    return get_raven_config().tags.copy()
예제 #38
0
 def test_no_tags_by_default(self):
     self.assertEquals({}, get_raven_config().tags)