Skip to content

Commit 142bf71

Browse files
authored
Merge branch 'master' into VED-1143-Create-Subscription-SQS-Queue
2 parents dc0e420 + ec75255 commit 142bf71

41 files changed

Lines changed: 2054 additions & 1771 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lambdas/ack_backend/poetry.lock

Lines changed: 127 additions & 127 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lambdas/ack_backend/pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ packages = [
1111

1212
[tool.poetry.dependencies]
1313
python = "~3.11"
14-
boto3 = "~1.42.37"
15-
mypy-boto3-dynamodb = "^1.42.33"
14+
boto3 = "~1.42.74"
15+
mypy-boto3-dynamodb = "^1.42.73"
1616
freezegun = "^1.5.2"
17-
moto = "^5.1.20"
18-
coverage = "^7.13.2"
17+
moto = "^5.1.22"
18+
coverage = "^7.13.5"
1919

2020

2121
[build-system]

lambdas/backend/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package: build
99

1010
test:
1111
$(TEST_ENV) python -m unittest
12-
1312
coverage-run:
1413
$(TEST_ENV) coverage run --source=src -m unittest discover
1514

lambdas/backend/poetry.lock

Lines changed: 142 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lambdas/backend/pyproject.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ packages = [
1212
[tool.poetry.dependencies]
1313
python = "~3.11"
1414
"fhir.resources" = "~7.0.2"
15-
boto3 = "~1.42.37"
16-
boto3-stubs-lite = {extras = ["dynamodb"], version = "~1.42.37"}
15+
boto3 = "~1.42.74"
16+
boto3-stubs-lite = {extras = ["dynamodb"], version = "~1.42.74"}
1717
aws-lambda-typing = "~2.20.0"
1818
redis = "^4.6.0"
19-
moto = "^5.1.20"
19+
moto = "^5.1.22"
2020
requests = "~2.32.5"
21-
responses = "~0.25.7"
21+
responses = "~0.26.0"
2222
pydantic = "~1.10.13"
23-
pyjwt = {extras = ["crypto"], version = "^2.12.0"}
24-
jsonpath-ng = "^1.6.0"
23+
pyjwt = {extras = ["crypto"], version = "^2.12.1"}
24+
jsonpath-ng = "^1.8.0"
2525
simplejson = "^3.20.2"
2626
structlog = "^24.1.0"
2727
python-stdnum = "^2.1"
2828
freezegun = "^1.5.1"
29-
coverage = "^7.13.2"
29+
coverage = "^7.13.5"
3030

3131
[build-system]
3232
requires = ["poetry-core ~= 1.5.0"]

lambdas/backend/src/get_status_handler.py

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
import tempfile
3+
import unittest
4+
5+
from local_lambda import load_string
6+
7+
8+
class TestLoadString(unittest.TestCase):
9+
def test_reads_file_contents(self):
10+
fd, path = tempfile.mkstemp()
11+
self.addCleanup(os.unlink, path)
12+
with os.fdopen(fd, "w") as f:
13+
f.write("hello world")
14+
15+
self.assertEqual(load_string(path), "hello world")
16+
17+
def test_raises_if_file_not_found(self):
18+
with self.assertRaises(FileNotFoundError):
19+
load_string("/nonexistent/file/path.py")
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import json
2+
import unittest
3+
4+
from not_found_handler import ALLOWED_METHODS, not_found
5+
6+
7+
class TestNotFoundHandler(unittest.TestCase):
8+
"""Tests for the not_found_handler functionality"""
9+
10+
def test_method_not_allowed_unsupported_method(self):
11+
"""Test that unsupported HTTP methods return 405 Method Not Allowed"""
12+
event = {"httpMethod": "PATCH"}
13+
14+
response = not_found(event, None)
15+
16+
self.assertEqual(response["statusCode"], 405)
17+
self.assertEqual(response["headers"]["Content-Type"], "application/json")
18+
self.assertEqual(response["headers"]["Allow"], "GET, POST, DELETE, PUT")
19+
20+
# Verify the response body structure
21+
body = json.loads(response["body"])
22+
self.assertEqual(body["resourceType"], "OperationOutcome")
23+
self.assertEqual(body["issue"][0]["severity"], "error")
24+
self.assertEqual(body["issue"][0]["code"], "not-supported")
25+
self.assertEqual(body["issue"][0]["diagnostics"], "Method Not Allowed")
26+
27+
def test_method_not_allowed_other_unsupported_method(self):
28+
"""Test that other unsupported HTTP methods also return 405"""
29+
unsupported_methods = ["PUTT", "PATCH", "HEAD", "OPTIONS", "TRACE", "CONNECT"]
30+
31+
for method in unsupported_methods:
32+
with self.subTest(method=method):
33+
event = {"httpMethod": method}
34+
response = not_found(event, None)
35+
36+
self.assertEqual(response["statusCode"], 405)
37+
self.assertEqual(response["headers"]["Allow"], "GET, POST, DELETE, PUT")
38+
39+
def test_not_found_allowed_method(self):
40+
"""Test that allowed HTTP methods return 404 Not Found"""
41+
allowed_methods = ALLOWED_METHODS # ["GET", "POST", "DELETE", "PUT"]
42+
43+
for method in allowed_methods:
44+
with self.subTest(method=method):
45+
event = {"httpMethod": method}
46+
response = not_found(event, None)
47+
48+
self.assertEqual(response["statusCode"], 404)
49+
self.assertEqual(response["headers"]["Content-Type"], "application/json")
50+
self.assertNotIn("Allow", response["headers"]) # No Allow header for 404
51+
52+
# Verify the response body structure
53+
body = json.loads(response["body"])
54+
self.assertEqual(body["resourceType"], "OperationOutcome")
55+
self.assertEqual(body["issue"][0]["severity"], "error")
56+
self.assertEqual(body["issue"][0]["code"], "not-found")
57+
self.assertEqual(body["issue"][0]["diagnostics"], "The requested resource was not found.")
58+
59+
def test_not_found_missing_http_method(self):
60+
"""Test that missing httpMethod defaults to 405 Method Not Allowed"""
61+
event = {}
62+
63+
response = not_found(event, None)
64+
65+
self.assertEqual(response["statusCode"], 405)
66+
self.assertEqual(response["headers"]["Content-Type"], "application/json")
67+
self.assertEqual(response["headers"]["Allow"], "GET, POST, DELETE, PUT")
68+
69+
def test_not_found_none_http_method(self):
70+
"""Test that None httpMethod defaults to 405 Method Not Allowed"""
71+
event = {"httpMethod": None}
72+
73+
response = not_found(event, None)
74+
75+
self.assertEqual(response["statusCode"], 405)
76+
self.assertEqual(response["headers"]["Content-Type"], "application/json")
77+
self.assertEqual(response["headers"]["Allow"], "GET, POST, DELETE, PUT")
78+
79+
def test_allowed_methods_constant(self):
80+
"""Test that ALLOWED_METHODS contains the expected HTTP methods"""
81+
expected_methods = ["GET", "POST", "DELETE", "PUT"]
82+
self.assertEqual(ALLOWED_METHODS, expected_methods)
83+
84+
85+
if __name__ == "__main__":
86+
unittest.main()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import unittest
2+
from unittest.mock import patch
3+
4+
from timer import timed
5+
6+
7+
class TestTimedDecorator(unittest.TestCase):
8+
@patch("timer.time")
9+
@patch("timer.logger")
10+
def test_timed_logs_correct_execution_time(self, mock_logger, mock_time):
11+
mock_time.time.side_effect = [1000.0, 1000.12345]
12+
13+
@timed
14+
def sample_function():
15+
return "success"
16+
17+
result = sample_function()
18+
19+
self.assertEqual(result, "success")
20+
mock_logger.info.assert_called_once_with({"time_taken": "sample_function ran in 0.12345s"})
21+
22+
@patch("timer.time")
23+
@patch("timer.logger")
24+
def test_timed_preserves_function_name(self, mock_logger, mock_time):
25+
mock_time.time.side_effect = [0.0, 0.0]
26+
27+
@timed
28+
def my_named_function():
29+
pass
30+
31+
my_named_function()
32+
33+
logged_payload = mock_logger.info.call_args[0][0]
34+
self.assertIn("my_named_function", logged_payload["time_taken"])

0 commit comments

Comments
 (0)