1- import pytest
1+ import asyncio
2+ from unittest .mock import patch
23
3- pytest . importorskip ( "google.adk" )
4+ from feedback_agent . database import StudentDatabase
45
5- import os
6- from feedback_agent .agent import FeedbackSystem
76
8- @pytest .fixture
9- def system ():
10- # Use a temporary db for testing
11- db_path = "data/test_students.db"
12- if os .path .exists (db_path ):
13- os .remove (db_path )
14-
15- sys = FeedbackSystem (db_path = db_path )
16- yield sys
17-
18- if os .path .exists (db_path ):
19- os .remove (db_path )
7+ def test_full_flow_mocked (tmp_path ):
8+ import pytest
9+ pytest .importorskip ("google.adk" )
10+ db_path = tmp_path / "students.db"
11+ _ = StudentDatabase (str (db_path ))
2012
13+ def mock_run_agent (agent , prompt , image_path = None , image_bytes = None , session_state = None ):
14+ import json
2115
22-
23- def test_full_flow_mocked (system ):
24- from unittest .mock import patch
25- import json
26-
27- # Mock responses for different agents
28- def mock_run_agent (agent , prompt ):
2916 if "grading_agent" in agent .name :
3017 return json .dumps ({
3118 "total_score" : 8 ,
@@ -52,43 +39,73 @@ def mock_run_agent(agent, prompt):
5239 })
5340 elif "analysis_agent" in agent .name :
5441 return json .dumps ({
55- "weaknesses" : ["Arithmetic" ],
42+ "topics" : ["Arithmetic" ],
43+ "weaknesses" : [
44+ {"topic" : "Arithmetic" , "description" : "Struggled with subtraction" , "severity" : "medium" }
45+ ],
5646 "summary" : "Weak in math."
5747 })
58- elif "recommendation_agent" in agent .name :
48+ elif "study_materials_agent" in agent .name :
49+ return json .dumps ({
50+ "study_materials" : [
51+ {"topic" : "Arithmetic" , "resources" : [{"type" : "textbook" , "title" : "Math 101" , "description" : "Basics" , "difficulty" : "beginner" }]}
52+ ]
53+ })
54+ elif "practice_problems_agent" in agent .name :
55+ return json .dumps ({
56+ "practice_problems" : [
57+ {"topic" : "Arithmetic" , "problems" : [{"difficulty" : "easy" , "problem" : "2+2" , "hint" : "Add" , "learning_goal" : "Addition" }]}
58+ ]
59+ })
60+ elif "learning_strategy_agent" in agent .name :
61+ return json .dumps ({
62+ "learning_strategy" : {
63+ "study_schedule" : {"weekly_hours" : 2 , "sessions_per_week" : 2 , "session_duration" : "30m" },
64+ "learning_techniques" : [{"technique" : "Flashcards" , "when_to_use" : "Daily" , "expected_benefit" : "Recall" }],
65+ "milestones" : [{"timeline" : "1 week" , "goal" : "Basics" , "success_criteria" : "80% correct" }]
66+ }
67+ })
68+ elif "recommendation_synthesizer" in agent .name :
5969 return json .dumps ({
6070 "learning_objectives" : [
6171 {
62- "topic" : "Arithmetic" ,
6372 "objective" : "Learn addition" ,
64- "resources" : ["Math book" ]
73+ "resources" : ["Math 101" ],
74+ "practice_activities" : ["2+2" ],
75+ "estimated_time" : "1 week" ,
76+ "priority" : "high"
6577 }
6678 ],
67- "encouragement" : "Keep practicing!"
79+ "weekly_plan" : {
80+ "total_hours" : 2 ,
81+ "activities" : [{"day" : "Mon" , "activity" : "Practice" , "duration" : "30m" , "resources_needed" : ["Math 101" ]}]
82+ },
83+ "encouragement" : "Keep practicing!" ,
84+ "success_metrics" : ["80% on quizzes" ]
6885 })
6986 return "{}"
7087
71- with patch ('feedback_agent.utils.run_agent' , side_effect = mock_run_agent ):
72- # 1. Register Student
88+ with patch ("feedback_agent.agent.run_agent" , side_effect = mock_run_agent , create = True ):
89+ from feedback_agent .agent import FeedbackSystem
90+
91+ system = FeedbackSystem (
92+ db_path = str (db_path ),
93+ use_memory_sessions = True ,
94+ enable_metrics = False ,
95+ enable_logging_plugin = False ,
96+ )
97+
7398 student_id = system .register_student ("Alice" )
7499 assert student_id is not None
75100
76- # 2. Process Exam
77- exam_content = "..."
78- answer_key = "..."
79-
80- result = system .process_exam (student_id , "General Knowledge" , exam_content , answer_key )
81-
82- # Verify Grading
83- assert result ['grading' ]['total_score' ] == 8
84-
85- # Verify Analysis
86- assert "Arithmetic" in result ['analysis' ]['weaknesses' ]
87-
88- # Verify Recommendations
89- assert len (result ['recommendations' ]['learning_objectives' ]) > 0
101+ result = asyncio .run (
102+ system .process_exam (student_id , "..." , "..." , "General Knowledge" )
103+ )
104+
105+ assert result ["total_score" ] == 8
106+ assert "Arithmetic" in result ["weaknesses" ][0 ]["topic" ]
107+ assert result ["recommendations" ]
90108
91- # Verify DB Persistence
92109 history = system .db .get_student_history (student_id )
93110 assert len (history ) == 1
94- assert history [0 ][' subject' ] == "General Knowledge"
111+ assert history [0 ][" subject" ] == "General Knowledge"
0 commit comments