1- import os
21import pytest
32
43from unstructured_client import UnstructuredClient
4+ from unstructured_client .models import shared
5+ from unstructured_client .models .errors import SDKError
56
67
7- def get_api_key ():
8- api_key = os .getenv ("UNS_API_KEY" )
9- if api_key is None :
10- raise ValueError ("""UNS_API_KEY environment variable not set.
11- Set it in your current shell session with `export UNS_API_KEY=<api_key>`""" )
12- return api_key
8+ FAKE_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
139
1410
1511@pytest .mark .parametrize (
@@ -25,7 +21,7 @@ def get_api_key():
2521def test_clean_server_url_on_paid_api_url (server_url : str ):
2622 client = UnstructuredClient (
2723 server_url = server_url ,
28- api_key_auth = get_api_key () ,
24+ api_key_auth = FAKE_KEY ,
2925 )
3026 assert client .general .sdk_configuration .server_url == "https://unstructured-000mock.api.unstructuredapp.io"
3127
@@ -42,18 +38,19 @@ def test_clean_server_url_on_paid_api_url(server_url: str):
4238def test_clean_server_url_on_localhost (server_url : str ):
4339 client = UnstructuredClient (
4440 server_url = server_url ,
45- api_key_auth = get_api_key () ,
41+ api_key_auth = FAKE_KEY ,
4642 )
4743 assert client .general .sdk_configuration .server_url == "http://localhost:8000"
4844
4945
5046def test_clean_server_url_on_empty_string ():
5147 client = UnstructuredClient (
5248 server_url = "" ,
53- api_key_auth = get_api_key () ,
49+ api_key_auth = FAKE_KEY ,
5450 )
5551 assert client .general .sdk_configuration .server_url == ""
5652
53+
5754@pytest .mark .parametrize (
5855 ("server_url" ),
5956 [
@@ -63,8 +60,33 @@ def test_clean_server_url_on_empty_string():
6360)
6461def test_clean_server_url_with_positional_arguments (server_url : str ):
6562 client = UnstructuredClient (
66- get_api_key () ,
63+ FAKE_KEY ,
6764 "" ,
6865 server_url ,
6966 )
7067 assert client .general .sdk_configuration .server_url == "https://unstructured-000mock.api.unstructuredapp.io"
68+
69+
70+ def test_suggest_defining_url_if_401 ():
71+ with pytest .warns (UserWarning ):
72+
73+ client = UnstructuredClient (
74+ api_key_auth = FAKE_KEY ,
75+ )
76+
77+ filename = "_sample_docs/layout-parser-paper-fast.pdf"
78+
79+ with open (filename , "rb" ) as f :
80+ files = shared .Files (
81+ content = f .read (),
82+ file_name = filename ,
83+ )
84+
85+ req = shared .PartitionParameters (
86+ files = files ,
87+ )
88+
89+ try :
90+ client .general .partition (req )
91+ except SDKError as e :
92+ print (e )
0 commit comments