Skip to content

Commit

Permalink
feat: do not set authorization header in document index when token is…
Browse files Browse the repository at this point in the history
… None

Task: IL-174
  • Loading branch information
Valentina Galata committed Jan 25, 2024
1 parent 169e762 commit 21f942e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ class DocumentIndexClient:

def __init__(
self,
token: str,
token: str | None,
base_document_index_url: str = "https://document-index.aleph-alpha.com",
) -> None:
self._base_document_index_url = base_document_index_url
self.headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {token}",
**({"Authorization": f"Bearer {token}"} if token is not None else {}),
}

def _raise_for_status(self, response: requests.Response) -> None:
Expand Down
16 changes: 16 additions & 0 deletions tests/connectors/document_index/test_document_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ def document_contents() -> DocumentContents:
return DocumentContents(contents=[text], metadata={"Some": "Metadata"})


@pytest.mark.internal
def test_document_index_sets_authorization_header_for_given_token() -> None:
token = "some-token"

document_index = DocumentIndexClient(token)

assert document_index.headers["Authorization"] == f"Bearer {token}"


@pytest.mark.internal
def test_document_index_sets_no_authorization_header_when_token_is_none() -> None:
document_index = DocumentIndexClient(None)

assert "Authorization" not in document_index.headers


@pytest.mark.internal
def test_document_index_lists_namespaces(document_index: DocumentIndexClient) -> None:
namespaces = document_index.list_namespaces()
Expand Down

0 comments on commit 21f942e

Please sign in to comment.