11from typing import Dict
22
3- from behave import given , then , when
3+ from behave import given , then , when # type: ignore
44
55from tests .features .stubs import TestContext
66
1515def __parse_keyword (keyword : str ):
1616 keyword = keyword .lower ()
1717 if keyword not in ("fizz" , "buzz" , "fizzbuzz" ):
18- raise ValueError (f"Invalid keyword" )
18+ raise AssertionError (f"Invalid keyword" )
1919 return keyword
2020
2121
@@ -38,24 +38,27 @@ def step_get_request(context: TestContext, endpoint_name: str):
3838 assert (
3939 endpoint_name in ENDPOINT_MAP .keys ()
4040 ), f"Endpoint '{ endpoint_name } ' is not recognized."
41- endpoint = ENDPOINT_MAP . get ( endpoint_name )
41+ endpoint = ENDPOINT_MAP [ endpoint_name ]
4242 context .response = context .mock_server .get (endpoint )
4343
4444
4545@then ("the response is returned with status code {status_code:d}" )
4646def step_evaluate_request_status (context : TestContext , status_code : int ):
47+ assert context .response is not None , "Last response was null"
4748 assert (
4849 context .response .status_code == status_code
4950 ), f"Expected status code { status_code } but got { context .response .status_code } "
5051
5152
5253@then ('the response JSON contains "{message:S}" in keys' )
5354def step_evaluate_response_message (context : TestContext , message : str ):
55+ assert context .response is not None , "Last response was null"
5456 assert message in context .response .json ()
5557
5658
5759@then ('the sequence contains {count:d} instances of "{word:S}"' )
5860def step_check_count (context : TestContext , count : int , word : str ):
61+ assert context .response is not None , "Last response was null"
5962 key = __parse_keyword (word )
6063 instance_count = context .response .json ()[key ]
6164 assert (
@@ -65,6 +68,7 @@ def step_check_count(context: TestContext, count: int, word: str):
6568
6669@then ('an error is raised with "{message}" in "{key:S}"' )
6770def step_check_error_output (context : TestContext , message : str , key : str ):
71+ assert context .response is not None , "Last response was null"
6872 response = context .response .json ()["message" ][key ]
6973 assert (
7074 message in response
0 commit comments