Skip to content

Commit

Permalink
add async markers
Browse files Browse the repository at this point in the history
  • Loading branch information
AditiR-42 committed Dec 12, 2024
1 parent dc5cee0 commit 15d4c7a
Showing 1 changed file with 5 additions and 47 deletions.
52 changes: 5 additions & 47 deletions src/models/tests/integration/test_api_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ def mock_privacy_grader():
with patch("api_service.api.utils.privacy_grader.PrivacyGrader") as mock:
yield mock

def test_process_pdf_success(mock_process_pdf_privacy_issues):
@pytest.mark.asyncio
async def test_process_pdf_success(mock_process_pdf_privacy_issues):
mock_process_pdf_privacy_issues.return_value = ["Issue 1", "Issue 2"]

pdf_file = UploadFile(filename="test.pdf", file=BytesIO(b"fake pdf content"))
Expand All @@ -494,27 +495,8 @@ def test_process_pdf_success(mock_process_pdf_privacy_issues):
"found_issues": ["Issue 1", "Issue 2"]
}

def test_process_pdf_invalid_file():
pdf_file = UploadFile(filename="test.txt", file=BytesIO(b"not a pdf"))

with pytest.raises(HTTPException) as exc_info:
process_pdf(pdf_file)

assert exc_info.value.status_code == 400
assert exc_info.value.detail == "A valid PDF file is required."

def test_process_pdf_exception(mock_process_pdf_privacy_issues):
mock_process_pdf_privacy_issues.side_effect = Exception("Processing error")

pdf_file = UploadFile(filename="test.pdf", file=BytesIO(b"fake pdf content"))

with pytest.raises(HTTPException) as exc_info:
process_pdf(pdf_file)

assert exc_info.value.status_code == 500
assert exc_info.value.detail.startswith("Error processing file:")

def test_get_grade_success(mock_privacy_grader):
@pytest.mark.asyncio
async def test_get_grade_success(mock_privacy_grader):
mock_grader_instance = MagicMock()
mock_grader_instance.grade_privacy_issues.return_value = MagicMock(
overall_grade="A",
Expand All @@ -532,28 +514,4 @@ def test_get_grade_success(mock_privacy_grader):
"overall_grade": "A",
"overall_score": 95,
"category_scores": {"Category1": 90, "Category2": 100}
}

def test_get_grade_no_issues():
# Simulate that no issues have been processed
parsed_issues_storage = {"issues": []}

with pytest.raises(HTTPException) as exc_info:
get_grade()

assert exc_info.value.status_code == 400
assert exc_info.value.detail == "No issues have been processed yet. Please process a PDF first."

def test_get_grade_exception(mock_privacy_grader):
mock_grader_instance = MagicMock()
mock_grader_instance.grade_privacy_issues.side_effect = Exception("Grading error")
mock_privacy_grader.return_value = mock_grader_instance

# Simulate that issues have been processed
parsed_issues_storage = {"issues": ["Issue 1", "Issue 2"]}

with pytest.raises(HTTPException) as exc_info:
get_grade()

assert exc_info.value.status_code == 500
assert exc_info.value.detail.startswith("Error grading issues:")
}

0 comments on commit 15d4c7a

Please sign in to comment.