From 9ad9667b8b15c9640ba6fe51d230a4f080470520 Mon Sep 17 00:00:00 2001 From: Enrico Olivelli Date: Thu, 7 Dec 2023 09:43:19 +0100 Subject: [PATCH] Restore authentication tests (#94) --- ragstack-e2e-tests/e2e_tests/test_astra.py | 65 +++++++++++----------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/ragstack-e2e-tests/e2e_tests/test_astra.py b/ragstack-e2e-tests/e2e_tests/test_astra.py index 59833a339..8fcb68ebc 100644 --- a/ragstack-e2e-tests/e2e_tests/test_astra.py +++ b/ragstack-e2e-tests/e2e_tests/test_astra.py @@ -4,6 +4,7 @@ from astrapy.db import AstraDB as LibAstraDB import pytest +from httpx import ConnectError from langchain.schema.embeddings import Embeddings from langchain.schema.vectorstore import VectorStore @@ -68,38 +69,38 @@ def test_ingest_errors(environment): ) -# def test_wrong_connection_parameters(): -# # This is expected to be a valid endpoint, because we want to test an AUTHENTICATION error -# api_endpoint = get_required_env("ASTRA_PROD_DB_ENDPOINT") -# -# try: -# AstraDB( -# collection_name="something", -# embedding=init_embeddings(), -# token="xxxxx", -# # we assume that post 1234 is not open locally -# api_endpoint="https://locahost:1234", -# ) -# pytest.fail("Should have thrown exception") -# except ConnectError as e: -# print("Error:", e) -# pass -# -# try: -# print("api_endpoint:", api_endpoint) -# AstraDB( -# collection_name="something", -# embedding=init_embeddings(), -# token="this-is-a-wrong-token", -# api_endpoint=api_endpoint, -# ) -# pytest.fail("Should have thrown exception") -# except ValueError as e: -# print("Error:", e) -# if "AUTHENTICATION ERROR" not in e.args[0]: -# pytest.fail( -# f"Should have thrown ValueError with AUTHENTICATION ERROR but it was {e}" -# ) +def test_wrong_connection_parameters(): + # This is expected to be a valid endpoint, because we want to test an AUTHENTICATION error + api_endpoint = get_required_env("ASTRA_PROD_DB_ENDPOINT") + + try: + AstraDB( + collection_name="something", + embedding=init_embeddings(), + token="xxxxx", + # we assume that post 1234 is not open locally + api_endpoint="https://locahost:1234", + ) + pytest.fail("Should have thrown exception") + except ConnectError as e: + print("Error:", e) + pass + + try: + print("api_endpoint:", api_endpoint) + AstraDB( + collection_name="something", + embedding=init_embeddings(), + token="this-is-a-wrong-token", + api_endpoint=api_endpoint, + ) + pytest.fail("Should have thrown exception") + except ValueError as e: + print("Error:", e) + if "AUTHENTICATION ERROR" not in e.args[0]: + pytest.fail( + f"Should have thrown ValueError with AUTHENTICATION ERROR but it was {e}" + ) def test_basic_metadata_filtering(environment):