unstructured-ingest 0.5.8__py3-none-any.whl → 0.5.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of unstructured-ingest might be problematic. Click here for more details.

@@ -56,12 +56,7 @@ def test_precheck_succeeds_indexer(connection_config: AstraDBConnectionConfig):
56
56
  connection_config=connection_config,
57
57
  index_config=AstraDBIndexerConfig(collection_name=EXISTENT_COLLECTION_NAME),
58
58
  )
59
- uploader = AstraDBUploader(
60
- connection_config=connection_config,
61
- upload_config=AstraDBUploaderConfig(collection_name=EXISTENT_COLLECTION_NAME),
62
- )
63
59
  indexer.precheck()
64
- uploader.precheck()
65
60
 
66
61
 
67
62
  @pytest.mark.tags(CONNECTOR_TYPE, DESTINATION_TAG, VECTOR_DB_TAG)
@@ -73,6 +68,12 @@ def test_precheck_succeeds_uploader(connection_config: AstraDBConnectionConfig):
73
68
  )
74
69
  uploader.precheck()
75
70
 
71
+ uploader2 = AstraDBUploader(
72
+ connection_config=connection_config,
73
+ upload_config=AstraDBUploaderConfig(),
74
+ )
75
+ uploader2.precheck()
76
+
76
77
 
77
78
  @pytest.mark.tags(CONNECTOR_TYPE, SOURCE_TAG, VECTOR_DB_TAG)
78
79
  @requires_env("ASTRA_DB_APPLICATION_TOKEN", "ASTRA_DB_API_ENDPOINT")
@@ -216,6 +217,32 @@ async def test_astra_search_destination(
216
217
  )
217
218
 
218
219
 
220
+ @pytest.mark.tags(CONNECTOR_TYPE, DESTINATION_TAG, VECTOR_DB_TAG)
221
+ @requires_env("ASTRA_DB_API_ENDPOINT", "ASTRA_DB_APPLICATION_TOKEN")
222
+ def test_astra_create_destination():
223
+ env_data = get_env_data()
224
+ connection_config = AstraDBConnectionConfig(
225
+ access_config=AstraDBAccessConfig(api_endpoint=env_data.api_endpoint, token=env_data.token),
226
+ )
227
+ uploader = AstraDBUploader(
228
+ connection_config=connection_config,
229
+ upload_config=AstraDBUploaderConfig(),
230
+ )
231
+ collection_name = "system_created-123"
232
+ formatted_collection_name = "system_created_123"
233
+ created = uploader.create_destination(destination_name=collection_name, vector_length=3072)
234
+ assert created
235
+ assert uploader.upload_config.collection_name == formatted_collection_name
236
+
237
+ created = uploader.create_destination(destination_name=collection_name, vector_length=3072)
238
+ assert not created
239
+
240
+ # cleanup
241
+ client = AstraDBClient()
242
+ db = client.get_database(api_endpoint=env_data.api_endpoint, token=env_data.token)
243
+ db.drop_collection(formatted_collection_name)
244
+
245
+
219
246
  @pytest.mark.tags(CONNECTOR_TYPE, DESTINATION_TAG, VECTOR_DB_TAG)
220
247
  @pytest.mark.parametrize("upload_file_str", ["upload_file_ndjson", "upload_file"])
