Skip to content

Commit ecff4f5

Browse files
chore: apply tests and preview options
1 parent cc325f5 commit ecff4f5

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

app/evaluation_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TestEvaluationFunction(unittest.TestCase):
3232
def test_connection(self):
3333
id_connection = initialize_test_connection()
3434

35-
response, answer, params = id_connection, 0.0, {"api_endpoint": "resistance/"}
35+
response, answer, params = id_connection, id_connection, {"api_endpoint": "resistance/", "correct_answer": 0.0}
3636
result = evaluation_function(response, answer, params)
3737

3838
self.assertEqual(result.get("is_correct"), False)

app/preview.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
class Result(TypedDict):
88
preview: Any
99

10-
1110
def preview_function(response: Any, params: Any) -> Result:
1211
"""
1312
Function used to preview a student response.
1413
---
15-
The handler function passes three arguments to preview_function():
14+
The handler function passes two arguments to preview_function():
1615
1716
- `response` which are the answers provided by the student.
1817
- `params` which are any extra parameters that may be useful,
@@ -21,21 +20,18 @@ def preview_function(response: Any, params: Any) -> Result:
2120
The output of this function is what is returned as the API response
2221
and therefore must be JSON-encodable. It must also conform to the
2322
response schema.
24-
25-
Any standard python library may be used, as well as any package
26-
available on pip (provided it is added to requirements.txt).
27-
28-
The way you wish to structure you code (all in this function, or
29-
split into many) is entirely up to you.
3023
"""
3124
try:
3225
api_endpoint = params.get("api_endpoint", 'resistance/')
3326

27+
if len(response) != 6:
28+
raise Exception("Connection ID must be 6 characters long")
29+
3430
api_response = requests.get(f"{os.environ.get('API_CONNECTION')}/{api_endpoint}{response}")
3531
api_response.raise_for_status()
3632
api_data = api_response.json()
3733
except requests.RequestException as e:
3834
print(f"Error API connection: {e}")
3935
api_data = None
4036

41-
return Result(preview=api_data)
37+
return Result(preview=api_data)

app/preview_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class TestPreviewFunction(unittest.TestCase):
3030

3131
def test_api_endpoint_resistance(self):
3232
id_connection = initialize_test_connection()
33-
response, params = id_connection, {"api_endpoint": "resistance/"}
33+
response, params = id_connection, {"api_endpoint": "resistance/", "correct_answer": 0.0}
3434
result = preview_function(response, params)
3535

3636
self.assertIn("preview", result)
3737
self.assertIsNotNone(result["preview"])
3838

3939
def test_api_endpoint_resistors(self):
4040
id_connection = initialize_test_connection()
41-
response, params = id_connection, {"api_endpoint": "resistors/"}
41+
response, params = id_connection, {"api_endpoint": "resistors/", "correct_answer": 0.0}
4242
result = preview_function(response, params)
4343

4444
self.assertIn("preview", result)

0 commit comments

Comments
 (0)