99
1010# Corrected import for FakeAsyncRedis based on common usage and docs
1111from fakeredis import FakeAsyncRedis
12- from fastapi import Response
1312from fastapi .testclient import TestClient
1413from freezegun import freeze_time # For controlling time in tests
1514
@@ -540,17 +539,16 @@ def assert_suggestions_error_response(response, expected_status=422):
540539
541540@patch .dict (os .environ , {"SUGGESTIONS_API_KEY" : "valid-suggestions-key" })
542541@patch ("mxgo.auth.JWT_SECRET" , "test_secret_key_for_development_only" )
543- @patch ("mxgo.api.validate_email_whitelist" , new_callable = AsyncMock )
544542@patch ("mxgo.api.generate_suggestions" , new_callable = AsyncMock )
545- def test_suggestions_api_success_single_request (mock_generate_suggestions , mock_validate_whitelist ):
543+ def test_suggestions_api_success_single_request (mock_generate_suggestions ):
546544 """Test successful suggestions API call with single request."""
547- mock_validate_whitelist .return_value = None # User is whitelisted
548545
549546 # Mock the suggestions response
550547
551548 mock_response = EmailSuggestionResponse (
552549 email_identified = "test-email-123" ,
553550 user_email_id = "test@example.com" ,
551+ overview = "Test email requesting content summarization" ,
554552 suggestions = [
555553 SuggestionDetail (
556554 suggestion_title = "Summarize content" ,
@@ -574,7 +572,6 @@ def test_suggestions_api_success_single_request(mock_generate_suggestions, mock_
574572 response = make_suggestions_post_request (request_data )
575573
576574 assert_suggestions_successful_response (response , expected_num_requests = 1 )
577- mock_validate_whitelist .assert_called_once ()
578575 mock_generate_suggestions .assert_called_once ()
579576
580577 # Verify the response content
@@ -587,17 +584,16 @@ def test_suggestions_api_success_single_request(mock_generate_suggestions, mock_
587584
588585@patch .dict (os .environ , {"SUGGESTIONS_API_KEY" : "valid-suggestions-key" })
589586@patch ("mxgo.auth.JWT_SECRET" , "test_secret_key_for_development_only" )
590- @patch ("mxgo.api.validate_email_whitelist" , new_callable = AsyncMock )
591587@patch ("mxgo.api.generate_suggestions" , new_callable = AsyncMock )
592- def test_suggestions_api_success_multiple_requests (mock_generate_suggestions , mock_validate_whitelist ):
588+ def test_suggestions_api_success_multiple_requests (mock_generate_suggestions ):
593589 """Test successful suggestions API call with multiple requests."""
594- mock_validate_whitelist .return_value = None
595590
596591 # Mock responses for each request
597592 mock_responses = [
598593 EmailSuggestionResponse (
599594 email_identified = f"test-email-{ i } " ,
600595 user_email_id = "test@example.com" ,
596+ overview = f"Test email { i } overview" ,
601597 suggestions = [
602598 SuggestionDetail (
603599 suggestion_title = "Ask anything" ,
@@ -629,7 +625,6 @@ def test_suggestions_api_success_multiple_requests(mock_generate_suggestions, mo
629625 response = make_suggestions_post_request (request_data )
630626
631627 assert_suggestions_successful_response (response , expected_num_requests = 3 )
632- assert mock_validate_whitelist .call_count == 3
633628 assert mock_generate_suggestions .call_count == 3
634629
635630
@@ -655,22 +650,34 @@ def test_suggestions_api_invalid_jwt_token():
655650
656651@patch .dict (os .environ , {"SUGGESTIONS_API_KEY" : "valid-suggestions-key" })
657652@patch ("mxgo.auth.JWT_SECRET" , "test_secret_key_for_development_only" )
658- @patch ("mxgo.api.validate_email_whitelist" , new_callable = AsyncMock )
659- def test_suggestions_api_user_not_whitelisted (mock_validate_whitelist ):
660- """Test suggestions API when user is not whitelisted."""
661- # Mock whitelist validation to return an error response
662- mock_validate_whitelist .return_value = Response (
663- status_code = 403 , content = json .dumps ({"detail" : "User not whitelisted" })
653+ @patch ("mxgo.api.generate_suggestions" , new_callable = AsyncMock )
654+ def test_suggestions_api_user_not_whitelisted (mock_generate_suggestions ):
655+ """Test suggestions API processes normally since whitelist check was removed."""
656+ # Mock successful suggestions generation
657+ mock_response = EmailSuggestionResponse (
658+ email_identified = "test-email-123" ,
659+ user_email_id = "test@example.com" ,
660+ overview = "Test email processed without whitelist check" ,
661+ suggestions = [
662+ SuggestionDetail (
663+ suggestion_title = "Ask anything" ,
664+ suggestion_id = "suggest-1" ,
665+ suggestion_to_email = "ask@mxgo.ai" ,
666+ suggestion_cc_emails = [],
667+ suggestion_email_instructions = "" ,
668+ ),
669+ ],
664670 )
671+ mock_generate_suggestions .return_value = mock_response
665672
666673 request_data = prepare_suggestions_request_data ()
667674 response = make_suggestions_post_request (request_data )
668675
669- # Should return 403 Forbidden instead of 200 with error suggestions
670- assert response .status_code == 403 , "Should return 403 Forbidden for non-whitelisted user "
676+ # Should return 200 OK since whitelist validation was removed
677+ assert response .status_code == 200 , "Should return 200 OK since whitelist check removed "
671678 response_json = response .json ()
672- assert "detail" in response_json
673- assert "Email verification required" in response_json [ "detail" ]
679+ assert len ( response_json ) == 1
680+ assert response_json [ 0 ][ "email_identified" ] == "test-email-123"
674681
675682
676683@patch .dict (os .environ , {"SUGGESTIONS_API_KEY" : "valid-suggestions-key" })
@@ -728,6 +735,7 @@ def test_suggestions_api_with_attachments(mock_generate_suggestions, mock_valida
728735 mock_response = EmailSuggestionResponse (
729736 email_identified = "test-email-123" ,
730737 user_email_id = "test@example.com" ,
738+ overview = "Email with PDF and Excel attachments requiring document analysis" ,
731739 suggestions = [
732740 SuggestionDetail (
733741 suggestion_title = "Summarize documents" ,
@@ -778,6 +786,7 @@ def test_suggestions_api_with_cc_emails(mock_generate_suggestions, mock_validate
778786 mock_response = EmailSuggestionResponse (
779787 email_identified = "test-email-123" ,
780788 user_email_id = "test@example.com" ,
789+ overview = "Meeting request with CC recipients" ,
781790 suggestions = [
782791 SuggestionDetail (
783792 suggestion_title = "Schedule meeting" ,
@@ -824,6 +833,7 @@ def test_suggestions_api_rate_limiting_integration(client_with_patched_redis):
824833 mock_response = EmailSuggestionResponse (
825834 email_identified = "test-email-123" ,
826835 user_email_id = "test@example.com" ,
836+ overview = "Test email for rate limiting integration" ,
827837 suggestions = [
828838 SuggestionDetail (
829839 suggestion_title = "Ask anything" ,
@@ -851,6 +861,7 @@ def test_suggestions_api_subject_field_alias(mock_generate_suggestions, mock_val
851861 mock_response = EmailSuggestionResponse (
852862 email_identified = "test-email-123" ,
853863 user_email_id = "test@example.com" ,
864+ overview = "Test email with Subject field alias" ,
854865 suggestions = [
855866 SuggestionDetail (
856867 suggestion_title = "Ask anything" ,
@@ -886,6 +897,7 @@ def test_suggestions_api_default_suggestions_always_included(mock_generate_sugge
886897 mock_response = EmailSuggestionResponse (
887898 email_identified = "test-email-123" ,
888899 user_email_id = "test@example.com" ,
900+ overview = "Email with statistical claims requiring fact verification" ,
889901 suggestions = [
890902 SuggestionDetail (
891903 suggestion_title = "Fact check claims" ,
0 commit comments