Skip to content

Commit 2a230e7

Browse files
msch-nutrientclaude
andcommitted
Add integration test skeleton for live API testing
- Add integration_config.py template for API key configuration - Create test_live_api.py with basic connectivity tests and fixtures - Add conftest.py for integration test pytest configuration - Update .gitignore to exclude integration_config.py 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 20fd150 commit 2a230e7

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,6 @@ openapi_spec.yml
153153

154154
.pixi
155155
.claude/settings.local.json
156+
157+
# Integration test configuration
158+
tests/integration/integration_config.py

tests/integration/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Pytest configuration for integration tests."""
2+
3+
import pytest
4+
5+
6+
def pytest_configure(config):
7+
"""Configure pytest for integration tests."""
8+
# Add custom markers
9+
config.addinivalue_line(
10+
"markers", "integration: marks tests as integration tests (may require API key)"
11+
)
12+
13+
14+
def pytest_collection_modifyitems(config, items):
15+
"""Automatically mark integration tests."""
16+
for item in items:
17+
if "integration" in str(item.fspath):
18+
item.add_marker(pytest.mark.integration)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Integration test configuration template.
2+
3+
Copy this file to integration_config.py and fill in your API key.
4+
"""
5+
6+
# Your Nutrient DWS API key
7+
API_KEY = "your-api-key-here"
8+
9+
# Optional: Override base URL if testing against different environment
10+
# BASE_URL = "https://api.nutrient.io/build"
11+
12+
# Optional: Request timeout for integration tests
13+
# TIMEOUT = 60

tests/integration/test_live_api.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""Integration tests against the live Nutrient DWS API.
2+
3+
These tests require a valid API key configured in integration_config.py.
4+
"""
5+
6+
import os
7+
import pytest
8+
from pathlib import Path
9+
10+
from nutrient_dws import NutrientClient
11+
from nutrient_dws.exceptions import AuthenticationError
12+
13+
try:
14+
from . import integration_config
15+
API_KEY = integration_config.API_KEY
16+
BASE_URL = getattr(integration_config, 'BASE_URL', None)
17+
TIMEOUT = getattr(integration_config, 'TIMEOUT', 60)
18+
except ImportError:
19+
API_KEY = None
20+
BASE_URL = None
21+
TIMEOUT = 60
22+
23+
24+
@pytest.mark.skipif(not API_KEY, reason="No API key configured in integration_config.py")
25+
class TestLiveAPI:
26+
"""Integration tests against live API."""
27+
28+
@pytest.fixture
29+
def client(self):
30+
"""Create a client with the configured API key."""
31+
client = NutrientClient(api_key=API_KEY, timeout=TIMEOUT)
32+
yield client
33+
client.close()
34+
35+
@pytest.fixture
36+
def sample_pdf_path(self, tmp_path):
37+
"""Create a simple PDF file for testing."""
38+
pdf_content = b"%PDF-1.4\n1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 612 792]>>endobj xref 0 4 0000000000 65535 f 0000000010 00000 n 0000000053 00000 n 0000000125 00000 n trailer<</Size 4/Root 1 0 R>>startxref 177 %%EOF"
39+
pdf_path = tmp_path / "test.pdf"
40+
pdf_path.write_bytes(pdf_content)
41+
return str(pdf_path)
42+
43+
def test_client_initialization(self):
44+
"""Test that client initializes correctly with API key."""
45+
client = NutrientClient(api_key=API_KEY)
46+
assert client._api_key == API_KEY
47+
client.close()
48+
49+
def test_client_missing_api_key(self):
50+
"""Test that client works without API key but fails on API calls."""
51+
client = NutrientClient()
52+
# Should not raise during initialization
53+
assert client is not None
54+
client.close()
55+
56+
def test_basic_api_connectivity(self, client, sample_pdf_path):
57+
"""Test basic API connectivity with a simple operation."""
58+
# This test will depend on what operations are available
59+
# For now, we'll test that we can create a builder without errors
60+
builder = client.build(input_file=sample_pdf_path)
61+
assert builder is not None
62+
63+
@pytest.mark.skip(reason="Requires specific tool implementation")
64+
def test_convert_operation(self, client, sample_pdf_path, tmp_path):
65+
"""Test a basic convert operation (example - adjust based on available tools)."""
66+
output_path = tmp_path / "output.pdf"
67+
68+
# This is an example - adjust based on actual available tools
69+
# result = client.convert_to_pdf(input_file=sample_pdf_path, output_path=str(output_path))
70+
71+
# assert output_path.exists()
72+
# assert output_path.stat().st_size > 0
73+
74+
def test_builder_api_basic(self, client, sample_pdf_path):
75+
"""Test basic builder API functionality."""
76+
builder = client.build(input_file=sample_pdf_path)
77+
78+
# Test that we can add steps without errors
79+
# This will need to be updated based on actual available tools
80+
# builder.add_step("example-tool", {})
81+
82+
assert builder is not None

0 commit comments

Comments
 (0)