-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1290ec4
commit 76778c0
Showing
20 changed files
with
887 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from src.adapters.fetch_filenames.rabbitmq import RabbitMQFetchFilenamesClient | ||
from src.deployments.scripts.config import RabbitMQConfig | ||
import pika | ||
import pytest | ||
from pytest import MonkeyPatch | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def rabbitmq_fetch_filenames_client() -> RabbitMQFetchFilenamesClient: | ||
return RabbitMQFetchFilenamesClient( | ||
host=RabbitMQConfig.HOST, | ||
port=RabbitMQConfig.PORT, | ||
credentials_service=lambda: (RabbitMQConfig.USERNAME, RabbitMQConfig.PASSWORD), | ||
queue=RabbitMQConfig.QUEUE, | ||
polling_timeout=RabbitMQConfig.POLLING_TIMEOUT, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def raw_rabbitmq_pika_conn_config() -> tuple[pika.BaseConnection, str]: | ||
pika_conn = pika.BlockingConnection( | ||
pika.ConnectionParameters( | ||
host=RabbitMQConfig.HOST, | ||
port=RabbitMQConfig.PORT, | ||
credentials=pika.PlainCredentials( | ||
RabbitMQConfig.USERNAME, RabbitMQConfig.PASSWORD | ||
), | ||
) | ||
) | ||
return pika_conn, RabbitMQConfig.QUEUE |
2 changes: 0 additions & 2 deletions
2
consumer/tests/test_adapters/test_fetch_filenames/test_rabbitmq/test_helloworld.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from src.adapters.upsert_iot_records.postgres import PostgresUpsertIOTRecordsClient | ||
from src.deployments.scripts.config import PostgresConfig | ||
import psycopg2 | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def postgres_upsert_iot_records_client() -> PostgresUpsertIOTRecordsClient: | ||
return PostgresUpsertIOTRecordsClient( | ||
host=PostgresConfig.HOST, | ||
port=PostgresConfig.PORT, | ||
credentials_service=lambda: (PostgresConfig.USERNAME, PostgresConfig.PASSWORD), | ||
database=PostgresConfig.DATABASE, | ||
batch_upsert_size=PostgresConfig.BATCH_UPSERT_SIZE, | ||
) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def raw_postgres_psycopg2_conn_config() -> psycopg2.extensions.connection: | ||
with psycopg2.connect( | ||
host=PostgresConfig.HOST, | ||
port=PostgresConfig.PORT, | ||
user=PostgresConfig.USERNAME, | ||
password=PostgresConfig.PASSWORD, | ||
database=PostgresConfig.DATABASE, | ||
) as conn: | ||
yield conn | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def setup_teardown_postgres_tables( | ||
raw_postgres_psycopg2_conn_config: psycopg2.extensions.connection, | ||
) -> None: | ||
with raw_postgres_psycopg2_conn_config.cursor() as cursor: | ||
try: | ||
cursor.execute( | ||
""" | ||
TRUNCATE TABLE records; | ||
""" | ||
) | ||
raw_postgres_psycopg2_conn_config.commit() | ||
yield | ||
except Exception as e: | ||
raw_postgres_psycopg2_conn_config.rollback() | ||
raise e | ||
finally: | ||
cursor.execute( | ||
""" | ||
TRUNCATE TABLE records; | ||
""" | ||
) | ||
raw_postgres_psycopg2_conn_config.commit() |
19 changes: 19 additions & 0 deletions
19
consumer/tests/test_adapters/test_upsert_iot_records/test_postgres/test_close_conn_failed.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pytest import LogCaptureFixture | ||
from src.adapters.upsert_iot_records.postgres import PostgresUpsertIOTRecordsClient | ||
from .utils import random_iot_records, MockedPostgresConnection | ||
import pytest | ||
|
||
|
||
def test_close_conn_failed( | ||
postgres_upsert_iot_records_client: PostgresUpsertIOTRecordsClient, | ||
caplog: LogCaptureFixture, | ||
): | ||
postgres_upsert_iot_records_client.upsert(random_iot_records()[0]) | ||
|
||
assert postgres_upsert_iot_records_client._conn is not None | ||
|
||
postgres_upsert_iot_records_client._conn = MockedPostgresConnection() | ||
|
||
with caplog.at_level("ERROR"): | ||
assert not postgres_upsert_iot_records_client.close() | ||
assert "Failed to close!" in caplog.text |
16 changes: 16 additions & 0 deletions
16
...r/tests/test_adapters/test_upsert_iot_records/test_postgres/test_close_conn_successful.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from src.adapters.upsert_iot_records.postgres import PostgresUpsertIOTRecordsClient | ||
from .utils import random_iot_records | ||
|
||
|
||
def test_close_conn_successful( | ||
postgres_upsert_iot_records_client: PostgresUpsertIOTRecordsClient, | ||
): | ||
postgres_upsert_iot_records_client.upsert(random_iot_records()[0]) | ||
assert postgres_upsert_iot_records_client._conn is not None | ||
assert postgres_upsert_iot_records_client.close() | ||
|
||
|
||
def test_none_conn_close_successful( | ||
postgres_upsert_iot_records_client: PostgresUpsertIOTRecordsClient, | ||
): | ||
assert postgres_upsert_iot_records_client.close() |
Oops, something went wrong.