diff --git a/.coverage_consumer b/.coverage_consumer deleted file mode 100644 index ee56acd..0000000 Binary files a/.coverage_consumer and /dev/null differ diff --git a/Makefile b/Makefile index 95fea5c..3411d53 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ test_consumer: export RABBITMQ_USERNAME=$(RABBITMQ_USERNAME) && \ export RABBITMQ_PASSWORD=$(RABBITMQ_PASSWORD) && \ export QUEUE_NAME=$(QUEUE_NAME) && \ - COVERAGE_FILE=.coverage_consumer coverage run -m pytest -vxs consumer/tests/test_adapters/test_fetch_filenames/test_rabbitmq + COVERAGE_FILE=.coverage_consumer coverage run -m pytest -vxs consumer/tests coverage_report: coverage combine .coverage_producer .coverage_consumer && \ coverage report -m --omit="*/tests/*" diff --git a/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_conn.py b/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_conn.py index 7089aa3..4823a85 100644 --- a/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_conn.py +++ b/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_conn.py @@ -4,7 +4,7 @@ from src.entities import IOTRecord import psycopg2 from .utils import random_iot_records, MockedPostgresConnection -from pytest import MonkeyPatch +from pytest import MonkeyPatch, LogCaptureFixture @pytest.mark.smoke @@ -14,9 +14,9 @@ def test_upsert_single_failed_conn( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_record: IOTRecord, monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): def mocked_failed_conn( - self, *args, **kwargs, ) -> None: @@ -24,8 +24,9 @@ def mocked_failed_conn( monkeypatch.setattr(psycopg2, "connect", mocked_failed_conn) - with pytest.raises(Exception, match="^Failed to connect$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "Failed to connect" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( @@ -54,9 +55,9 @@ def test_upsert_batch_failed_conn( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_records: list[IOTRecord], monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): def mocked_failed_conn( - self, *args, **kwargs, ) -> None: @@ -64,8 +65,9 @@ def mocked_failed_conn( monkeypatch.setattr(psycopg2, "connect", mocked_failed_conn) - with pytest.raises(Exception, match="^Failed to connect$"): + with caplog.at_level("ERROR"): assert not any(postgres_upsert_iot_records_client.upsert(iot_records)) + assert "Failed to connect" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: stmt = """ @@ -94,6 +96,7 @@ def mocked_failed_conn( def test_upsert_single_wrong_credentials( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_record: IOTRecord, + caplog: LogCaptureFixture, ): postgres_upsert_iot_records_client = PostgresUpsertIOTRecordsClient( host=PostgresConfig.HOST, @@ -103,8 +106,9 @@ def test_upsert_single_wrong_credentials( batch_upsert_size=1, ) - with pytest.raises(Exception, match="^.*403.*ACCESS_REFISED.*$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "ERROR" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( @@ -129,6 +133,7 @@ def test_upsert_single_wrong_credentials( def test_upsert_single_wrong_host( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_record: IOTRecord, + caplog: LogCaptureFixture, ): postgres_upsert_iot_records_client = PostgresUpsertIOTRecordsClient( host="wrong", @@ -138,8 +143,9 @@ def test_upsert_single_wrong_host( batch_upsert_size=1, ) - with pytest.raises(Exception, match="^.*403.*ACCESS_REFUSED.*$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "ERROR" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( diff --git a/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py b/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py index 12b7071..01555dc 100644 --- a/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py +++ b/consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_failed_upsert.py @@ -5,7 +5,7 @@ import pytest from src.entities import IOTRecord import psycopg2 -from pytest import MonkeyPatch +from pytest import MonkeyPatch, LogCaptureFixture @pytest.mark.smoke @@ -15,13 +15,15 @@ def test_upsert_single_failed( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_record: IOTRecord, monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): monkeypatch.setattr( psycopg2, "connect", lambda *args, **kwargs: MockedPostgresConnection() ) - with pytest.raises(Exception, match="^Failed to execute!$"): + with caplog.at_level("ERROR"): assert not postgres_upsert_iot_records_client.upsert(iot_record) + assert "Failed to execute!" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: cursor.execute( @@ -50,13 +52,15 @@ def test_upsert_batch_failed( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_records: list[IOTRecord], monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): monkeypatch.setattr( psycopg2, "connect", lambda *args, **kwargs: MockedPostgresConnection() ) - with pytest.raises(Exception, match="^Failed to execute!$"): - assert not any(postgres_upsert_iot_records_client.upsert(iot_records)) + with caplog.at_level("ERROR"): + assert not all(postgres_upsert_iot_records_client.upsert(iot_records)) + assert "Failed to execute!" in caplog.text with raw_postgres_psycopg2_conn_config.cursor() as cursor: stmt = """ @@ -90,6 +94,7 @@ def test_upsert_batch_partial_failed( raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, iot_records: list[IOTRecord], monkeypatch: MonkeyPatch, + caplog: LogCaptureFixture, ): new_postgres_upsert_iot_records_client = PostgresUpsertIOTRecordsClient( host=postgres_upsert_iot_records_client._host, @@ -139,12 +144,13 @@ def mocked_partially_failed_upsert( MockedPostgresCursor, "executemany", mocked_partially_failed_upsert ) - with pytest.raises(Exception, match="^Failed to execute!"): + with caplog.at_level("ERROR"): upsert_successes = new_postgres_upsert_iot_records_client.upsert(iot_records) assert not all(upsert_successes) assert any(upsert_successes) assert upsert_successes[2] == False + assert "Failed to execute!" in caplog.text successful_records = [ iot_record diff --git a/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py b/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py index 6b7dd0e..46f5819 100644 --- a/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py +++ b/producer/tests/test_adapters/test_publish_filenames/test_rabbitmq/test_failed_conn.py @@ -101,7 +101,6 @@ def test_publish_single_wrong_credentials( def test_publish_single_wrong_host( raw_rabbitmq_pika_conn_config: tuple[pika.BaseConnection, str], filename: str, - caplog: LogCaptureFixture, ): rabbitmq_publish_filenames_client = RabbitMQPublishFilenamesClient( host="wrong", @@ -110,9 +109,7 @@ def test_publish_single_wrong_host( queue=RabbitMQConfig.QUEUE, ) - with caplog.at_level("ERROR"): - assert not rabbitmq_publish_filenames_client.publish(filename) - assert "Name or service not known" in caplog.text + assert not rabbitmq_publish_filenames_client.publish(filename) pika_conn, queue = raw_rabbitmq_pika_conn_config channel = pika_conn.channel()