unstructured-ingest 0.2.1__py3-none-any.whl → 0.2.2__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.
- test/integration/connectors/test_confluence.py +113 -0
- test/integration/connectors/test_kafka.py +67 -0
- test/integration/connectors/test_onedrive.py +112 -0
- test/integration/connectors/test_qdrant.py +137 -0
- test/integration/connectors/utils/docker.py +2 -1
- test/integration/connectors/utils/validation.py +73 -22
- unstructured_ingest/__version__.py +1 -1
- unstructured_ingest/connector/kafka.py +0 -1
- unstructured_ingest/interfaces.py +7 -7
- unstructured_ingest/v2/processes/chunker.py +2 -2
- unstructured_ingest/v2/processes/connectors/__init__.py +12 -1
- unstructured_ingest/v2/processes/connectors/confluence.py +195 -0
- unstructured_ingest/v2/processes/connectors/databricks/volumes.py +2 -4
- unstructured_ingest/v2/processes/connectors/fsspec/fsspec.py +1 -10
- unstructured_ingest/v2/processes/connectors/gitlab.py +267 -0
- unstructured_ingest/v2/processes/connectors/kafka/__init__.py +13 -0
- unstructured_ingest/v2/processes/connectors/kafka/cloud.py +82 -0
- unstructured_ingest/v2/processes/connectors/kafka/kafka.py +196 -0
- unstructured_ingest/v2/processes/connectors/kafka/local.py +75 -0
- unstructured_ingest/v2/processes/connectors/onedrive.py +163 -2
- unstructured_ingest/v2/processes/connectors/qdrant/__init__.py +16 -0
- unstructured_ingest/v2/processes/connectors/qdrant/cloud.py +59 -0
- unstructured_ingest/v2/processes/connectors/qdrant/local.py +58 -0
- unstructured_ingest/v2/processes/connectors/qdrant/qdrant.py +168 -0
- unstructured_ingest/v2/processes/connectors/qdrant/server.py +60 -0
- unstructured_ingest/v2/processes/connectors/sql/snowflake.py +3 -1
- unstructured_ingest/v2/processes/connectors/sql/sql.py +2 -4
- unstructured_ingest/v2/processes/partitioner.py +14 -3
- unstructured_ingest/v2/unstructured_api.py +24 -10
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/METADATA +22 -22
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/RECORD +35 -20
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/LICENSE.md +0 -0
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/WHEEL +0 -0
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/entry_points.txt +0 -0
- {unstructured_ingest-0.2.1.dist-info → unstructured_ingest-0.2.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from test.integration.connectors.utils.constants import (
|
|
6
|
+
SOURCE_TAG,
|
|
7
|
+
)
|
|
8
|
+
from test.integration.connectors.utils.validation import (
|
|
9
|
+
ValidationConfigs,
|
|
10
|
+
source_connector_validation,
|
|
11
|
+
)
|
|
12
|
+
from test.integration.utils import requires_env
|
|
13
|
+
from unstructured_ingest.v2.processes.connectors.confluence import (
|
|
14
|
+
CONNECTOR_TYPE,
|
|
15
|
+
ConfluenceAccessConfig,
|
|
16
|
+
ConfluenceConnectionConfig,
|
|
17
|
+
ConfluenceDownloader,
|
|
18
|
+
ConfluenceDownloaderConfig,
|
|
19
|
+
ConfluenceIndexer,
|
|
20
|
+
ConfluenceIndexerConfig,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@pytest.mark.asyncio
|
|
25
|
+
@pytest.mark.tags(CONNECTOR_TYPE, SOURCE_TAG)
|
|
26
|
+
@requires_env("CONFLUENCE_USER_EMAIL", "CONFLUENCE_API_TOKEN")
|
|
27
|
+
async def test_confluence_source(temp_dir):
|
|
28
|
+
# Retrieve environment variables
|
|
29
|
+
confluence_url = "https://unstructured-ingest-test.atlassian.net"
|
|
30
|
+
user_email = os.environ["CONFLUENCE_USER_EMAIL"]
|
|
31
|
+
api_token = os.environ["CONFLUENCE_API_TOKEN"]
|
|
32
|
+
spaces = ["testteamsp", "MFS"]
|
|
33
|
+
|
|
34
|
+
# Create connection and indexer configurations
|
|
35
|
+
access_config = ConfluenceAccessConfig(api_token=api_token)
|
|
36
|
+
connection_config = ConfluenceConnectionConfig(
|
|
37
|
+
url=confluence_url,
|
|
38
|
+
user_email=user_email,
|
|
39
|
+
access_config=access_config,
|
|
40
|
+
)
|
|
41
|
+
index_config = ConfluenceIndexerConfig(
|
|
42
|
+
max_num_of_spaces=500,
|
|
43
|
+
max_num_of_docs_from_each_space=100,
|
|
44
|
+
spaces=spaces,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
download_config = ConfluenceDownloaderConfig(download_dir=temp_dir)
|
|
48
|
+
|
|
49
|
+
# Instantiate indexer and downloader
|
|
50
|
+
indexer = ConfluenceIndexer(
|
|
51
|
+
connection_config=connection_config,
|
|
52
|
+
index_config=index_config,
|
|
53
|
+
)
|
|
54
|
+
downloader = ConfluenceDownloader(
|
|
55
|
+
connection_config=connection_config,
|
|
56
|
+
download_config=download_config,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Run the source connector validation
|
|
60
|
+
await source_connector_validation(
|
|
61
|
+
indexer=indexer,
|
|
62
|
+
downloader=downloader,
|
|
63
|
+
configs=ValidationConfigs(
|
|
64
|
+
test_id="confluence",
|
|
65
|
+
expected_num_files=11,
|
|
66
|
+
validate_downloaded_files=True,
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@pytest.mark.asyncio
|
|
72
|
+
@pytest.mark.tags(CONNECTOR_TYPE, SOURCE_TAG)
|
|
73
|
+
@requires_env("CONFLUENCE_USER_EMAIL", "CONFLUENCE_API_TOKEN")
|
|
74
|
+
async def test_confluence_source_large(temp_dir):
|
|
75
|
+
# Retrieve environment variables
|
|
76
|
+
confluence_url = "https://unstructured-ingest-test.atlassian.net"
|
|
77
|
+
user_email = os.environ["CONFLUENCE_USER_EMAIL"]
|
|
78
|
+
api_token = os.environ["CONFLUENCE_API_TOKEN"]
|
|
79
|
+
spaces = ["testteamsp1"]
|
|
80
|
+
|
|
81
|
+
# Create connection and indexer configurations
|
|
82
|
+
access_config = ConfluenceAccessConfig(api_token=api_token)
|
|
83
|
+
connection_config = ConfluenceConnectionConfig(
|
|
84
|
+
url=confluence_url,
|
|
85
|
+
user_email=user_email,
|
|
86
|
+
access_config=access_config,
|
|
87
|
+
)
|
|
88
|
+
index_config = ConfluenceIndexerConfig(
|
|
89
|
+
max_num_of_spaces=10,
|
|
90
|
+
max_num_of_docs_from_each_space=250,
|
|
91
|
+
spaces=spaces,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
download_config = ConfluenceDownloaderConfig(download_dir=temp_dir)
|
|
95
|
+
|
|
96
|
+
# Instantiate indexer and downloader
|
|
97
|
+
indexer = ConfluenceIndexer(
|
|
98
|
+
connection_config=connection_config,
|
|
99
|
+
index_config=index_config,
|
|
100
|
+
)
|
|
101
|
+
downloader = ConfluenceDownloader(
|
|
102
|
+
connection_config=connection_config,
|
|
103
|
+
download_config=download_config,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Run the source connector validation
|
|
107
|
+
await source_connector_validation(
|
|
108
|
+
indexer=indexer,
|
|
109
|
+
downloader=downloader,
|
|
110
|
+
configs=ValidationConfigs(
|
|
111
|
+
test_id="confluence_large", expected_num_files=250, validate_file_data=False
|
|
112
|
+
),
|
|
113
|
+
)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import socket
|
|
2
|
+
import tempfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from confluent_kafka import Producer
|
|
7
|
+
|
|
8
|
+
from test.integration.connectors.utils.constants import (
|
|
9
|
+
SOURCE_TAG,
|
|
10
|
+
env_setup_path,
|
|
11
|
+
)
|
|
12
|
+
from test.integration.connectors.utils.docker_compose import docker_compose_context
|
|
13
|
+
from test.integration.connectors.utils.validation import (
|
|
14
|
+
ValidationConfigs,
|
|
15
|
+
source_connector_validation,
|
|
16
|
+
)
|
|
17
|
+
from unstructured_ingest.v2.processes.connectors.kafka.local import (
|
|
18
|
+
CONNECTOR_TYPE,
|
|
19
|
+
LocalKafkaConnectionConfig,
|
|
20
|
+
LocalKafkaDownloader,
|
|
21
|
+
LocalKafkaDownloaderConfig,
|
|
22
|
+
LocalKafkaIndexer,
|
|
23
|
+
LocalKafkaIndexerConfig,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
SEED_MESSAGES = 10
|
|
27
|
+
TOPIC = "fake-topic"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture
|
|
31
|
+
def kafka_seed_topic() -> str:
|
|
32
|
+
with docker_compose_context(docker_compose_path=env_setup_path / "kafka"):
|
|
33
|
+
conf = {
|
|
34
|
+
"bootstrap.servers": "localhost:29092",
|
|
35
|
+
"client.id": socket.gethostname(),
|
|
36
|
+
"message.max.bytes": 10485760,
|
|
37
|
+
}
|
|
38
|
+
producer = Producer(conf)
|
|
39
|
+
for i in range(SEED_MESSAGES):
|
|
40
|
+
message = f"This is some text for message {i}"
|
|
41
|
+
producer.produce(topic=TOPIC, value=message)
|
|
42
|
+
producer.flush(timeout=10)
|
|
43
|
+
print(f"kafka topic {TOPIC} seeded with {SEED_MESSAGES} messages")
|
|
44
|
+
yield TOPIC
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.asyncio
|
|
48
|
+
@pytest.mark.tags(CONNECTOR_TYPE, SOURCE_TAG)
|
|
49
|
+
async def test_kafka_source_local(kafka_seed_topic: str):
|
|
50
|
+
connection_config = LocalKafkaConnectionConfig(bootstrap_server="localhost", port=29092)
|
|
51
|
+
with tempfile.TemporaryDirectory() as tempdir:
|
|
52
|
+
tempdir_path = Path(tempdir)
|
|
53
|
+
download_config = LocalKafkaDownloaderConfig(download_dir=tempdir_path)
|
|
54
|
+
indexer = LocalKafkaIndexer(
|
|
55
|
+
connection_config=connection_config,
|
|
56
|
+
index_config=LocalKafkaIndexerConfig(topic=kafka_seed_topic, num_messages_to_consume=5),
|
|
57
|
+
)
|
|
58
|
+
downloader = LocalKafkaDownloader(
|
|
59
|
+
connection_config=connection_config, download_config=download_config
|
|
60
|
+
)
|
|
61
|
+
await source_connector_validation(
|
|
62
|
+
indexer=indexer,
|
|
63
|
+
downloader=downloader,
|
|
64
|
+
configs=ValidationConfigs(
|
|
65
|
+
test_id="kafka", expected_num_files=5, validate_downloaded_files=True
|
|
66
|
+
),
|
|
67
|
+
)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import uuid
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from office365.graph_client import GraphClient
|
|
7
|
+
|
|
8
|
+
from test.integration.connectors.utils.constants import (
|
|
9
|
+
DESTINATION_TAG,
|
|
10
|
+
)
|
|
11
|
+
from test.integration.utils import requires_env
|
|
12
|
+
from unstructured_ingest.v2.interfaces import FileData, SourceIdentifiers
|
|
13
|
+
from unstructured_ingest.v2.processes.connectors.onedrive import (
|
|
14
|
+
CONNECTOR_TYPE,
|
|
15
|
+
OnedriveAccessConfig,
|
|
16
|
+
OnedriveConnectionConfig,
|
|
17
|
+
OnedriveUploader,
|
|
18
|
+
OnedriveUploaderConfig,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def onedrive_test_folder() -> str:
|
|
24
|
+
"""
|
|
25
|
+
Pytest fixture that creates a test folder in OneDrive and deletes it after test run.
|
|
26
|
+
"""
|
|
27
|
+
connection_config = get_connection_config()
|
|
28
|
+
user_pname = connection_config.user_pname
|
|
29
|
+
|
|
30
|
+
# Get the OneDrive client
|
|
31
|
+
client: GraphClient = connection_config.get_client()
|
|
32
|
+
drive = client.users[user_pname].drive
|
|
33
|
+
|
|
34
|
+
# Generate a unique test folder path
|
|
35
|
+
test_folder_path = f"utic-test-output-{uuid.uuid4()}"
|
|
36
|
+
|
|
37
|
+
# Create the test folder
|
|
38
|
+
root = drive.root
|
|
39
|
+
folder = root.create_folder(test_folder_path).execute_query()
|
|
40
|
+
print(f"created folder: {folder.name}")
|
|
41
|
+
try:
|
|
42
|
+
yield test_folder_path
|
|
43
|
+
finally:
|
|
44
|
+
# Teardown: delete the test folder and its contents
|
|
45
|
+
folder.delete_object().execute_query()
|
|
46
|
+
print(f"successfully deleted folder: {folder.name}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_connection_config():
|
|
50
|
+
"""
|
|
51
|
+
Pytest fixture that provides the OnedriveConnectionConfig for tests.
|
|
52
|
+
"""
|
|
53
|
+
client_id = os.getenv("MS_CLIENT_ID")
|
|
54
|
+
client_secret = os.getenv("MS_CLIENT_CRED")
|
|
55
|
+
tenant_id = os.getenv("MS_TENANT_ID")
|
|
56
|
+
user_pname = os.getenv("MS_USER_PNAME")
|
|
57
|
+
|
|
58
|
+
connection_config = OnedriveConnectionConfig(
|
|
59
|
+
client_id=client_id,
|
|
60
|
+
tenant=tenant_id,
|
|
61
|
+
user_pname=user_pname,
|
|
62
|
+
access_config=OnedriveAccessConfig(client_cred=client_secret),
|
|
63
|
+
)
|
|
64
|
+
return connection_config
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@pytest.mark.tags(CONNECTOR_TYPE, DESTINATION_TAG)
|
|
68
|
+
@requires_env("MS_CLIENT_CRED", "MS_CLIENT_ID", "MS_TENANT_ID", "MS_USER_PNAME")
|
|
69
|
+
def test_onedrive_destination(upload_file: Path, onedrive_test_folder: str):
|
|
70
|
+
"""
|
|
71
|
+
Integration test for the OneDrive destination connector.
|
|
72
|
+
|
|
73
|
+
This test uploads a file to OneDrive and verifies that it exists.
|
|
74
|
+
"""
|
|
75
|
+
connection_config = get_connection_config()
|
|
76
|
+
# Retrieve user principal name from the connection config
|
|
77
|
+
user_pname = connection_config.user_pname
|
|
78
|
+
|
|
79
|
+
# The test folder is provided by the fixture
|
|
80
|
+
destination_folder = onedrive_test_folder
|
|
81
|
+
destination_fullpath = f"{destination_folder}/{upload_file.name}"
|
|
82
|
+
|
|
83
|
+
# Configure the uploader with remote_url
|
|
84
|
+
upload_config = OnedriveUploaderConfig(remote_url=f"onedrive://{destination_folder}")
|
|
85
|
+
|
|
86
|
+
uploader = OnedriveUploader(
|
|
87
|
+
connection_config=connection_config,
|
|
88
|
+
upload_config=upload_config,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
file_data = FileData(
|
|
92
|
+
source_identifiers=SourceIdentifiers(
|
|
93
|
+
fullpath=destination_fullpath,
|
|
94
|
+
filename=upload_file.name,
|
|
95
|
+
),
|
|
96
|
+
connector_type=CONNECTOR_TYPE,
|
|
97
|
+
identifier="mock_file_data",
|
|
98
|
+
)
|
|
99
|
+
uploader.precheck()
|
|
100
|
+
uploader.run(path=upload_file, file_data=file_data)
|
|
101
|
+
|
|
102
|
+
# Verify that the file was uploaded
|
|
103
|
+
client = connection_config.get_client()
|
|
104
|
+
drive = client.users[user_pname].drive
|
|
105
|
+
|
|
106
|
+
uploaded_file = (
|
|
107
|
+
drive.root.get_by_path(destination_fullpath).select(["id", "name"]).get().execute_query()
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Check if the file exists
|
|
111
|
+
assert uploaded_file is not None
|
|
112
|
+
assert uploaded_file.name == upload_file.name
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import uuid
|
|
3
|
+
from contextlib import asynccontextmanager
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import AsyncGenerator
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from qdrant_client import AsyncQdrantClient
|
|
9
|
+
|
|
10
|
+
from test.integration.connectors.utils.constants import DESTINATION_TAG
|
|
11
|
+
from test.integration.connectors.utils.docker import container_context
|
|
12
|
+
from unstructured_ingest.v2.interfaces.file_data import FileData, SourceIdentifiers
|
|
13
|
+
from unstructured_ingest.v2.processes.connectors.qdrant.local import (
|
|
14
|
+
CONNECTOR_TYPE as LOCAL_CONNECTOR_TYPE,
|
|
15
|
+
)
|
|
16
|
+
from unstructured_ingest.v2.processes.connectors.qdrant.local import (
|
|
17
|
+
LocalQdrantConnectionConfig,
|
|
18
|
+
LocalQdrantUploader,
|
|
19
|
+
LocalQdrantUploaderConfig,
|
|
20
|
+
LocalQdrantUploadStager,
|
|
21
|
+
LocalQdrantUploadStagerConfig,
|
|
22
|
+
)
|
|
23
|
+
from unstructured_ingest.v2.processes.connectors.qdrant.server import (
|
|
24
|
+
CONNECTOR_TYPE as SERVER_CONNECTOR_TYPE,
|
|
25
|
+
)
|
|
26
|
+
from unstructured_ingest.v2.processes.connectors.qdrant.server import (
|
|
27
|
+
ServerQdrantConnectionConfig,
|
|
28
|
+
ServerQdrantUploader,
|
|
29
|
+
ServerQdrantUploaderConfig,
|
|
30
|
+
ServerQdrantUploadStager,
|
|
31
|
+
ServerQdrantUploadStagerConfig,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
COLLECTION_NAME = f"test-coll-{uuid.uuid4().hex[:12]}"
|
|
35
|
+
VECTORS_CONFIG = {"size": 384, "distance": "Cosine"}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@asynccontextmanager
|
|
39
|
+
async def qdrant_client(client_params: dict) -> AsyncGenerator[AsyncQdrantClient, None]:
|
|
40
|
+
client = AsyncQdrantClient(**client_params)
|
|
41
|
+
try:
|
|
42
|
+
yield client
|
|
43
|
+
finally:
|
|
44
|
+
await client.close()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
async def validate_upload(client: AsyncQdrantClient, upload_file: Path):
|
|
48
|
+
with upload_file.open() as upload_fp:
|
|
49
|
+
elements = json.load(upload_fp)
|
|
50
|
+
expected_point_count = len(elements)
|
|
51
|
+
first_element = elements[0]
|
|
52
|
+
expected_text = first_element["text"]
|
|
53
|
+
embeddings = first_element["embeddings"]
|
|
54
|
+
collection = await client.get_collection(COLLECTION_NAME)
|
|
55
|
+
assert collection.points_count == expected_point_count
|
|
56
|
+
|
|
57
|
+
response = await client.query_points(COLLECTION_NAME, query=embeddings, limit=1)
|
|
58
|
+
assert response.points[0].payload is not None
|
|
59
|
+
assert response.points[0].payload["text"] == expected_text
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.asyncio
|
|
63
|
+
@pytest.mark.tags(LOCAL_CONNECTOR_TYPE, DESTINATION_TAG, "qdrant")
|
|
64
|
+
async def test_qdrant_destination_local(upload_file: Path, tmp_path: Path):
|
|
65
|
+
connection_kwargs = {"path": str(tmp_path / "qdrant")}
|
|
66
|
+
async with qdrant_client(connection_kwargs) as client:
|
|
67
|
+
await client.create_collection(COLLECTION_NAME, vectors_config=VECTORS_CONFIG)
|
|
68
|
+
AsyncQdrantClient(**connection_kwargs)
|
|
69
|
+
stager = LocalQdrantUploadStager(
|
|
70
|
+
upload_stager_config=LocalQdrantUploadStagerConfig(),
|
|
71
|
+
)
|
|
72
|
+
uploader = LocalQdrantUploader(
|
|
73
|
+
connection_config=LocalQdrantConnectionConfig(**connection_kwargs),
|
|
74
|
+
upload_config=LocalQdrantUploaderConfig(collection_name=COLLECTION_NAME),
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
file_data = FileData(
|
|
78
|
+
source_identifiers=SourceIdentifiers(fullpath=upload_file.name, filename=upload_file.name),
|
|
79
|
+
connector_type=LOCAL_CONNECTOR_TYPE,
|
|
80
|
+
identifier="mock-file-data",
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
staged_upload_file = stager.run(
|
|
84
|
+
elements_filepath=upload_file,
|
|
85
|
+
file_data=file_data,
|
|
86
|
+
output_dir=tmp_path,
|
|
87
|
+
output_filename=upload_file.name,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if uploader.is_async():
|
|
91
|
+
await uploader.run_async(path=staged_upload_file, file_data=file_data)
|
|
92
|
+
else:
|
|
93
|
+
uploader.run(path=upload_file, file_data=file_data)
|
|
94
|
+
async with qdrant_client(connection_kwargs) as client:
|
|
95
|
+
await validate_upload(client=client, upload_file=upload_file)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@pytest.fixture
|
|
99
|
+
def docker_context():
|
|
100
|
+
with container_context(image="qdrant/qdrant:latest", ports={"6333": "6333"}) as container:
|
|
101
|
+
yield container
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@pytest.mark.asyncio
|
|
105
|
+
@pytest.mark.tags(SERVER_CONNECTOR_TYPE, DESTINATION_TAG, "qdrant")
|
|
106
|
+
async def test_qdrant_destination_server(upload_file: Path, tmp_path: Path, docker_context):
|
|
107
|
+
connection_kwargs = {"location": "http://localhost:6333"}
|
|
108
|
+
async with qdrant_client(connection_kwargs) as client:
|
|
109
|
+
await client.create_collection(COLLECTION_NAME, vectors_config=VECTORS_CONFIG)
|
|
110
|
+
AsyncQdrantClient(**connection_kwargs)
|
|
111
|
+
stager = ServerQdrantUploadStager(
|
|
112
|
+
upload_stager_config=ServerQdrantUploadStagerConfig(),
|
|
113
|
+
)
|
|
114
|
+
uploader = ServerQdrantUploader(
|
|
115
|
+
connection_config=ServerQdrantConnectionConfig(**connection_kwargs),
|
|
116
|
+
upload_config=ServerQdrantUploaderConfig(collection_name=COLLECTION_NAME),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
file_data = FileData(
|
|
120
|
+
source_identifiers=SourceIdentifiers(fullpath=upload_file.name, filename=upload_file.name),
|
|
121
|
+
connector_type=SERVER_CONNECTOR_TYPE,
|
|
122
|
+
identifier="mock-file-data",
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
staged_upload_file = stager.run(
|
|
126
|
+
elements_filepath=upload_file,
|
|
127
|
+
file_data=file_data,
|
|
128
|
+
output_dir=tmp_path,
|
|
129
|
+
output_filename=upload_file.name,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if uploader.is_async():
|
|
133
|
+
await uploader.run_async(path=staged_upload_file, file_data=file_data)
|
|
134
|
+
else:
|
|
135
|
+
uploader.run(path=upload_file, file_data=file_data)
|
|
136
|
+
async with qdrant_client(connection_kwargs) as client:
|
|
137
|
+
await validate_upload(client=client, upload_file=upload_file)
|
|
@@ -47,14 +47,15 @@ def healthcheck_wait(container: Container, timeout: int = 10) -> None:
|
|
|
47
47
|
|
|
48
48
|
@contextmanager
|
|
49
49
|
def container_context(
|
|
50
|
-
docker_client: docker.DockerClient,
|
|
51
50
|
image: str,
|
|
52
51
|
ports: dict,
|
|
53
52
|
environment: Optional[dict] = None,
|
|
54
53
|
volumes: Optional[dict] = None,
|
|
55
54
|
healthcheck: Optional[dict] = None,
|
|
56
55
|
healthcheck_timeout: int = 10,
|
|
56
|
+
docker_client: Optional[docker.DockerClient] = None,
|
|
57
57
|
):
|
|
58
|
+
docker_client = docker_client or docker.from_env()
|
|
58
59
|
container: Optional[Container] = None
|
|
59
60
|
try:
|
|
60
61
|
container = get_container(
|
|
@@ -7,13 +7,14 @@ from pathlib import Path
|
|
|
7
7
|
from typing import Callable, Optional
|
|
8
8
|
|
|
9
9
|
import pandas as pd
|
|
10
|
+
from bs4 import BeautifulSoup
|
|
10
11
|
from deepdiff import DeepDiff
|
|
11
12
|
|
|
12
13
|
from test.integration.connectors.utils.constants import expected_results_path
|
|
13
14
|
from unstructured_ingest.v2.interfaces import Downloader, FileData, Indexer
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
def
|
|
17
|
+
def json_equality_check(expected_filepath: Path, current_filepath: Path) -> bool:
|
|
17
18
|
expected_df = pd.read_csv(expected_filepath)
|
|
18
19
|
current_df = pd.read_csv(current_filepath)
|
|
19
20
|
if expected_df.equals(current_df):
|
|
@@ -27,6 +28,42 @@ def pandas_df_equality_check(expected_filepath: Path, current_filepath: Path) ->
|
|
|
27
28
|
return False
|
|
28
29
|
|
|
29
30
|
|
|
31
|
+
def html_equality_check(expected_filepath: Path, current_filepath: Path) -> bool:
|
|
32
|
+
with expected_filepath.open() as expected_f:
|
|
33
|
+
expected_soup = BeautifulSoup(expected_f, "html.parser")
|
|
34
|
+
with current_filepath.open() as current_f:
|
|
35
|
+
current_soup = BeautifulSoup(current_f, "html.parser")
|
|
36
|
+
return expected_soup.text == current_soup.text
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def txt_equality_check(expected_filepath: Path, current_filepath: Path) -> bool:
|
|
40
|
+
with expected_filepath.open() as expected_f:
|
|
41
|
+
expected_text_lines = expected_f.readlines()
|
|
42
|
+
with current_filepath.open() as current_f:
|
|
43
|
+
current_text_lines = current_f.readlines()
|
|
44
|
+
if len(expected_text_lines) != len(current_text_lines):
|
|
45
|
+
print(
|
|
46
|
+
f"Lines in expected text file ({len(expected_text_lines)}) "
|
|
47
|
+
f"don't match current text file ({len(current_text_lines)})"
|
|
48
|
+
)
|
|
49
|
+
return False
|
|
50
|
+
expected_text = "\n".join(expected_text_lines)
|
|
51
|
+
current_text = "\n".join(current_text_lines)
|
|
52
|
+
if expected_text == current_text:
|
|
53
|
+
return True
|
|
54
|
+
print("txt content don't match:")
|
|
55
|
+
print(f"expected: {expected_text}")
|
|
56
|
+
print(f"current: {current_text}")
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
file_type_equality_check = {
|
|
61
|
+
".json": json_equality_check,
|
|
62
|
+
".html": html_equality_check,
|
|
63
|
+
".txt": txt_equality_check,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
30
67
|
@dataclass
|
|
31
68
|
class ValidationConfigs:
|
|
32
69
|
test_id: str
|
|
@@ -39,6 +76,7 @@ class ValidationConfigs:
|
|
|
39
76
|
)
|
|
40
77
|
exclude_fields_extend: list[str] = field(default_factory=list)
|
|
41
78
|
validate_downloaded_files: bool = False
|
|
79
|
+
validate_file_data: bool = True
|
|
42
80
|
downloaded_file_equality_check: Optional[Callable[[Path, Path], bool]] = None
|
|
43
81
|
|
|
44
82
|
def get_exclude_fields(self) -> list[str]:
|
|
@@ -86,7 +124,7 @@ class ValidationConfigs:
|
|
|
86
124
|
|
|
87
125
|
def get_files(dir_path: Path) -> list[str]:
|
|
88
126
|
return [
|
|
89
|
-
str(f).replace(str(dir_path), "").lstrip("/") for f in dir_path.
|
|
127
|
+
str(f).replace(str(dir_path), "").lstrip("/") for f in dir_path.rglob("*") if f.is_file()
|
|
90
128
|
]
|
|
91
129
|
|
|
92
130
|
|
|
@@ -122,6 +160,23 @@ def check_contents(
|
|
|
122
160
|
assert not found_diff, f"Diffs found between files: {found_diff}"
|
|
123
161
|
|
|
124
162
|
|
|
163
|
+
def detect_diff(
|
|
164
|
+
configs: ValidationConfigs, expected_filepath: Path, current_filepath: Path
|
|
165
|
+
) -> bool:
|
|
166
|
+
if expected_filepath.suffix != current_filepath.suffix:
|
|
167
|
+
return True
|
|
168
|
+
if downloaded_file_equality_check := configs.downloaded_file_equality_check:
|
|
169
|
+
return not downloaded_file_equality_check(expected_filepath, current_filepath)
|
|
170
|
+
current_suffix = expected_filepath.suffix
|
|
171
|
+
if current_suffix in file_type_equality_check:
|
|
172
|
+
equality_check_callable = file_type_equality_check[current_suffix]
|
|
173
|
+
return not equality_check_callable(
|
|
174
|
+
expected_filepath=expected_filepath, current_filepath=current_filepath
|
|
175
|
+
)
|
|
176
|
+
# Fallback is using filecmp.cmp to compare the files
|
|
177
|
+
return not filecmp.cmp(expected_filepath, current_filepath, shallow=False)
|
|
178
|
+
|
|
179
|
+
|
|
125
180
|
def check_raw_file_contents(
|
|
126
181
|
expected_output_dir: Path,
|
|
127
182
|
current_output_dir: Path,
|
|
@@ -133,15 +188,7 @@ def check_raw_file_contents(
|
|
|
133
188
|
for current_file in current_files:
|
|
134
189
|
current_file_path = current_output_dir / current_file
|
|
135
190
|
expected_file_path = expected_output_dir / current_file
|
|
136
|
-
if
|
|
137
|
-
is_different = downloaded_file_equality_check(expected_file_path, current_file_path)
|
|
138
|
-
elif expected_file_path.suffix == ".csv" and current_file_path.suffix == ".csv":
|
|
139
|
-
is_different = not pandas_df_equality_check(
|
|
140
|
-
expected_filepath=expected_file_path, current_filepath=current_file_path
|
|
141
|
-
)
|
|
142
|
-
else:
|
|
143
|
-
is_different = not filecmp.cmp(expected_file_path, current_file_path, shallow=False)
|
|
144
|
-
if is_different:
|
|
191
|
+
if detect_diff(configs, expected_file_path, current_file_path):
|
|
145
192
|
found_diff = True
|
|
146
193
|
files.append(str(expected_file_path))
|
|
147
194
|
print(f"diffs between files {expected_file_path} and {current_file_path}")
|
|
@@ -185,17 +232,19 @@ def update_fixtures(
|
|
|
185
232
|
download_dir: Path,
|
|
186
233
|
all_file_data: list[FileData],
|
|
187
234
|
save_downloads: bool = False,
|
|
235
|
+
save_filedata: bool = True,
|
|
188
236
|
):
|
|
189
237
|
# Delete current files
|
|
190
238
|
shutil.rmtree(path=output_dir, ignore_errors=True)
|
|
191
239
|
output_dir.mkdir(parents=True)
|
|
192
240
|
# Rewrite the current file data
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
241
|
+
if save_filedata:
|
|
242
|
+
file_data_output_path = output_dir / "file_data"
|
|
243
|
+
file_data_output_path.mkdir(parents=True, exist_ok=True)
|
|
244
|
+
for file_data in all_file_data:
|
|
245
|
+
file_data_path = file_data_output_path / f"{file_data.identifier}.json"
|
|
246
|
+
with file_data_path.open(mode="w") as f:
|
|
247
|
+
json.dump(file_data.to_dict(), f, indent=2)
|
|
199
248
|
|
|
200
249
|
# Record file structure of download directory
|
|
201
250
|
download_files = get_files(dir_path=download_dir)
|
|
@@ -229,11 +278,12 @@ def run_all_validations(
|
|
|
229
278
|
predownload_file_data=pre_data, postdownload_file_data=post_data
|
|
230
279
|
)
|
|
231
280
|
configs.run_download_dir_validation(download_dir=download_dir)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
281
|
+
if configs.validate_file_data:
|
|
282
|
+
run_expected_results_validation(
|
|
283
|
+
expected_output_dir=test_output_dir / "file_data",
|
|
284
|
+
all_file_data=postdownload_file_data,
|
|
285
|
+
configs=configs,
|
|
286
|
+
)
|
|
237
287
|
download_files = get_files(dir_path=download_dir)
|
|
238
288
|
download_files.sort()
|
|
239
289
|
run_directory_structure_validation(
|
|
@@ -291,4 +341,5 @@ async def source_connector_validation(
|
|
|
291
341
|
download_dir=download_dir,
|
|
292
342
|
all_file_data=all_postdownload_file_data,
|
|
293
343
|
save_downloads=configs.validate_downloaded_files,
|
|
344
|
+
save_filedata=configs.validate_file_data,
|
|
294
345
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.2.
|
|
1
|
+
__version__ = "0.2.2" # pragma: no cover
|
|
@@ -181,7 +181,6 @@ class KafkaSourceConnector(SourceConnectorCleanupMixin, BaseSourceConnector):
|
|
|
181
181
|
logger.debug(f"found {len(collected)} messages, stopping")
|
|
182
182
|
consumer.commit(asynchronous=False)
|
|
183
183
|
break
|
|
184
|
-
|
|
185
184
|
return [
|
|
186
185
|
KafkaIngestDoc(
|
|
187
186
|
connector_config=self.connector_config,
|
|
@@ -21,6 +21,7 @@ from unstructured_ingest.enhanced_dataclass.core import _asdict
|
|
|
21
21
|
from unstructured_ingest.error import PartitionError, SourceConnectionError
|
|
22
22
|
from unstructured_ingest.logger import logger
|
|
23
23
|
from unstructured_ingest.utils.data_prep import flatten_dict
|
|
24
|
+
from unstructured_ingest.v2.unstructured_api import call_api
|
|
24
25
|
|
|
25
26
|
if TYPE_CHECKING:
|
|
26
27
|
from unstructured.documents.elements import Element
|
|
@@ -565,6 +566,7 @@ class BaseSingleIngestDoc(BaseIngestDoc, IngestDocJsonMixin, ABC):
|
|
|
565
566
|
) -> list["Element"]:
|
|
566
567
|
from unstructured.documents.elements import DataSourceMetadata
|
|
567
568
|
from unstructured.partition.auto import partition
|
|
569
|
+
from unstructured.staging.base import elements_from_dicts
|
|
568
570
|
|
|
569
571
|
if not partition_config.partition_by_api:
|
|
570
572
|
logger.debug("Using local partition")
|
|
@@ -582,18 +584,16 @@ class BaseSingleIngestDoc(BaseIngestDoc, IngestDocJsonMixin, ABC):
|
|
|
582
584
|
**partition_kwargs,
|
|
583
585
|
)
|
|
584
586
|
else:
|
|
585
|
-
from unstructured.partition.api import partition_via_api
|
|
586
|
-
|
|
587
587
|
endpoint = partition_config.partition_endpoint
|
|
588
588
|
|
|
589
589
|
logger.debug(f"using remote partition ({endpoint})")
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
filename=str(self.filename),
|
|
590
|
+
elements_dicts = call_api(
|
|
591
|
+
server_url=endpoint,
|
|
593
592
|
api_key=partition_config.api_key,
|
|
594
|
-
|
|
595
|
-
|
|
593
|
+
filename=Path(self.filename),
|
|
594
|
+
api_parameters=partition_kwargs,
|
|
596
595
|
)
|
|
596
|
+
elements = elements_from_dicts(elements_dicts)
|
|
597
597
|
# TODO: add m_data_source_metadata to unstructured-api pipeline_api and then
|
|
598
598
|
# pass the stringified json here
|
|
599
599
|
return elements
|
|
@@ -9,7 +9,7 @@ from unstructured_ingest.utils.chunking import assign_and_map_hash_ids
|
|
|
9
9
|
from unstructured_ingest.utils.dep_check import requires_dependencies
|
|
10
10
|
from unstructured_ingest.v2.interfaces.process import BaseProcess
|
|
11
11
|
from unstructured_ingest.v2.logger import logger
|
|
12
|
-
from unstructured_ingest.v2.unstructured_api import
|
|
12
|
+
from unstructured_ingest.v2.unstructured_api import call_api_async
|
|
13
13
|
|
|
14
14
|
CHUNK_MAX_CHARS_DEFAULT: int = 500
|
|
15
15
|
CHUNK_MULTI_PAGE_DEFAULT: bool = True
|
|
@@ -112,7 +112,7 @@ class Chunker(BaseProcess, ABC):
|
|
|
112
112
|
|
|
113
113
|
@requires_dependencies(dependencies=["unstructured_client"], extras="remote")
|
|
114
114
|
async def run_async(self, elements_filepath: Path, **kwargs: Any) -> list[dict]:
|
|
115
|
-
elements = await
|
|
115
|
+
elements = await call_api_async(
|
|
116
116
|
server_url=self.config.chunking_endpoint,
|
|
117
117
|
api_key=self.config.chunk_api_key.get_secret_value(),
|
|
118
118
|
filename=elements_filepath,
|