99
1010
1111@pytest .mark .parametrize (
12- ( "server_url" ) ,
12+ "server_url" ,
1313 [
14- ("https://unstructured-000mock.api.unstructuredapp.io" ), # correct url
15- ("unstructured-000mock.api.unstructuredapp.io" ),
16- ("http://unstructured-000mock.api.unstructuredapp.io/general/v0/general" ),
17- ("https://unstructured-000mock.api.unstructuredapp.io/general/v0/general" ),
18- ("unstructured-000mock.api.unstructuredapp.io/general/v0/general" ),
14+ # -- well-formed url --
15+ "https://unstructured-000mock.api.unstructuredapp.io" ,
16+ # -- common malformed urls --
17+ "unstructured-000mock.api.unstructuredapp.io" ,
18+ "http://unstructured-000mock.api.unstructuredapp.io/general/v0/general" ,
19+ "https://unstructured-000mock.api.unstructuredapp.io/general/v0/general" ,
20+ "unstructured-000mock.api.unstructuredapp.io/general/v0/general" ,
1921 ],
2022)
21- def test_clean_server_url_on_paid_api_url (server_url : str ):
23+ def test_clean_server_url_fixes_malformed_paid_api_url (server_url : str ):
2224 client = UnstructuredClient (
2325 server_url = server_url ,
2426 api_key_auth = FAKE_KEY ,
@@ -30,38 +32,51 @@ def test_clean_server_url_on_paid_api_url(server_url: str):
3032
3133
3234@pytest .mark .parametrize (
33- ( "server_url" ) ,
35+ "server_url" ,
3436 [
35- ("http://localhost:8000" ), # correct url
36- ("localhost:8000" ),
37- ("localhost:8000/general/v0/general" ),
38- ("http://localhost:8000/general/v0/general" ),
37+ # -- well-formed url --
38+ "http://localhost:8000" ,
39+ # -- common malformed urls --
40+ "localhost:8000" ,
41+ "localhost:8000/general/v0/general" ,
42+ "http://localhost:8000/general/v0/general" ,
3943 ],
4044)
41- def test_clean_server_url_on_localhost (server_url : str ):
45+ def test_clean_server_url_fixes_malformed_localhost_url (server_url : str ):
4246 client = UnstructuredClient (
4347 server_url = server_url ,
4448 api_key_auth = FAKE_KEY ,
4549 )
4650 assert client .general .sdk_configuration .server_url == "http://localhost:8000"
4751
4852
49- def test_clean_server_url_on_empty_string ():
53+ def test_clean_server_url_returns_empty_string_given_empty_string ():
5054 client = UnstructuredClient (
5155 server_url = "" ,
5256 api_key_auth = FAKE_KEY ,
5357 )
5458 assert client .general .sdk_configuration .server_url == ""
5559
5660
61+ def test_clean_server_url_returns_None_given_no_server_url ():
62+ client = UnstructuredClient (
63+ api_key_auth = FAKE_KEY ,
64+ )
65+ assert client .general .sdk_configuration .server_url == None
66+
67+
5768@pytest .mark .parametrize (
58- ( "server_url" ) ,
69+ "server_url" ,
5970 [
60- ("https://unstructured-000mock.api.unstructuredapp.io" ),
61- ("unstructured-000mock.api.unstructuredapp.io/general/v0/general" ),
71+ # -- well-formed url --
72+ "https://unstructured-000mock.api.unstructuredapp.io" ,
73+ # -- malformed url --
74+ "unstructured-000mock.api.unstructuredapp.io/general/v0/general" ,
6275 ],
6376)
64- def test_clean_server_url_with_positional_arguments (server_url : str ):
77+ def test_clean_server_url_fixes_malformed_urls_with_positional_arguments (
78+ server_url : str ,
79+ ):
6580 client = UnstructuredClient (
6681 FAKE_KEY ,
6782 "" ,
@@ -73,26 +88,26 @@ def test_clean_server_url_with_positional_arguments(server_url: str):
7388 )
7489
7590
76- def test_suggest_defining_url_if_401 ():
77- with pytest .warns (UserWarning ):
78-
79- client = UnstructuredClient (
80- api_key_auth = FAKE_KEY ,
81- )
82-
83- filename = "_sample_docs/layout-parser-paper-fast.pdf"
91+ def test_suggest_defining_url_issues_a_warning_on_a_401 ():
92+ client = UnstructuredClient (
93+ api_key_auth = FAKE_KEY ,
94+ )
8495
85- with open (filename , "rb" ) as f :
86- files = shared .Files (
87- content = f .read (),
88- file_name = filename ,
89- )
96+ filename = "_sample_docs/layout-parser-paper-fast.pdf"
9097
91- req = shared .PartitionParameters (
92- files = files ,
98+ with open (filename , "rb" ) as f :
99+ files = shared .Files (
100+ content = f .read (),
101+ file_name = filename ,
93102 )
94103
95- try :
104+ req = shared .PartitionParameters (
105+ files = files ,
106+ )
107+
108+ with pytest .raises (SDKError , match = "API error occurred: Status 401" ):
109+ with pytest .warns (
110+ UserWarning ,
111+ match = "If intending to use the paid API, please define `server_url` in your request." ,
112+ ):
96113 client .general .partition (req )
97- except SDKError as e :
98- print (e )
0 commit comments