diff --git a/tests/step_defs/conftest.py b/tests/step_defs/conftest.py index b1a040c..e2ba0ce 100644 --- a/tests/step_defs/conftest.py +++ b/tests/step_defs/conftest.py @@ -1,7 +1,7 @@ import pytest from utilities.classes.sqs_client import SQSClient from utilities.classes.log import CustomLogger -from utilities.settings import queue_name, sqs_bucket, report_dir +from utilities.settings import QUEUE_NAME, SQS_BUCKET, REPORT_DIR from utilities import os_funcs as cmd from moto import mock_aws @@ -41,7 +41,7 @@ def log() -> CustomLogger: Returns: CustomLogger: A CustomLogger instance. """ - return CustomLogger(report_dir) + return CustomLogger(REPORT_DIR) @pytest.fixture(autouse=True, scope='module') def setup(request: 'pytest.FixtureRequest', mock_aws_flag: bool, log: CustomLogger) -> None: @@ -89,8 +89,8 @@ def sqs_cli(mock_aws_flag: bool, log: CustomLogger) -> SQSClient: Returns: SQSClient: An SQSClient instance. """ - sqs_cli = SQSClient(log=log, bucket=sqs_bucket, mock_aws_flag=mock_aws_flag) - sqs_cli.create_queue(queue_name) - sqs_cli.get_queue_url(queue_name) + sqs_cli = SQSClient(log=log, bucket=SQS_BUCKET, mock_aws_flag=mock_aws_flag) + sqs_cli.create_queue(QUEUE_NAME) + sqs_cli.get_queue_url(QUEUE_NAME) return sqs_cli diff --git a/tests/step_defs/test_messages_steps.py b/tests/step_defs/test_messages_steps.py index 304be92..b3554c5 100644 --- a/tests/step_defs/test_messages_steps.py +++ b/tests/step_defs/test_messages_steps.py @@ -1,6 +1,6 @@ from pytest_bdd import scenarios, given, when, then import json -from utilities.settings import project_dir +from utilities.settings import PROJECT_DIR # Load feature files for pytest-bdd scenarios('../features/cars_stream_processing.feature') @@ -19,7 +19,7 @@ def added_cars(sqs_cli: 'SQSClient', log: 'CustomLogger') -> list: list: List of cars added to the queue. """ log.info("######## Start Step: 'Given a list of cars are added to car queue' ########") - f = open(project_dir + "\\test-data\\cars.json", "r") + f = open(PROJECT_DIR + "\\test-data\\cars.json", "r") cars = json.loads(f.read()) for car in cars: diff --git a/utilities/classes/sqs_client.py b/utilities/classes/sqs_client.py index 92fe69d..3bb3e9b 100644 --- a/utilities/classes/sqs_client.py +++ b/utilities/classes/sqs_client.py @@ -1,10 +1,10 @@ import boto3 from botocore.exceptions import ClientError import json -from utilities.settings import localhost, region_name +from utilities.settings import LOCALHOST, REGION_NAME class SQSClient: - def __init__(self, log: 'CustomLogger', bucket: str, mock_aws_flag: bool, host: str = localhost, region_name: str = region_name): + def __init__(self, log: 'CustomLogger', bucket: str, mock_aws_flag: bool, host: str = LOCALHOST, region_name: str = REGION_NAME): """ Initialize SQSClient. @@ -12,8 +12,8 @@ def __init__(self, log: 'CustomLogger', bucket: str, mock_aws_flag: bool, host: log (CustomLogger): Logger object. bucket (str): Name of the AWS bucket. mock_aws_flag (bool): Flag indicating whether to mock AWS or not. - host (str, optional): Host URL. Defaults to localhost. - region_name (str, optional): AWS region name. Defaults to region_name. + host (str, optional): Host URL. Defaults to LOCALHOST. + region_name (str, optional): AWS region name. Defaults to REGION_NAME. """ self.log = log self.bucket_name = bucket diff --git a/utilities/os_funcs.py b/utilities/os_funcs.py index 7bdd06a..38a2e20 100644 --- a/utilities/os_funcs.py +++ b/utilities/os_funcs.py @@ -11,4 +11,4 @@ def stop_localstack() -> None: """ Stop local stack on command line. """ - os.system('localstack stop') \ No newline at end of file + os.system('localstack stop') diff --git a/utilities/settings.py b/utilities/settings.py index 01a8d11..27e2c31 100644 --- a/utilities/settings.py +++ b/utilities/settings.py @@ -1,8 +1,8 @@ import os -project_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) -report_dir = project_dir + "//reports" -queue_name = "cars" -localhost = "http://localhost:4566" -sqs_bucket = "sqs" -region_name = "eu-west-2" +PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +REPORT_DIR = PROJECT_DIR + "//reports" +QUEUE_NAME = "cars" +LOCALHOST = "http://localhost:4566" +SQS_BUCKET = "sqs" +REGION_NAME = "eu-west-2"