Skip to content

Commit

Permalink
refactoring 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmateusribeiro committed Jun 2, 2024
1 parent ebdbddb commit 18e36e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions tests/step_defs/test_messages_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions utilities/classes/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 10 additions & 12 deletions utilities/classes/sqs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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 = ''
Expand All @@ -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
)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 18e36e0

Please sign in to comment.