Skip to content

Commit 801e057

Browse files
committed
Fix linting issues in hello function
1 parent e1ad082 commit 801e057

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

.github/workflows/pylint.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ on:
44
push:
55
paths:
66
- '**.py'
7-
branches:
8-
- main
97
pull_request:
108
paths:
119
- '**.py'
12-
branches:
13-
- main
1410

1511
jobs:
1612
analyze:

functions/hello/main.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
"""Main module for the hello function handler."""
2+
13
from crowdstrike.foundry.function import Function, Request, Response, APIError
24

3-
func = Function.instance()
5+
FUNC = Function.instance()
46

57

6-
# Handler hello
7-
@func.handler(method="POST", path="/hello")
8+
@FUNC.handler(method="POST", path="/hello")
89
def on_post(request: Request) -> Response:
10+
"""
11+
Handle POST requests to /hello endpoint.
12+
13+
Args:
14+
request: The incoming request object containing the request body.
15+
16+
Returns:
17+
Response: JSON response with greeting or error message.
18+
"""
919
#
1020
# Replace the following example code with your handler code
1121
#
@@ -29,4 +39,4 @@ def on_post(request: Request) -> Response:
2939

3040

3141
if __name__ == "__main__":
32-
func.run()
42+
FUNC.run()

functions/hello/test_main.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1+
"""Test module for the hello function handler."""
2+
3+
import importlib
14
import unittest
25
from unittest.mock import patch
36

7+
import main
48
from crowdstrike.foundry.function import Request
59

610

7-
def mock_handler(*args, **kwargs):
11+
def mock_handler(*_args, **_kwargs):
12+
"""Mock handler decorator for testing."""
813
def identity(func):
914
return func
1015

1116
return identity
1217

1318

1419
class FnTestCase(unittest.TestCase):
20+
"""Test case class for function handler tests."""
21+
1522
def setUp(self):
23+
"""Set up test fixtures before each test method."""
1624
patcher = patch("crowdstrike.foundry.function.Function.handler", new=mock_handler)
1725
self.addCleanup(patcher.stop)
1826
self.handler_patch = patcher.start()
1927

20-
import importlib
21-
import main
2228
importlib.reload(main)
2329

2430
def test_on_post_success(self):
31+
"""Test successful POST request with valid name in body."""
2532
from main import on_post
2633
request = Request()
2734
request.body = {
@@ -33,6 +40,7 @@ def test_on_post_success(self):
3340
self.assertEqual(response.body["greeting"], "Hello Test User! It is nice to see you.")
3441

3542
def test_on_post_missing_name(self):
43+
"""Test POST request with missing name in body returns error."""
3644
from main import on_post
3745
request = Request()
3846

0 commit comments

Comments
 (0)