Compare commits

..

No commits in common. "5b8d88339f9e9ac53a97918338135a5f48b1750f" and "1ded24aab54b695ae5bf28f1891d7c1090e8417b" have entirely different histories.

6 changed files with 11 additions and 72 deletions

View File

@ -1,45 +0,0 @@
#!/usr/bin/env python3
import pytest
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
@pytest.fixture(scope='session')
def database(request):
"""
Create a Postgres database for the tests, and drop it when the tests are done.
"""
pg_host = DB_OPTS.get("postgresql")
pg_port = DB_OPTS.get("5432")
pg_user = DB_OPTS.get("input-service-test")
pg_db = DB_OPTS["input-service-test"]
init_postgresql_database(pg_user, pg_host, pg_port, pg_db)
@request.addfinalizer
def drop_database():
drop_postgresql_database(pg_user, pg_host, pg_port, pg_db)
@pytest.fixture(scope='session')
def app(database):
"""
Create a Flask app context for the tests.
"""
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = DB_CONN
return app
@pytest.fixture(scope='session')
def _db(app):
"""
Provide the transactional fixtures with access to the database via a Flask-SQLAlchemy
database connection.
"""
db = SQLAlchemy(app=app)
return db

View File

@ -1,4 +0,0 @@
pytest
pytest-rabbitmq
pytest-httpserver
pytest-flask-sqlalchemy

View File

@ -24,11 +24,9 @@ if SENTRY_DSN:
sentry_sdk.init( sentry_sdk.init(
dsn=SENTRY_DSN, dsn=SENTRY_DSN,
integrations=[FlaskIntegration()], integrations=[FlaskIntegration()],
traces_sample_rate=1.0,
send_default_pii=True, send_default_pii=True,
release=RELEASE_ID, release=RELEASE_ID,
environment=RELEASEMODE, environment=RELEASEMODE
_experiments={"auto_enabling_integrations": True}
) )

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import uuid
import pika import pika
""" """
@ -29,7 +28,6 @@ class FlaskRabbitBroker:
self.connection = None self.connection = None
self.channel = None self.channel = None
self.exchange = None self.exchange = None
self.exchange_type = "fanout"
def init_app(self, app) -> None: def init_app(self, app) -> None:
""" """
@ -37,11 +35,11 @@ class FlaskRabbitBroker:
:param app: application context :param app: application context
:return: :return:
""" """
self.username = app.config.get('RABBIT_USERNAME') self.username = app.context.get('RABBIT_USERNAME')
self.password = app.config.get('RABBIT_PASSWORD') self.password = app.context.get('RABBIT_PASSWORD')
self.rabbitmq_host = app.config.get('RABBIT_HOST') self.rabbitmq_host = app.context.get('RABBIT_HOST')
self.exchange_name = app.config.get('EXCHANGE_NAME') self.exchange_name = app.context.get('EXCHANGE_NAME')
self.routing_key = app.config.get('RABBIT_ROUTING_KEY') self.routing_key = app.context.get('RABBIT_ROUTING_KEY')
self.init_connection(timeout=5) self.init_connection(timeout=5)
self.init_exchange() self.init_exchange()
@ -67,8 +65,8 @@ class FlaskRabbitBroker:
""" """
channel = self.connection.channel() channel = self.connection.channel()
try: try:
channel.exchange_declare(exchange=self.exchange_name, exchange = channel.exchange_declare(exchange=self.exchange_name,
exchange_type=self.exchange_type, exchange_type='fanout',
durable=True, durable=True,
auto_delete=False) auto_delete=False)
finally: finally:
@ -81,10 +79,9 @@ class FlaskRabbitBroker:
:return: :return:
""" """
channel = self.connection.channel() channel = self.connection.channel()
queue = channel.queue_declare(durable=True, auto_delete=False, exclusive=True, queue = channel.queue_declare(durable=True, auto_delete=False)
queue=uuid.uuid4().urn.split(':')[2]).method.queue queue.bind(self.exchange)
channel.bind(exchange=self.exchange_name, queue=queue) queue.basic_consume(callback, no_ack=True)
channel.basic_consume(queue=queue, on_message_callback=callback, auto_ack=True)
def send(self, message: str) -> None: def send(self, message: str) -> None:
""" """

View File

@ -1,7 +0,0 @@
#!/usr/bin/env python3
"""
Unit tests
"""
import pytest