Skip to content

Commit

Permalink
Create test_session_tracking.py
Browse files Browse the repository at this point in the history
test session tracking

Signed-off-by: Josef Edwards <joed6834@colorado.edu>
  • Loading branch information
bearycool11 authored Nov 11, 2024
1 parent ec9290c commit f9119f2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test_session_tracking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
from session_tracking import get_db_connection, create_sessions_table, insert_session_data, retrieve_session_data

class TestSessionTracking(unittest.TestCase):

def setUp(self):
"""Shared setup method to initialize the database and table."""
self.conn = get_db_connection()
self.cursor = self.conn.cursor()
create_sessions_table(self.cursor)

def tearDown(self):
"""Clean up method to delete data after each test."""
self.cursor.execute('DELETE FROM sessions')
self.conn.commit()

def test_create_sessions_table(self):
"""Test if the sessions table is created."""
self.assertTrue(self.cursor.execute('SELECT * FROM sessions').fetchone() is None)

def test_insert_session_data(self):
"""Test if session data is inserted correctly."""
insert_session_data(self.cursor, 1, 'reset_context=False, check_flags=False', 'Started the conversation with some context.', '2023-03-01 12:00:00')
self.assertTrue(self.cursor.execute('SELECT * FROM sessions').fetchone() is not None)

def test_retrieve_session_data(self):
"""Test if session data is retrieved correctly."""
insert_session_data(self.cursor, 1, 'reset_context=False, check_flags=False', 'Started the conversation with some context.', '2023-03-01 12:00:00')
session_data = retrieve_session_data(self.cursor, 1)
self.assertEqual(session_data[0], 'reset_context=False, check_flags=False')
self.assertEqual(session_data[1], 'Started the conversation with some context.')

def test_retrieve_non_existent_session(self):
"""Test retrieving a session that doesn't exist."""
session_data = retrieve_session_data(self.cursor, 999) # assuming 999 is an invalid ID
self.assertIsNone(session_data)

if __name__ == '__main__':
unittest.main()

0 comments on commit f9119f2

Please sign in to comment.