Skip to content

Commit 72e4bb7

Browse files
committed
mock test logs
1 parent 9fe19a1 commit 72e4bb7

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

backend/src/get_imms_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
from models.errors import Severity, Code, create_operation_outcome
99
from log_structure import function_info
1010
from constants import GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE
11+
from clients import logger
1112

1213
logging.basicConfig(level="INFO")
1314
logger = logging.getLogger()
1415

16+
1517
@function_info
1618
def get_imms_handler(event, _context):
1719
return get_immunization_by_id(event, make_controller())

backend/src/timer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import time
33

44
from functools import wraps
5+
from clients import logger
6+
57

68
logging.basicConfig()
79
logger = logging.getLogger()

backend/tests/test_create_imms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def setUp(self):
1313
self.controller = create_autospec(FhirController)
1414
self.logger_info_patcher = patch("logging.Logger.info")
1515
self.mock_logger_info = self.logger_info_patcher.start()
16+
self.logger_exception_patcher = patch("logging.Logger.exception")
17+
self.mock_logger_exception = self.logger_exception_patcher.start()
18+
1619

1720
def tearDown(self):
1821
patch.stopall()
@@ -31,7 +34,7 @@ def test_create_immunization(self):
3134
self.controller.create_immunization.assert_called_once_with(lambda_event)
3235
self.assertDictEqual(exp_res, act_res)
3336

34-
def test_handle_exception(self):
37+
def test_create_handle_exception(self):
3538
"""unhandled exceptions should result in 500"""
3639
lambda_event = {"aws": "event"}
3740
error_msg = "an unhandled error"

backend/tests/test_delete_imms.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import unittest
3-
from unittest.mock import create_autospec
3+
from unittest.mock import create_autospec, patch
44

55
from delete_imms_handler import delete_immunization
66
from fhir_controller import FhirController
@@ -11,6 +11,11 @@
1111
class TestDeleteImmunizationById(unittest.TestCase):
1212
def setUp(self):
1313
self.controller = create_autospec(FhirController)
14+
self.logger_exception_patcher = patch("logging.Logger.exception")
15+
self.mock_logger_exception = self.logger_exception_patcher.start()
16+
17+
def tearDown(self):
18+
patch.stopall()
1419

1520
def test_delete_immunization(self):
1621
"""it should delete Immunization"""
@@ -26,7 +31,7 @@ def test_delete_immunization(self):
2631
self.controller.delete_immunization.assert_called_once_with(lambda_event)
2732
self.assertDictEqual(exp_res, act_res)
2833

29-
def test_handle_exception(self):
34+
def test_delete_handle_exception(self):
3035
"""unhandled exceptions should result in 500"""
3136
lambda_event = {"pathParameters": {"id": "an-id"}}
3237
error_msg = "an unhandled error"

backend/tests/test_get_imms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_get_immunization_by_id(self):
2727
self.controller.get_immunization_by_id.assert_called_once_with(lambda_event)
2828
self.assertDictEqual(exp_res, act_res)
2929

30-
def test_handle_exception(self):
30+
def test_get_handle_exception(self):
3131
"""unhandled exceptions should result in 500"""
3232
lambda_event = {"headers": {"id": "an-id"}, "pathParameters": {"id": "an-id"}}
3333
error_msg = "an unhandled error"

backend/tests/test_search_imms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def setUp(self):
1818
self.mock_logger_exception = self.logger_exception_patcher.start()
1919
self.logger_info_patcher = patch("logging.Logger.info")
2020
self.mock_logger_info = self.logger_info_patcher.start()
21+
self.logger_exception_patcher = patch("logging.Logger.exception")
22+
self.mock_logger_exception = self.logger_exception_patcher.start()
2123

2224
def tearDown(self):
2325
patch.stopall()
@@ -142,7 +144,7 @@ def test_search_immunizations_lambda_size_limit(self):
142144
self.controller.search_immunizations.assert_called_once_with(lambda_event)
143145
self.assertEqual(act_res["statusCode"], 400)
144146

145-
def test_handle_exception(self):
147+
def test_search_handle_exception(self):
146148
"""unhandled exceptions should result in 500"""
147149
lambda_event = {"pathParameters": {"id": "an-id"}}
148150
error_msg = "an unhandled error"

backend/tests/test_update_imms.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def setUp(self):
1515
self.mock_logger_exception = self.logger_exception_patcher.start()
1616
self.logger_info_patcher = patch("logging.Logger.info")
1717
self.mock_logger_info = self.logger_info_patcher.start()
18+
self.logger_exception_patcher = patch("logging.Logger.exception")
19+
self.mock_logger_exception = self.logger_exception_patcher.start()
1820

1921
def tearDown(self):
2022
patch.stopall()

0 commit comments

Comments
 (0)