diff --git a/tests/step_defs/test_messages_steps.py b/tests/step_defs/test_messages_steps.py index 402f947..bf568de 100644 --- a/tests/step_defs/test_messages_steps.py +++ b/tests/step_defs/test_messages_steps.py @@ -63,7 +63,7 @@ def queue_list(sqs_cli: 'SQSClient', log: 'CustomLogger') -> dict: # Then Step @then("the list contains the cars added") -def assert_response_code(sqs_cli: 'SQSClient', +def assert_response_code(sqs_cli: 'SQSClient', cars_list: list, messages: dict, log: 'CustomLogger') -> None: """ Then step to assert that the list contains the cars added. @@ -95,8 +95,8 @@ def assert_response_code(sqs_cli: 'SQSClient', log.info(f"delete message with id {in_message_id}") sqs_cli.delete_message(receipt_handle) messages_count += 1 - - error_messages = f"""Couldn't find all messages sent. + + error_messages = f"""Couldn't find all messages sent. Were sent {len(cars_list)} msgs, but found only {messages_count} msgs""" assert len(cars_list) == messages_count, error_messages diff --git a/utilities/classes/log.py b/utilities/classes/log.py index 2971629..3eb6367 100644 --- a/utilities/classes/log.py +++ b/utilities/classes/log.py @@ -10,8 +10,10 @@ class CustomLogger(Logger): """ A custom logger class that logs messages to both console and file with timed rotation. - This class extends the standard Logger class from the logging module and provides additional functionality - for logging messages to both console and file. Log files are rotated daily, and old log files are automatically + This class extends the standard Logger class + from the logging module and provides additional functionality + for logging messages to both console and file. Log files are rotated daily, + and old log files are automatically deleted after a specified number of days. Attributes: diff --git a/utilities/classes/sqs_client.py b/utilities/classes/sqs_client.py index afadbbb..b946574 100644 --- a/utilities/classes/sqs_client.py +++ b/utilities/classes/sqs_client.py @@ -20,7 +20,6 @@ class SQSClient: log (CustomLogger): Logger object. bucket_name (str): Name of the AWS bucket. host (str): Host URL. - region_name (str): AWS region name. mock_aws_flag (bool): Flag indicating whether to mock AWS or not. client (boto3.client): SQS client object. queue_url (str): URL of the SQS queue. @@ -35,8 +34,8 @@ class SQSClient: delete_message: Deletes a message from the SQS queue. """ - 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): """ Initialize SQSClient. @@ -45,12 +44,11 @@ def __init__(self, log: 'CustomLogger', bucket: str, 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. """ self.log = log self.bucket_name = bucket self.host = host - self.region_name = region_name + self.region_name = REGION_NAME self.mock_aws_flag = mock_aws_flag self.client = self.create_client() self.queue_url = '' @@ -63,12 +61,12 @@ def create_client(self) -> boto3.client: boto3.client: SQS client object. """ if self.mock_aws_flag: - return boto3.client(self.bucket_name, + return boto3.client(self.bucket_name, region_name=self.region_name ) - - return boto3.client(self.bucket_name, - endpoint_url=self.host, + + return boto3.client(self.bucket_name, + endpoint_url=self.host, region_name=self.region_name ) @@ -119,7 +117,7 @@ def send_message(self, car: dict) -> dict: """ try: message = car - response = self.client.send_message(QueueUrl=self.queue_url, + response = self.client.send_message(QueueUrl=self.queue_url, MessageBody=json.dumps(message)) self.log.info("Message sent") return response @@ -135,8 +133,8 @@ def receive_messages(self) -> dict: dict: Messages received from the SQS service. """ try: - messages = self.client.receive_message(QueueUrl=self.queue_url, - MaxNumberOfMessages=10, + messages = self.client.receive_message(QueueUrl=self.queue_url, + MaxNumberOfMessages=10, WaitTimeSeconds=10) self.log.info("Messages received") return messages