221
248
  def test_astra_stager(
@@ -0,0 +1,151 @@
1
+ import os
2
+
3
+ import pytest
4
+ import requests
5
+
6
+ from test.integration.connectors.utils.constants import (
7
+ BLOB_STORAGE_TAG,
8
+ SOURCE_TAG,
9
+ )
10
+ from test.integration.connectors.utils.validation.source import (
11
+ SourceValidationConfigs,
12
+ source_connector_validation,
13
+ )
14
+ from test.integration.utils import requires_env
15
+ from unstructured_ingest.v2.processes.connectors.fsspec.dropbox import (
16
+ CONNECTOR_TYPE as DROPBOX_CONNECTOR_TYPE,
17
+ )
18
+ from unstructured_ingest.v2.processes.connectors.fsspec.dropbox import (
19
+ DropboxAccessConfig,
20
+ DropboxConnectionConfig,
21
+ DropboxDownloader,
22
+ DropboxDownloaderConfig,
23
+ DropboxIndexer,
24
+ DropboxIndexerConfig,
25
+ )
26
+
27
+
28
+ @pytest.mark.asyncio
29
+ @pytest.mark.tags(DROPBOX_CONNECTOR_TYPE, SOURCE_TAG, BLOB_STORAGE_TAG)
30
+ @requires_env("DROPBOX_REFRESH_TOKEN", "DROPBOX_APP_KEY", "DROPBOX_APP_SECRET")
31
+ async def test_dropbox_source(temp_dir):
32
+ """
33
+ Integration test for the Dropbox source connector.
34
+
35
+ This test indexes data from dropbox://test-input/ and downloads the resulting files,
36
+ then compares them to fixture data.
37
+ """
38
+ refresh_token = os.getenv("DROPBOX_REFRESH_TOKEN")
39
+ app_key = os.getenv("DROPBOX_APP_KEY")
40
+ app_secret = os.getenv("DROPBOX_APP_SECRET")
41
+
42
+ connection_config = DropboxConnectionConfig(
43
+ access_config=DropboxAccessConfig(
44
+ refresh_token=refresh_token,
45
+ app_key=app_key,
46
+ app_secret=app_secret,
47
+ )
48
+ )
49
+
50
+ index_config = DropboxIndexerConfig(
51
+ recursive=True,
52
+ remote_url="dropbox://test-input",
53
+ )
54
+ downloader_config = DropboxDownloaderConfig(download_dir=temp_dir)
55
+
56
+ indexer = DropboxIndexer(
57
+ connection_config=connection_config,
58
+ index_config=index_config,
59
+ )
60
+ downloader = DropboxDownloader(
61
+ connection_config=connection_config,
62
+ download_config=downloader_config,
63
+ )
64
+
65
+ await source_connector_validation(
66
+ indexer=indexer,
67
+ downloader=downloader,
68
+ configs=SourceValidationConfigs(
69
+ test_id="dropbox",
70
+ expected_num_files=4,
71
+ validate_downloaded_files=True,
72
+ exclude_fields_extend=[
73
+ "metadata.date_created",
74
+ "metadata.date_modified",
75
+ ],
76
+ ),
77
+ )
78
+
79
+
80
+ @pytest.mark.asyncio
81
+ @pytest.mark.tags(DROPBOX_CONNECTOR_TYPE, SOURCE_TAG, BLOB_STORAGE_TAG)
82
+ @requires_env("DROPBOX_REFRESH_TOKEN", "DROPBOX_APP_KEY", "DROPBOX_APP_SECRET")
83
+ async def test_dropbox_short_lived_token_via_refresh(temp_dir):
84
+ """
85
+ Demonstrates manually generating an access token from refresh credentials,
86
+ then passing ONLY the short-lived token to the Dropbox connector
87
+ (no app_key, app_secret, or refresh_token in the actual connection config).
88
+
89
+ This effectively mimics an external system that hands us a short-lived token.
90
+ """
91
+ refresh_token = os.getenv("DROPBOX_REFRESH_TOKEN")
92
+ app_key = os.getenv("DROPBOX_APP_KEY")
93
+ app_secret = os.getenv("DROPBOX_APP_SECRET")
94
+
95
+ # Manually request a short-lived token from Dropbox's OAuth endpoint
96
+ # This call is basically what the connector code does internally,
97
+ # but we're doing it here in the test so we can pass only the short-lived token later.
98
+ response = requests.post(
99
+ "https://api.dropboxapi.com/oauth2/token",
100
+ data={
101
+ "grant_type": "refresh_token",
102
+ "refresh_token": refresh_token,
103
+ },
104
+ auth=(app_key, app_secret),
105
+ timeout=30, # seconds
106
+ )
107
+ response.raise_for_status()
108
+ data = response.json()
109
+ short_lived_token = data["access_token"]
110
+ print("Acquired an access token from Dropbox")
111
+
112
+ # Build connection config with ONLY the short-lived token
113
+ # We omit refresh_token, app_key, and app_secret to confirm that
114
+ # our connector can operate purely on the short-lived token.
115
+ connection_config = DropboxConnectionConfig(
116
+ access_config=DropboxAccessConfig(
117
+ token=short_lived_token,
118
+ app_key=None,
119
+ app_secret=None,
120
+ refresh_token=None,
121
+ )
122
+ )
123
+
124
+ index_config = DropboxIndexerConfig(
125
+ recursive=True,
126
+ remote_url="dropbox://test-input",
127
+ )
128
+ downloader_config = DropboxDownloaderConfig(download_dir=temp_dir)
129
+
130
+ indexer = DropboxIndexer(
131
+ connection_config=connection_config,
132
+ index_config=index_config,
133
+ )
134
+ downloader = DropboxDownloader(
135
+ connection_config=connection_config,
136
+ download_config=downloader_config,
137
+ )
138
+
139
+ await source_connector_validation(
140
+ indexer=indexer,
141
+ downloader=downloader,
142
+ configs=SourceValidationConfigs(
143
+ test_id="dropbox_short_lived_via_refresh",
144
+ expected_num_files=4,
145
+ validate_downloaded_files=True,
146
+ exclude_fields_extend=[
147
+ "metadata.date_created",
148
+ "metadata.date_modified",
149
+ ],
150
+ ),
151
+ )
@@ -0,0 +1,67 @@
1
+ import os
2
+
3
+ import pytest
4
+
5
+ from test.integration.connectors.utils.constants import SOURCE_TAG, UNCATEGORIZED_TAG
6
+ from test.integration.connectors.utils.validation.source import (
7
+ SourceValidationConfigs,
8
+ source_connector_validation,
9
+ )
10
+ from test.integration.utils import requires_env
11
+ from unstructured_ingest.v2.processes.connectors.jira import (
12
+ CONNECTOR_TYPE,
13
+ JiraAccessConfig,
14
+ JiraConnectionConfig,
15
+ JiraDownloader,
16
+ JiraDownloaderConfig,
17
+ JiraIndexer,
18
+ JiraIndexerConfig,
19
+ )
20
+
21
+
22
+ @pytest.mark.asyncio
23
+ @pytest.mark.tags(CONNECTOR_TYPE, SOURCE_TAG, UNCATEGORIZED_TAG)
24
+ @requires_env("JIRA_INGEST_USER_EMAIL", "JIRA_INGEST_API_TOKEN")
25
+ async def test_jira_source(temp_dir):
26
+ # Retrieve environment variables
27
+ jira_url = os.environ.get(
28
+ "JIRA_INGEST_URL", "https://unstructured-jira-connector-test.atlassian.net"
29
+ )
30
+ user_email = os.environ["JIRA_INGEST_USER_EMAIL"]
31
+ api_token = os.environ["JIRA_INGEST_API_TOKEN"]
32
+ projects = ["JCTP1"]
33
+ boards = ["3"]
34
+ issues = ["JCTP2-1", "JCTP2-2", "JCTP2-3"]
35
+
36
+ # Create connection and indexer configurations
37
+ access_config = JiraAccessConfig(password=api_token)
38
+ connection_config = JiraConnectionConfig(
39
+ url=jira_url,
40
+ username=user_email,
41
+ access_config=access_config,
42
+ )
43
+ index_config = JiraIndexerConfig(projects=projects, boards=boards, issues=issues)
44
+
45
+ download_config = JiraDownloaderConfig(download_dir=temp_dir)
46
+
47
+ # Instantiate indexer and downloader
48
+ indexer = JiraIndexer(
49
+ connection_config=connection_config,
50
+ index_config=index_config,
51
+ )
52
+ downloader = JiraDownloader(
53
+ connection_config=connection_config,
54
+ download_config=download_config,
55
+ )
56
+
57
+ # Run the source connector validation
58
+ await source_connector_validation(
59
+ indexer=indexer,
60
+ downloader=downloader,
61
+ configs=SourceValidationConfigs(
62
+ test_id="jira",
63
+ expected_num_files=8,
64
+ validate_file_data=True,
65
+ validate_downloaded_files=True,
66
+ ),
67
+ )
test/unit/test_utils.py CHANGED
@@ -10,6 +10,7 @@ from unstructured_ingest.cli.utils import extract_config
10
10
  from unstructured_ingest.interfaces import BaseConfig
11
11
  from unstructured_ingest.utils.string_and_date_utils import (
12
12
  ensure_isoformat_datetime,
13
+ fix_unescaped_unicode,
13
14
  json_to_dict,
14
15
  truncate_string_bytes,
15
16
  )
@@ -182,3 +183,29 @@ def test_truncate_string_bytes_return_untouched_string():
182
183
  result = truncate_string_bytes(test_string, max_bytes)
183
184
  assert result == "abcdef"
184
185
  assert len(result.encode("utf-8")) <= max_bytes
186
+
187
+
188
+ def test_fix_unescaped_unicode_valid():
189
+ text = "This is a test with unescaped unicode: \\u0041"
190
+ expected = "This is a test with unescaped unicode: \u0041"
191
+ assert fix_unescaped_unicode(text) == expected
192
+
193
+
194
+ def test_fix_unescaped_unicode_no_unescaped_chars():
195
+ text = "This is a test with no unescaped unicode: \u0041"
196
+ expected = "This is a test with no unescaped unicode: \u0041"
197
+ assert fix_unescaped_unicode(text) == expected
198
+
199
+
200
+ def test_fix_unescaped_unicode_invalid_unicode():
201
+ text = "This is a test with invalid unescaped unicode: \\uZZZZ"
202
+ expected = "This is a test with invalid unescaped unicode: \\uZZZZ"
203
+ assert fix_unescaped_unicode(text) == expected
204
+
205
+
206
+ def test_fix_unescaped_unicode_encoding_error(caplog: pytest.LogCaptureFixture):
207
+ text = "This is a test with unescaped unicode: \\uD83D"
208
+ fix_unescaped_unicode(text)
209
+ with caplog.at_level("WARNING"):
210
+ fix_unescaped_unicode(text)
211
+ assert "Failed to fix unescaped Unicode sequences" in caplog.text