| Server IP : 3.147.158.171 / Your IP : 216.73.216.88 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/api/tests/unit/ |
Upload File : |
import unittest
from datetime import datetime
from app.services.chat import ChatService
class TestDateRecency(unittest.TestCase):
def setUp(self):
self.cs = ChatService()
self.today = datetime(2025, 12, 4)
def test_today(self):
result = self.cs._calculate_date_recency('2025-12-04', self.today)
self.assertIn('TODAY', result)
self.assertIn('CURRENT EVENT', result)
def test_yesterday(self):
result = self.cs._calculate_date_recency('2025-12-03', self.today)
self.assertIn('yesterday', result)
self.assertIn('CURRENT EVENT', result)
def test_days_ago(self):
result = self.cs._calculate_date_recency('2025-11-30', self.today)
self.assertIn('days ago', result)
self.assertIn('CURRENT EVENT', result)
def test_weeks_ago(self):
result = self.cs._calculate_date_recency('2025-11-15', self.today)
self.assertIn('week', result)
self.assertIn('RECENT', result)
def test_months_ago(self):
result = self.cs._calculate_date_recency('2025-10-04', self.today)
self.assertIn('month', result)
self.assertNotIn('CURRENT EVENT', result)
def test_unknown_date(self):
result = self.cs._calculate_date_recency('Unknown date', self.today)
self.assertEqual(result, '')
def test_invalid_date(self):
result = self.cs._calculate_date_recency('invalid', self.today)
self.assertEqual(result, '')
def test_empty_date(self):
result = self.cs._calculate_date_recency('', self.today)
self.assertEqual(result, '')
def test_future_date(self):
result = self.cs._calculate_date_recency('2025-12-10', self.today)
self.assertIn('future date', result)
self.assertIn('6 days from now', result)
def test_two_weeks_ago(self):
result = self.cs._calculate_date_recency('2025-11-20', self.today)
self.assertIn('2 weeks ago', result)
self.assertIn('RECENT', result)
def test_three_months_ago(self):
result = self.cs._calculate_date_recency('2025-09-04', self.today)
self.assertIn('3 months ago', result)
self.assertNotIn('CURRENT EVENT', result)
self.assertNotIn('RECENT', result)
if __name__ == '__main__':
unittest.main()