-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace token api str with Secret (#449)
* replace token api str with Secret * PR fixes and adding one more test * cleaning leftovers
- Loading branch information
1 parent
3a6cf81
commit 102be5e
Showing
4 changed files
with
39 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def set_env_variables(monkeypatch): | ||
monkeypatch.setenv("UNSTRUCTURED_API_KEY", "test-api-key") | ||
|
||
|
||
@pytest.fixture | ||
def samples_path(): | ||
return Path(__file__).parent / "samples" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
# SPDX-FileCopyrightText: 2023-present deepset GmbH <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from pathlib import Path | ||
|
||
import pytest | ||
from haystack_integrations.components.converters.unstructured import UnstructuredFileConverter | ||
|
||
|
||
@pytest.fixture | ||
def samples_path(): | ||
return Path(__file__).parent / "samples" | ||
|
||
|
||
class TestUnstructuredFileConverter: | ||
@pytest.mark.usefixtures("set_env_variables") | ||
def test_init_default(self): | ||
converter = UnstructuredFileConverter(api_key="test-api-key") | ||
converter = UnstructuredFileConverter() | ||
assert converter.api_url == "https://api.unstructured.io/general/v0/general" | ||
assert converter.api_key == "test-api-key" | ||
assert converter.api_key.resolve_value() == "test-api-key" | ||
assert converter.document_creation_mode == "one-doc-per-file" | ||
assert converter.separator == "\n\n" | ||
assert converter.unstructured_kwargs == {} | ||
|
@@ -31,20 +25,26 @@ def test_init_with_parameters(self): | |
progress_bar=False, | ||
) | ||
assert converter.api_url == "http://custom-url:8000/general" | ||
assert converter.api_key is None | ||
assert converter.api_key.resolve_value() is None | ||
assert converter.document_creation_mode == "one-doc-per-element" | ||
assert converter.separator == "|" | ||
assert converter.unstructured_kwargs == {"foo": "bar"} | ||
assert not converter.progress_bar | ||
|
||
def test_init_hosted_without_api_key_raises_error(self): | ||
with pytest.raises(ValueError): | ||
UnstructuredFileConverter(api_url="https://api.unstructured.io/general/v0/general") | ||
|
||
@pytest.mark.usefixtures("set_env_variables") | ||
def test_to_dict(self): | ||
converter = UnstructuredFileConverter(api_key="test-api-key") | ||
converter = UnstructuredFileConverter() | ||
converter_dict = converter.to_dict() | ||
|
||
assert converter_dict == { | ||
"type": "haystack_integrations.components.converters.unstructured.converter.UnstructuredFileConverter", | ||
"init_parameters": { | ||
"api_url": "https://api.unstructured.io/general/v0/general", | ||
"api_key": {"env_vars": ["UNSTRUCTURED_API_KEY"], "strict": False, "type": "env_var"}, | ||
"document_creation_mode": "one-doc-per-file", | ||
"separator": "\n\n", | ||
"unstructured_kwargs": {}, | ||
|