|
| 1 | +import os |
| 2 | +from unittest.mock import AsyncMock |
| 3 | + |
| 4 | +import pytest |
| 5 | +from dotenv import load_dotenv |
| 6 | +from nutrient_dws import NutrientClient |
| 7 | +from tests.helpers import TestDocumentGenerator |
| 8 | + |
| 9 | +load_dotenv() # Load environment variables |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +def mock_workflow_instance(): |
| 13 | + """Create a mock workflow instance for testing.""" |
| 14 | + mock_output_stage = AsyncMock() |
| 15 | + mock_output_stage.execute.return_value = { |
| 16 | + "success": True, |
| 17 | + "output": { |
| 18 | + "buffer": b"test-buffer", |
| 19 | + "mimeType": "application/pdf", |
| 20 | + "filename": "output.pdf", |
| 21 | + }, |
| 22 | + } |
| 23 | + mock_output_stage.dry_run.return_value = {"success": True} |
| 24 | + |
| 25 | + mock_workflow = AsyncMock() |
| 26 | + mock_workflow.add_file_part.return_value = mock_workflow |
| 27 | + mock_workflow.add_html_part.return_value = mock_workflow |
| 28 | + mock_workflow.add_new_page.return_value = mock_workflow |
| 29 | + mock_workflow.add_document_part.return_value = mock_workflow |
| 30 | + mock_workflow.apply_actions.return_value = mock_workflow |
| 31 | + mock_workflow.apply_action.return_value = mock_workflow |
| 32 | + mock_workflow.output_pdf.return_value = mock_output_stage |
| 33 | + mock_workflow.output_pdfa.return_value = mock_output_stage |
| 34 | + mock_workflow.output_pdfua.return_value = mock_output_stage |
| 35 | + mock_workflow.output_image.return_value = mock_output_stage |
| 36 | + mock_workflow.output_office.return_value = mock_output_stage |
| 37 | + mock_workflow.output_html.return_value = mock_output_stage |
| 38 | + mock_workflow.output_markdown.return_value = mock_output_stage |
| 39 | + mock_workflow.output_json.return_value = mock_output_stage |
| 40 | + |
| 41 | + return mock_workflow |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture |
| 45 | +def valid_client_options(): |
| 46 | + """Valid client options for testing.""" |
| 47 | + return {"apiKey": "test-api-key", "baseUrl": "https://api.test.com/v1"} |
| 48 | + |
| 49 | +@pytest.fixture(scope="class") |
| 50 | +def client(): |
| 51 | + """Create client instance for testing.""" |
| 52 | + options = { |
| 53 | + "apiKey": os.getenv("NUTRIENT_API_KEY", ""), |
| 54 | + "baseUrl": os.getenv("NUTRIENT_BASE_URL", "https://api.nutrient.io"), |
| 55 | + } |
| 56 | + return NutrientClient(options) |
| 57 | + |
| 58 | + |
| 59 | +@pytest.fixture |
| 60 | +def test_table_pdf(): |
| 61 | + """Generate PDF with table for annotation tests.""" |
| 62 | + return TestDocumentGenerator.generate_pdf_with_table() |
| 63 | + |
| 64 | +@pytest.fixture |
| 65 | +def test_xfdf_content(): |
| 66 | + """Generate XFDF content for testing.""" |
| 67 | + return TestDocumentGenerator.generate_xfdf_content() |
| 68 | + |
| 69 | +@pytest.fixture |
| 70 | +def test_instant_json_content(): |
| 71 | + """Generate Instant JSON content for testing.""" |
| 72 | + return TestDocumentGenerator.generate_instant_json_content() |
| 73 | + |
| 74 | +@pytest.fixture |
| 75 | +def test_sensitive_pdf(): |
| 76 | + """Generate PDF with sensitive data for redaction testing.""" |
| 77 | + return TestDocumentGenerator.generate_pdf_with_sensitive_data() |
| 78 | + |
| 79 | +@pytest.fixture |
| 80 | +def test_html_content(): |
| 81 | + """Generate HTML content for testing.""" |
| 82 | + return TestDocumentGenerator.generate_html_content() |
0 commit comments