diff --git a/src/ansari/app/main_api.py b/src/ansari/app/main_api.py index 7b1d2eb..63ac9c3 100644 --- a/src/ansari/app/main_api.py +++ b/src/ansari/app/main_api.py @@ -25,7 +25,7 @@ import psycopg2 import psycopg2.extras import sentry_sdk -from diskcache import FanoutCache, Lock +from diskcache import FanoutCache from fastapi import Depends, FastAPI, HTTPException, Request from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse, StreamingResponse @@ -43,7 +43,7 @@ from ansari.app.main_whatsapp import router as whatsapp_router from ansari.config import Settings, get_settings from ansari.presenters.api_presenter import ApiPresenter -from ansari.util.general_helpers import CORSMiddlewareWithLogging, get_extended_origins, validate_cors +from ansari.util.general_helpers import CORSMiddlewareWithLogging, get_extended_origins logger = get_logger(__name__) deployment_type = get_settings().DEPLOYMENT_TYPE diff --git a/test_ansari_claude.py b/test_ansari_claude.py index fe19cc4..fe00345 100644 --- a/test_ansari_claude.py +++ b/test_ansari_claude.py @@ -1,7 +1,5 @@ #\!/usr/bin/env python -import json -import os import sys from ansari.agents.ansari_claude import AnsariClaude diff --git a/tests/unit/test_citation_formatting.py b/tests/unit/test_citation_formatting.py index 17c7162..6d207f0 100644 --- a/tests/unit/test_citation_formatting.py +++ b/tests/unit/test_citation_formatting.py @@ -38,7 +38,8 @@ def test_quran_search_sleeplessness_citation_format(self, mock_run): { "id": "25:47", "text": "وَهُوَ ٱلَّذِى جَعَلَ لَكُمُ ٱلَّيْلَ لِبَاسًا وَٱلنَّوْمَ سُبَاتًا وَجَعَلَ ٱلنَّهَارَ نُشُورًا", - "en_text": "He is the One Who has made the night for you as a cover, and made sleep for resting, and the day for rising.", + "en_text": """He is the One Who has made the night for you as a cover, + and made sleep for resting, and the day for rising.""", }, {"id": "78:9", "text": "وَجَعَلْنَا نَوْمَكُمْ سُبَاتًا", "en_text": "and made your sleep for rest,"}, ] @@ -56,17 +57,17 @@ def test_quran_search_sleeplessness_citation_format(self, mock_run): self.assertIn("source", doc) self.assertIn("data", doc["source"]) data = doc["source"]["data"] - + # Verify data is valid JSON format try: parsed_data = json.loads(data) self.assertIsInstance(parsed_data, list) - + # Check that it contains language-text entries self.assertTrue(len(parsed_data) > 0) self.assertIn("lang", parsed_data[0]) self.assertIn("text", parsed_data[0]) - + # If we have an Arabic entry, verify it matches one of the mock texts for item in parsed_data: if item["lang"] == "ar": @@ -91,7 +92,8 @@ def test_hadith_search_day_of_judgment_citation_format(self, mock_run): "section_english": "The asking of Jibreel about Iman, Islam, Ihsan", "hadith_number": "50", "ar_text": "عَنْ أَبِي هُرَيْرَةَ، قَالَ كَانَ النَّبِيُّ صلى الله عليه وسلم بَارِزًا يَوْمًا لِلنَّاسِ...", - "en_text": 'Narrated Abu Huraira: One day while the Prophet (ﷺ) was sitting in the company of some people, (The angel) Gabriel came and asked, "What is faith?"...', + "en_text": """Narrated Abu Huraira: One day while the Prophet (ﷺ) was sitting in the company of some people, + (The angel) Gabriel came and asked, "What is faith?"...""", "grade_en": "Sahih-Authentic", }, { @@ -103,7 +105,8 @@ def test_hadith_search_day_of_judgment_citation_format(self, mock_run): "section_english": "Signs of the hour", "hadith_number": "4178", "ar_text": "قال رسول الله صلى الله عليه وسلم: لا تقوم الساعة حتى تكون عشر آيات...", - "en_text": "The Messenger of Allah (peace be upon him) said: The last hour will not come or happen until there appear ten signs before it...", + "en_text": """The Messenger of Allah (peace be upon him) said: + The last hour will not come or happen until there appear ten signs before it...""", "grade_en": "Sahih - Authentic", }, ] @@ -121,17 +124,17 @@ def test_hadith_search_day_of_judgment_citation_format(self, mock_run): self.assertIn("source", doc) self.assertIn("data", doc["source"]) data = doc["source"]["data"] - + # Verify data is valid JSON format try: parsed_data = json.loads(data) self.assertIsInstance(parsed_data, list) - + # Check that it contains language-text entries self.assertTrue(len(parsed_data) > 0) self.assertIn("lang", parsed_data[0]) self.assertIn("text", parsed_data[0]) - + # Verify text content if we have Arabic or English entries for item in parsed_data: if item["lang"] == "ar": diff --git a/tests/unit/test_logging_regression.py b/tests/unit/test_logging_regression.py index e07807f..57db37d 100644 --- a/tests/unit/test_logging_regression.py +++ b/tests/unit/test_logging_regression.py @@ -25,7 +25,7 @@ def test_logging_changes_dont_break_basic_functionality(): claude = AnsariClaude.__new__(AnsariClaude) claude.settings = settings claude.message_logger = None - + # Set needed attributes that would normally be set in __init__ claude.tools = [] claude.tool_name_to_instance = {} @@ -37,26 +37,26 @@ def test_logging_changes_dont_break_basic_functionality(): claude.message_history = [ {"role": "user", "content": "Hello, world!"} ] - + # Mock the API response to avoid actual API calls claude.process_one_round = MagicMock(side_effect=lambda: []) - + # Add an assistant response claude.message_history.append({ - "role": "assistant", + "role": "assistant", "content": [{"type": "text", "text": "Hello! How can I help you today?"}] }) - + # Verify basic validation works - assert claude.validate_message(claude.message_history[-1]) == True - + assert claude.validate_message(claude.message_history[-1]) + # Test message logging works claude.message_logger = MagicMock() claude._log_message(claude.message_history[-1]) - + # Verify logger was called claude.message_logger.log.assert_called_once() - + print("Test passed - basic functionality works!")