Esempio n. 1
0
    def test_logging_setup_signal(self):
        app = Sanic(__name__)

        mock_handler = Mock()

        def receiver(sender, *args, **kwargs):
            self.assertIn("exclude", kwargs)
            mock_handler(*args, **kwargs)

        logging_configured.connect(receiver)
        raven = InMemoryClient()

        Sentry(
            app, client=raven, logging=True,
            logging_exclusions=("excluded_logger",))

        mock_handler.assert_called()
Esempio n. 2
0
def configure_sentry(app, config=current_config):
    global sentry_client
    global sentry
    if config.SENTRY_ENABLED:
        sentry_config = {
            'dsn': config.SENTRY_DSN,
            'release': fetch_git_sha(os.path.abspath(os.path.dirname(__file__))),
            'transport': AioHttpTransport,
            'ignore_exceptions': [NotFound],
            'environment': config.ENVIRONMENT
        }
        # initialize the client for sentry, note that the `sentry_client` is just a base client
        # you should use the `client` for methods like captureMethod, captureException
        sentry_client = Client(**sentry_config)
        sentry = Sentry(app, client=sentry_client)
        app.sentry = sentry
        app.sentry_client = sentry_client
        return sentry
Esempio n. 3
0
from exchangerates.utils import Gino, cors, parse_database_url

HISTORIC_RATES_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml"
LAST_90_DAYS_RATES_URL = (
    "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml")

app = Sanic()
app.config.update(
    parse_database_url(
        url=getenv("DATABASE_URL", "postgresql://localhost/exchangerates")))

# Database
db = Gino(app)

# Sentry
sentry = Sentry(app)


class ExchangeRates(db.Model):
    __tablename__ = "exchange_rates"

    date = db.Column(db.Date(), primary_key=True)
    rates = db.Column(JSONB())

    def __repr__(self):
        return "Rates [{}]".format(self.date)


async def update_rates(historic=False):
    r = requests.get(
        HISTORIC_RATES_URL if historic else LAST_90_DAYS_RATES_URL)
Esempio n. 4
0
 def make_client_and_raven(self, logging=False, *args, **kwargs):
     app = create_app(*args, **kwargs)
     raven = InMemoryClient()
     Sentry(app, logging=logging, client=raven)
     return app.test_client, raven, app
Esempio n. 5
0
 def bind_sentry(self):
     self.raven = InMemoryClient()
     self.middleware = Sentry(self.app, client=self.raven)
Esempio n. 6
0
 def test_overrides_default_include_paths(self):
     app = Sanic(__name__)
     app.config['SENTRY_CONFIG'] = {'include_paths': ['foo.bar']}
     sentry = Sentry(app, dsn='http://*****:*****@example.com/1')
     assert sentry.client.include_paths == set(['foo.bar'])
Esempio n. 7
0
 def test_binds_default_include_paths(self):
     app = Sanic(__name__)
     sentry = Sentry(app, dsn='http://*****:*****@example.com/1')
     assert sentry.client.include_paths == set([app.name])
Esempio n. 8
0
 def test_uses_dsn(self):
     app = Sanic(__name__)
     sentry = Sentry(app, dsn='http://*****:*****@example.com/1')
     assert sentry.client.remote.base_url == 'http://example.com'
Esempio n. 9
0
 def test_check_client_type(self):
     self.assertRaises(TypeError, lambda _: Sentry(self.app, "oops, I'm putting my DSN instead"))