@@ -20,9 +20,10 @@ def setUp(self, mock_configure, mock_model):
20
20
self .transcript_text = "This is a test transcript."
21
21
22
22
def test_initialization_with_key (self ):
23
- with patch ("src.app.gemini_ai.genai.configure" ) as mock_configure , \
24
- patch ("src.app.gemini_ai.genai.GenerativeModel" ) as mock_model :
25
-
23
+ with patch ("src.app.gemini_ai.genai.configure" ) as mock_configure , patch (
24
+ "src.app.gemini_ai.genai.GenerativeModel"
25
+ ) as mock_model :
26
+
26
27
gemini_ai = GeminiAI (api_key = "test_key" )
27
28
mock_configure .assert_called_once_with (api_key = "test_key" )
28
29
mock_model .assert_called_once_with ("gemini-1.5-flash" )
@@ -42,14 +43,14 @@ def test_generate_summary_success(self):
42
43
mock_response = MagicMock ()
43
44
mock_response .text = "This is a summary."
44
45
self .mock_model_instance .generate_content .return_value = mock_response
45
-
46
+
46
47
summary = self .gemini_ai .generate_summary (self .transcript_text )
47
48
self .assertEqual (summary , "This is a summary." )
48
49
self .mock_model_instance .generate_content .assert_called_once ()
49
50
50
51
def test_generate_summary_failure (self ):
51
52
self .mock_model_instance .generate_content .side_effect = Exception ("API Error" )
52
-
53
+
53
54
summary = self .gemini_ai .generate_summary (self .transcript_text )
54
55
self .assertIn ("Error generating summary" , summary )
55
56
self .assertIn ("API Error" , summary )
@@ -58,90 +59,90 @@ def test_extract_key_quotes_success(self):
58
59
mock_response = MagicMock ()
59
60
mock_response .text = "These are key quotes."
60
61
self .mock_model_instance .generate_content .return_value = mock_response
61
-
62
+
62
63
quotes = self .gemini_ai .extract_key_quotes (self .transcript_text )
63
64
self .assertEqual (quotes , "These are key quotes." )
64
65
65
66
def test_extract_key_quotes_failure (self ):
66
67
self .mock_model_instance .generate_content .side_effect = Exception ("API Error" )
67
-
68
+
68
69
quotes = self .gemini_ai .extract_key_quotes (self .transcript_text )
69
70
self .assertIn ("Error extracting quotes" , quotes )
70
71
71
72
def test_create_study_guide_success (self ):
72
73
mock_response = MagicMock ()
73
74
mock_response .text = "This is a study guide."
74
75
self .mock_model_instance .generate_content .return_value = mock_response
75
-
76
+
76
77
study_guide = self .gemini_ai .create_study_guide (self .transcript_text )
77
78
self .assertEqual (study_guide , "This is a study guide." )
78
79
79
80
def test_create_study_guide_failure (self ):
80
81
self .mock_model_instance .generate_content .side_effect = Exception ("API Error" )
81
-
82
+
82
83
study_guide = self .gemini_ai .create_study_guide (self .transcript_text )
83
84
self .assertIn ("Error creating study guide" , study_guide )
84
85
85
86
def test_generate_qa_success (self ):
86
87
mock_response = MagicMock ()
87
88
mock_response .text = "Q: Test question?\n A: Test answer."
88
89
self .mock_model_instance .generate_content .return_value = mock_response
89
-
90
+
90
91
qa = self .gemini_ai .generate_qa (self .transcript_text )
91
92
self .assertEqual (qa , "Q: Test question?\n A: Test answer." )
92
93
93
94
def test_generate_qa_failure (self ):
94
95
self .mock_model_instance .generate_content .side_effect = Exception ("API Error" )
95
-
96
+
96
97
qa = self .gemini_ai .generate_qa (self .transcript_text )
97
98
self .assertIn ("Error generating Q&A" , qa )
98
99
99
100
def test_create_flashcards_success (self ):
100
101
mock_response = MagicMock ()
101
102
mock_response .text = "FRONT: Test term\n BACK: Test definition\n ---"
102
103
self .mock_model_instance .generate_content .return_value = mock_response
103
-
104
+
104
105
flashcards = self .gemini_ai .create_flashcards (self .transcript_text )
105
106
self .assertEqual (flashcards , "FRONT: Test term\n BACK: Test definition\n ---" )
106
107
107
108
def test_create_flashcards_failure (self ):
108
109
self .mock_model_instance .generate_content .side_effect = Exception ("API Error" )
109
-
110
+
110
111
flashcards = self .gemini_ai .create_flashcards (self .transcript_text )
111
112
self .assertIn ("Error creating flashcards" , flashcards )
112
113
113
114
def test_highlight_insights_success (self ):
114
115
mock_response = MagicMock ()
115
116
mock_response .text = "🔍 Key Insights: Test insights"
116
117
self .mock_model_instance .generate_content .return_value = mock_response
117
-
118
+
118
119
insights = self .gemini_ai .highlight_insights (self .transcript_text )
119
120
self .assertEqual (insights , "🔍 Key Insights: Test insights" )
120
121
121
122
def test_highlight_insights_failure (self ):
122
123
self .mock_model_instance .generate_content .side_effect = Exception ("API Error" )
123
-
124
+
124
125
insights = self .gemini_ai .highlight_insights (self .transcript_text )
125
126
self .assertIn ("Error extracting insights" , insights )
126
127
127
128
def test_chat_with_transcript_success (self ):
128
129
mock_response = MagicMock ()
129
130
mock_response .text = "This is an answer."
130
131
self .mock_model_instance .generate_content .return_value = mock_response
131
-
132
+
132
133
answer = self .gemini_ai .chat_with_transcript (
133
134
self .transcript_text , "What is this?"
134
135
)
135
136
self .assertEqual (answer , "This is an answer." )
136
137
137
138
def test_chat_with_transcript_failure (self ):
138
139
self .mock_model_instance .generate_content .side_effect = Exception ("API Error" )
139
-
140
+
140
141
answer = self .gemini_ai .chat_with_transcript (
141
142
self .transcript_text , "What is this?"
142
143
)
143
144
self .assertIn ("Error in chat" , answer )
144
145
145
146
146
147
if __name__ == "__main__" :
147
- unittest .main ()
148
+ unittest .main ()
0 commit comments