Skip to content

Commit ac1cf9a

Browse files
committed
test: automate the main unit test
1 parent ed16715 commit ac1cf9a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

app/agent.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
User registration and management for Stackademy.
44
"""
55

6+
from typing import Optional, Tuple
7+
68
from .logging_config import get_logger, setup_logging
79
from .prompt import completion
810

@@ -11,15 +13,18 @@
1113
logger = get_logger(__name__)
1214

1315

14-
def main():
16+
def main(prompts: Optional[Tuple[str, ...]] = None) -> None:
1517
"""Main function to demonstrate user registration."""
18+
print("=" * 50)
1619
print("Stackademy User Registration Demo")
1720
print("=" * 50)
1821

19-
user_prompt = input("Welcome to Stackademy! How can I assist you today? ")
22+
i = 0
23+
user_prompt = prompts[i] if prompts else input("Welcome to Stackademy! How can I assist you today? ")
2024

2125
response, functions_called = completion(prompt=user_prompt)
2226
while response.choices[0].message.content != "Goodbye!":
27+
i += 1
2328
message = response.choices[0].message
2429
response_message = message.content or ""
2530
logger.info("ChatGPT: %s", response_message.strip())
@@ -34,9 +39,17 @@ def main():
3439
followup_question = None
3540

3641
if "get_courses" in functions_called:
37-
user_prompt = input(followup_question or "Would you like to register for a course? ")
42+
user_prompt = (
43+
prompts[i]
44+
if prompts and len(prompts) >= i
45+
else input(followup_question or "Would you like to register for a course? ")
46+
)
3847
elif "register_course" in functions_called:
39-
user_prompt = input(followup_question or "Can I help you with anything else? ")
48+
user_prompt = (
49+
prompts[i]
50+
if prompts and len(prompts) >= i
51+
else input(followup_question or "Can I help you with anything else? ")
52+
)
4053

4154
response, functions_called = completion(prompt=user_prompt)
4255

app/tests/test_application.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ def test_application_does_not_crash(self):
2626
"""Test that the application returns a value."""
2727

2828
# pylint: disable=broad-exception-caught
29+
prompts = (
30+
"Show me a list of available courses.",
31+
"I would like to register for the CS107 Algorithms course. My name is John Doe and my email is john.doe@example.com",
32+
"Thank you, that's all for now. Goodbye!",
33+
"Goodbye!",
34+
"Go away!",
35+
)
2936
try:
30-
main()
37+
main(prompts=prompts)
3138
except Exception as e:
3239
self.fail(f"main raised an exception: {e}")

0 commit comments

Comments
 (0)