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\n 1 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