Skip to content

Commit

Permalink
fix tests once again
Browse files Browse the repository at this point in the history
  • Loading branch information
AditiR-42 committed Dec 12, 2024
1 parent a244460 commit ae8f58d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/api_service/api/routers/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# In-memory storage for extracted issues
parsed_issues_storage = {"issues": []}

@router.post("/summarize/process-pdf/")
@router.post("/process-pdf/")
async def process_pdf(
pdf_file: UploadFile = File(...),
project_id: str = "473358048261",
Expand Down Expand Up @@ -58,7 +58,7 @@ async def process_pdf(
raise HTTPException(status_code=500, detail=f"Error processing file: {str(e)}")


@router.post("/summarize/get-grade/")
@router.post("/get-grade/")
async def get_grade():
"""
Grade the parsed privacy issues.
Expand Down
28 changes: 14 additions & 14 deletions src/models/tests/integration/test_api_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_process_pdf_endpoint(mock_post):

# Simulate a file upload
files = {"pdf_file": ("mock.pdf", b"PDF content", "application/pdf")}
response = httpx.post(f"{BASE_URL}/summarize/process-pdf", files=files)
response = httpx.post(f"{BASE_URL}/process-pdf/", files=files)

# Assertions
assert response.status_code == 200
Expand All @@ -57,7 +57,7 @@ def test_get_grade_endpoint(mock_post):
mock_response.json.return_value = {"grade": "A"}
mock_post.return_value = mock_response

response = httpx.post(f"{BASE_URL}/summarize/get-grade", json={"input": "test data"})
response = httpx.post(f"{BASE_URL}/get-grade/", json={"input": "test data"})

assert response.status_code == 200
assert response.json() == {"grade": "A"}
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_get_grade_invalid_payload(mock_post):
mock_response.json.return_value = {"error": "Invalid data format"}
mock_post.return_value = mock_response

response = httpx.post(f"{BASE_URL}/summarize/get-grade", json={"invalid": "data"})
response = httpx.post(f"{BASE_URL}/get-grade/", json={"invalid": "data"})
assert response.status_code == 422
assert response.json() == {"error": "Invalid data format"}

Expand All @@ -103,7 +103,7 @@ def test_get_grade_invalid_payload(mock_post):
mock_response.json.return_value = {"error": "Invalid data format"}
mock_post.return_value = mock_response

response = httpx.post(f"{BASE_URL}/summarize/get-grade", json={"invalid": "data"})
response = httpx.post(f"{BASE_URL}/get-grade/", json={"invalid": "data"})
assert response.status_code == 422
assert response.json() == {"error": "Invalid data format"}

Expand All @@ -116,7 +116,7 @@ def test_process_pdf_invalid_file(mock_post):
mock_post.return_value = mock_response

files = {"pdf_file": ("invalid.txt", b"Text content", "text/plain")}
response = httpx.post(f"{BASE_URL}/summarize/process-pdf", files=files)
response = httpx.post(f"{BASE_URL}/process-pdf/", files=files)

assert response.status_code == 400
assert response.json() == {"error": "Invalid file type"}
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_process_pdf_invalid_project_id(mock_post):

files = {"pdf_file": ("mock.pdf", b"PDF content", "application/pdf")}
response = httpx.post(
f"{BASE_URL}/summarize/process-pdf",
f"{BASE_URL}/process-pdf/",
files=files,
data={"project_id": "invalid_project", "location_id": "us-central1", "endpoint_id": "3504346967373250560"}
)
Expand All @@ -186,7 +186,7 @@ def test_process_pdf_empty_file(mock_post):
mock_post.return_value = mock_response

files = {"pdf_file": ("empty.pdf", b"", "application/pdf")}
response = httpx.post(f"{BASE_URL}/summarize/process-pdf", files=files)
response = httpx.post(f"{BASE_URL}/process-pdf/", files=files)

assert response.status_code == 400
assert response.json() == {"detail": "A valid PDF file is required."}
Expand All @@ -201,7 +201,7 @@ def test_get_grade_missing_issues(mock_post):
}
mock_post.return_value = mock_response

response = httpx.post(f"{BASE_URL}/summarize/get-grade")
response = httpx.post(f"{BASE_URL}/get-grade/")
assert response.status_code == 400
assert response.json() == {
"detail": "No issues have been processed yet. Please process a PDF first."
Expand All @@ -215,7 +215,7 @@ def test_get_grade_invalid_grading_logic(mock_post):
mock_response.json.return_value = {"detail": "Error grading issues: Invalid data"}
mock_post.return_value = mock_response

response = httpx.post(f"{BASE_URL}/summarize/get-grade")
response = httpx.post(f"{BASE_URL}/get-grade/")
assert response.status_code == 500
assert response.json() == {"detail": "Error grading issues: Invalid data"}

Expand Down Expand Up @@ -276,7 +276,7 @@ def test_process_pdf_processing_error(mock_post):
mock_post.return_value = mock_response

files = {"pdf_file": ("mock.pdf", b"PDF content", "application/pdf")}
response = httpx.post(f"{BASE_URL}/summarize/process-pdf", files=files)
response = httpx.post(f"{BASE_URL}/process-pdf/", files=files)
assert response.status_code == 500
assert response.json() == {"detail": "Error processing file: Unexpected error"}

Expand All @@ -289,7 +289,7 @@ def test_process_pdf_invalid_extension(mock_post):
mock_post.return_value = mock_response

files = {"pdf_file": ("invalid.txt", b"Not a PDF", "text/plain")}
response = httpx.post(f"{BASE_URL}/summarize/process-pdf", files=files)
response = httpx.post(f"{BASE_URL}/process-pdf/", files=files)

assert response.status_code == 400
assert response.json() == {"detail": "A valid PDF file is required."}
Expand All @@ -302,7 +302,7 @@ def test_process_pdf_no_file(mock_post):
mock_response.json.return_value = {"detail": "Missing file"}
mock_post.return_value = mock_response

response = httpx.post(f"{BASE_URL}/summarize/process-pdf", files={})
response = httpx.post(f"{BASE_URL}/process-pdf/", files={})
assert response.status_code == 422
assert response.json() == {"detail": "Missing file"}

Expand All @@ -314,7 +314,7 @@ def test_get_grade_empty_storage(mock_post):
mock_response.json.return_value = {"detail": "No issues have been processed yet."}
mock_post.return_value = mock_response

response = httpx.post(f"{BASE_URL}/summarize/get-grade")
response = httpx.post(f"{BASE_URL}/get-grade/")
assert response.status_code == 400
assert response.json() == {"detail": "No issues have been processed yet."}

Expand Down Expand Up @@ -422,7 +422,7 @@ def test_summarize_endpoint_valid_payload(mock_post):
response = httpx.post(f"{BASE_URL}/summarize", json=payload)
# Assertions
assert response.status_code == 200
assert response.json() == {"summary": "This is a summarized text"}
assert response.json() == {"summary": "This is a summarized text."}

@patch("httpx.post")
def test_summarize_endpoint_empty_payload(mock_post):
Expand Down

0 comments on commit ae8f58d

Please sign in to comment.