Skip to content

Commit 802eaee

Browse files
committed
fix: tests should be more BDD-aligned
1 parent 86bd55a commit 802eaee

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

tests/features/feature_tests/api_features/functionality.feature

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ Feature: API Operation Testing
44
Given I start the API
55

66
Scenario: Access numeric endpoint
7-
When I send a request to "/v0/fizzbuzz?number=15"
7+
When I send a request to the fizzbuzz endpoint with value 15
88
Then the response is returned with status code 200
99
And the sequence contains 4 instances of "fizz"
1010
And the sequence contains 2 instances of "buzz"
1111
And the sequence contains 1 instances of "fizzbuzz"
1212

1313
Scenario: Invalid input raises error
14-
When I send a request to "/v0/fizzbuzz?number=0"
14+
When I send a request to the fizzbuzz endpoint with value 0
1515
Then the response is returned with status code 400
1616
And an error is raised with "number must a positive integer" in "message"
17-
18-
Scenario: Attempt non-existent route
19-
When I send a request to "/fake-endpoint"
20-
Then the response is returned with status code 404
21-
And an error is raised with "Not Found" in "detail"

tests/features/feature_tests/api_features/system.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Feature: Basic Configuration Testing
44
Given I start the API
55

66
Scenario: Access root endpoint
7-
When I send a request to "/"
7+
When I send a request to the index endpoint
88
Then the response is returned with status code 200
99
And the response JSON contains "message" in keys
1010

1111
Scenario: Access health-check endpoint
12-
When I send a request to "/healthz"
12+
When I send a request to the health-check endpoint
1313
Then the response is returned with status code 200
1414

1515
Scenario: Access metrics endpoint
16-
When I send a request to "/metrics"
16+
When I send a request to the metrics endpoint
1717
Then the response is returned with status code 200

tests/features/steps/api_steps.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
from typing import Dict
2+
13
from behave import given, then, when
24

35
from tests.features.stubs import TestContext
46

7+
ENDPOINT_MAP: Dict[str, str] = {
8+
"index": "/",
9+
"health-check": "/healthz",
10+
"service info": "/service-info",
11+
"metrics": "/metrics",
12+
}
13+
514

615
def __parse_keyword(keyword: str):
716
keyword = keyword.lower()
@@ -13,12 +22,23 @@ def __parse_keyword(keyword: str):
1322
@given("I start the API")
1423
def step_prelaunch_checks(context: TestContext):
1524
assert context.setup_complete, "Setup was not successful."
16-
assert context.response is None, "Response was not reset to None."
25+
assert context.response is None, "Response was not reset to null."
26+
27+
28+
@given("I send a request to the fizzbuzz endpoint with value {value:d}")
29+
@when("I send a request to the fizzbuzz endpoint with value {value:d}")
30+
def step_get_request(context: TestContext, value: int):
31+
endpoint = f"/v0/fizzbuzz?number={value}"
32+
context.response = context.mock_server.get(endpoint)
1733

1834

19-
@given('I send a request to "{endpoint:S}"')
20-
@when('I send a request to "{endpoint:S}"')
21-
def step_get_request(context: TestContext, endpoint: str):
35+
@given("I send a request to the {endpoint_name:S} endpoint")
36+
@when("I send a request to the {endpoint_name:S} endpoint")
37+
def step_get_request(context: TestContext, endpoint_name: str):
38+
assert (
39+
endpoint_name in ENDPOINT_MAP.keys()
40+
), f"Endpoint '{endpoint_name}' is not recognized."
41+
endpoint = ENDPOINT_MAP.get(endpoint_name)
2242
context.response = context.mock_server.get(endpoint)
2343

2444

0 commit comments

Comments
 (0)