Skip to content

Commit 0195d30

Browse files
Merge pull request #34 from ISE-GenAI-TechX25-Section-D/working
Created tests for display_genai_advice function
2 parents 0d4432d + aed2b3f commit 0195d30

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

app.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def display_app_page():
2727
display_activity_summary(get_user_workouts(userId))
2828
with genai_advice:
2929
display_genai_advice(get_genai_advice(userId)['timestamp'],get_genai_advice(userId)['content'],get_genai_advice(userId)['image'] )
30-
31-
32-
30+
3331
# This is the starting point for your app. You do not need to change these lines
3432
if __name__ == '__main__':
3533
display_app_page()

modules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def display_recent_workouts(workouts_list):
204204

205205

206206
def display_genai_advice(timestamp, content, image):
207+
import streamlit as sl
207208
"""
208209
Description: Displays advice developed by the AI model along with a related image.
209210
Input: A timestamp, content, and image.

modules_test.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,52 @@ def test_progress_bar(self):
201201
self.assertEqual(test_progress_bar_amount, self.app.session_state.weekly_calorie_progress_amount)
202202

203203

204-
class TestDisplayGenAiAdvice(unittest.TestCase):
205-
"""Tests the display_genai_advice function."""
206204

207-
def test_foo(self):
208-
"""Tests foo."""
209-
pass
205+
class TestDisplayGenAIAdvice(unittest.TestCase):
206+
"""Tests the display_genai_advice function using Streamlit's AppTest."""
207+
208+
209+
def setUp(self):
210+
"""Set up the AppTest environment with test input values."""
211+
self.test_timestamp = "2024-03-07 12:00:00"
212+
self.test_content = "Stay hydrated and take breaks between workouts."
213+
self.test_image = "https://www.google.com/imgres?q=picture%20of%20water&imgurl=https%3A%2F%2Fmedia.istockphoto.com%2Fid%2F491962870%2Fphoto%2Fmineral-water-is-being-poured-into-glass.jpg%3Fs%3D612x612%26w%3D0%26k%3D20%26c%3DSyuhabOpDKyVo78GtFcOi_7j6r5e4BYMtZFQtDdC7UE%3D&imgrefurl=https%3A%2F%2Fwww.istockphoto.com%2Fphotos%2Fpure-water&docid=5s6c7T7yGr9fbM&tbnid=rHwc6oimw3j6SM&vet=12ahUKEwjwvrTloPmLAxW5M9AFHRRQEB8QM3oECBgQAA..i&w=612&h=459&hcb=2&ved=2ahUKEwjwvrTloPmLAxW5M9AFHRRQEB8QM3oECBgQAA"
214+
215+
self.app = AppTest.from_function(
216+
display_genai_advice,
217+
kwargs={
218+
"timestamp": self.test_timestamp,
219+
"content": self.test_content,
220+
"image": self.test_image
221+
}
222+
)
223+
224+
self.app.run() # Run the app to apply testing
225+
226+
def test_title_existence(self):
227+
"""Check if the title is present."""
228+
title_elements = [el.value for el in self.app.title]
229+
230+
# Check for title
231+
found_title = any("AI Fitness Coach" in text for text in title_elements)
232+
self.assertTrue(found_title, "Title 'AI Fitness Coach title' not found!")
233+
234+
def test_subheader_existence(self):
235+
"""Check if the subheader is present."""
236+
subheader_elements = [el.value for el in self.app.subheader]
237+
self.assertTrue(any("Personalized advice based on your activities" in text for text in subheader_elements),
238+
"Subheader 'Personalized advice based on your activities' not found!")
239+
240+
def test_markdown_content(self):
241+
"""Check if the content is correctly displayed."""
242+
markdown_elements = [el.value for el in self.app.markdown]
243+
self.assertIn(self.test_content, markdown_elements, "Advice content not displayed correctly!")
244+
245+
def test_timestamp_display(self):
246+
"""Check if the timestamp is correctly displayed."""
247+
markdown_elements = [el.value for el in self.app.markdown]
248+
expected_timestamp_text = f"Last updated: {self.test_timestamp}"
249+
self.assertIn(expected_timestamp_text, markdown_elements, "Timestamp not displayed correctly!")
210250

211251

212252
class TestDisplayRecentWorkouts(unittest.TestCase):

0 commit comments

Comments
 (0)