Skip to content

Commit dc8cccf

Browse files
committed
unrefactor II: remove mock dynamodb
1 parent c0b4792 commit dc8cccf

File tree

2 files changed

+7
-51
lines changed

2 files changed

+7
-51
lines changed

ack_backend/tests/test_splunk_logging.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""Tests for ack lambda logging decorators"""
2-
32
import unittest
43
from unittest.mock import patch, call
54
import json
65
from io import StringIO
76
from contextlib import ExitStack
8-
from moto import mock_s3, mock_dynamodb
7+
from moto import mock_s3
98
from boto3 import client as boto3_client
109

1110
from tests.utils.values_for_ack_backend_tests import (
@@ -19,21 +18,18 @@
1918
from tests.utils.utils_for_ack_backend_tests import generate_event
2019

2120
with patch.dict("os.environ", MOCK_ENVIRONMENT_DICT):
22-
from clients import REGION_NAME
2321
from ack_processor import lambda_handler
2422

2523
s3_client = boto3_client("s3")
26-
dynamodb_client = boto3_client("dynamodb", region_name=REGION_NAME)
2724

2825

29-
@mock_s3
30-
@mock_dynamodb
3126
@patch.dict("os.environ", MOCK_ENVIRONMENT_DICT)
27+
@mock_s3
3228
class TestLoggingDecorators(unittest.TestCase):
3329
"""Tests for the ack lambda logging decorators"""
3430

3531
def setUp(self):
36-
GenericSetUp(s3_client, None, dynamodb_client)
32+
GenericSetUp(s3_client)
3733

3834
# MOCK SOURCE FILE WITH 100 ROWS TO SIMULATE THE SCENARIO WHERE THE ACK FILE IS NO FULL.
3935
# TODO: Test all other scenarios.
Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
"""Generic setup and teardown for ACK backend tests"""
22

3-
from unittest.mock import patch
4-
5-
from tests.utils.mock_environment_variables import BucketNames, MOCK_ENVIRONMENT_DICT, Firehose
6-
7-
# Ensure environment variables are mocked before importing from src files
8-
with patch.dict("os.environ", MOCK_ENVIRONMENT_DICT):
9-
from clients import REGION_NAME
10-
from constants import AuditTableKeys, AUDIT_TABLE_NAME, AUDIT_TABLE_QUEUE_NAME_GSI, AUDIT_TABLE_FILENAME_GSI
3+
from tests.utils.mock_environment_variables import BucketNames, Firehose, REGION_NAME
114

125

136
class GenericSetUp:
@@ -18,7 +11,7 @@ class GenericSetUp:
1811
* If firehose_client is provided, creates a firehose delivery stream
1912
"""
2013

21-
def __init__(self, s3_client=None, firehose_client=None, dynamodb_client=None):
14+
def __init__(self, s3_client=None, firehose_client=None):
2215

2316
if s3_client:
2417
for bucket_name in [BucketNames.SOURCE, BucketNames.DESTINATION, BucketNames.MOCK_FIREHOSE]:
@@ -37,41 +30,11 @@ def __init__(self, s3_client=None, firehose_client=None, dynamodb_client=None):
3730
},
3831
)
3932

40-
if dynamodb_client:
41-
dynamodb_client.create_table(
42-
TableName=AUDIT_TABLE_NAME,
43-
KeySchema=[{"AttributeName": AuditTableKeys.MESSAGE_ID, "KeyType": "HASH"}],
44-
AttributeDefinitions=[
45-
{"AttributeName": AuditTableKeys.MESSAGE_ID, "AttributeType": "S"},
46-
{"AttributeName": AuditTableKeys.FILENAME, "AttributeType": "S"},
47-
{"AttributeName": AuditTableKeys.QUEUE_NAME, "AttributeType": "S"},
48-
{"AttributeName": AuditTableKeys.STATUS, "AttributeType": "S"},
49-
],
50-
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
51-
GlobalSecondaryIndexes=[
52-
{
53-
"IndexName": AUDIT_TABLE_FILENAME_GSI,
54-
"KeySchema": [{"AttributeName": AuditTableKeys.FILENAME, "KeyType": "HASH"}],
55-
"Projection": {"ProjectionType": "KEYS_ONLY"},
56-
"ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
57-
},
58-
{
59-
"IndexName": AUDIT_TABLE_QUEUE_NAME_GSI,
60-
"KeySchema": [
61-
{"AttributeName": AuditTableKeys.QUEUE_NAME, "KeyType": "HASH"},
62-
{"AttributeName": AuditTableKeys.STATUS, "KeyType": "RANGE"},
63-
],
64-
"Projection": {"ProjectionType": "ALL"},
65-
"ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
66-
},
67-
],
68-
)
69-
7033

7134
class GenericTearDown:
7235
"""Performs generic tear down of mock resources"""
7336

74-
def __init__(self, s3_client=None, firehose_client=None, dynamodb_client=None):
37+
def __init__(self, s3_client=None, firehose_client=None):
7538

7639
if s3_client:
7740
for bucket_name in [BucketNames.SOURCE, BucketNames.DESTINATION, BucketNames.MOCK_FIREHOSE]:
@@ -80,7 +43,4 @@ def __init__(self, s3_client=None, firehose_client=None, dynamodb_client=None):
8043
s3_client.delete_bucket(Bucket=bucket_name)
8144

8245
if firehose_client:
83-
firehose_client.delete_delivery_stream(DeliveryStreamName=Firehose.STREAM_NAME)
84-
85-
if dynamodb_client:
86-
dynamodb_client.delete_table(TableName=AUDIT_TABLE_NAME)
46+
firehose_client.delete_delivery_stream(DeliveryStreamName=Firehose.STREAM_NAME)

0 commit comments

Comments
 (0)