Skip to content

Update int tests #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ CONFIGURATION.md
resources/

src/vectara/types/search_corpora_parameters.py # do not remove
src/vectara/corpora/types/search_corpus_parameters.py # do not remove
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ poetry.toml
.ruff_cache/

.idea
.env

**/.ipynb_checkpoints
6 changes: 6 additions & 0 deletions int_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pathlib import Path
from dotenv import load_dotenv

# Load environment variables from .env file
env_path = Path(__file__).parent / '.env'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should .env include for the tests to path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vectara API key to run the tests

load_dotenv(dotenv_path=env_path)
File renamed without changes.
88 changes: 88 additions & 0 deletions int_tests/managers/test_api_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import unittest
import os

from vectara import Vectara


class TestApiKeys(unittest.TestCase):
client = None
corpus_name = None
corpus_key = None
created_api_keys = None

@classmethod
def setUpClass(cls):
api_key = os.getenv("VECTARA_API_KEY")
if not api_key:
raise ValueError("VECTARA_API_KEY not found in environment variables or .env file")

cls.client = Vectara(api_key=api_key)
cls.corpus_name = "test-api-keys"
cls.corpus_key = cls.corpus_name
cls.created_api_keys = set()

# Create corpus
response = cls.client.corpora.create(name=cls.corpus_name, key=cls.corpus_key)
cls.key = response.key

def _create_api_key(self, name="test-key", api_key_role="serving"):
"""Helper method to create an API key with given parameters."""
response = self.client.api_keys.create(
name=name,
api_key_role=api_key_role,
corpus_keys=[self.key]
)
self.created_api_keys.add(response.id)
return response

def test_create_api_key(self):
response = self._create_api_key()
self.assertEqual(response.name, "test-key")
self.assertEqual(response.api_key_role, "serving")

def test_delete_api_key(self):
create_response = self._create_api_key()
delete_response = self.client.api_keys.delete(create_response.id)
self.assertIsNone(delete_response)
self.created_api_keys.remove(create_response.id)

def test_get_api_key(self):
create_response = self._create_api_key()
get_response = self.client.api_keys.get(create_response.id)
self.assertEqual(get_response.name, create_response.name)

def test_update_api_key(self):
create_response = self._create_api_key()
update_response = self.client.api_keys.update(create_response.id, enabled=False)
self.assertEqual(update_response.enabled, False)

def test_list_api_keys(self):
# Create two test keys
created_keys = []
for index in range(2):
create_response = self._create_api_key(name=f"test-key-{index}")
created_keys.append(create_response.name)

# Get all keys and verify our created keys are in the list
all_keys = list(self.client.api_keys.list())

# Verify our created keys are in the list
for key in all_keys:
if key.name in created_keys:
self.assertIn(key.name, [name for name in created_keys])

@classmethod
def tearDownClass(cls):
"""Clean up all test resources."""
# Clean up created API keys
for api_key_id in cls.created_api_keys:
try:
cls.client.api_keys.delete(api_key_id)
except Exception:
pass

# Clean up corpus
try:
cls.client.corpora.delete(cls.corpus_key)
except Exception:
pass
76 changes: 76 additions & 0 deletions int_tests/managers/test_app_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import os
import unittest

from vectara import Vectara


class TestAppClient(unittest.TestCase):
client = None
created_clients = None

@classmethod
def setUpClass(cls):
api_key = os.getenv("VECTARA_API_KEY")
if not api_key:
raise ValueError("VECTARA_API_KEY not found in environment variables or .env file")
cls.client = Vectara(api_key=api_key)
cls.created_clients = set()

def _create_app_client(self, name="test-client", api_roles=["owner"]):
"""Helper method to create an app client with given parameters."""
response = self.client.app_clients.create(name=name, api_roles=api_roles)
self.created_clients.add(response.id)
return response

def test_create_app_client(self):
response = self._create_app_client()
self.assertEqual(response.name, "test-client")
self.assertIsNotNone(response.client_id)
self.assertIsNotNone(response.client_secret)

def test_get_app_client(self):
create_response = self._create_app_client()
get_response = self.client.app_clients.get(create_response.id)

self.assertEqual(get_response.client_id, create_response.client_id)
self.assertEqual(get_response.client_secret, create_response.client_secret)

def test_delete_app_client(self):
create_response = self._create_app_client()
del_response = self.client.app_clients.delete(create_response.id)
self.assertIsNone(del_response)
self.created_clients.remove(create_response.id)

def test_update_app_client(self):
create_response = self._create_app_client()
update_response = self.client.app_clients.update(
create_response.id,
api_roles=["owner", "administrator"],
description="test client"
)

self.assertEqual(update_response.api_roles, ["owner", "administrator"])
self.assertEqual(update_response.description, "test client")

def test_list_app_clients(self):
# Create two test clients
created_clients = []
for index in range(2):
create_response = self._create_app_client(name=f"test-client-{index}")
created_clients.append(create_response)

created_client_ids = {client.id for client in created_clients}

# Verify our created clients are in the list
for client in self.client.app_clients.list().items:
if client.id in created_client_ids:
self.assertIn(client.name, [c.name for c in created_clients])

@classmethod
def tearDownClass(cls):
"""Clean up all test resources."""
for client_id in cls.created_clients:
try:
cls.client.app_clients.delete(client_id)
except Exception:
pass
46 changes: 46 additions & 0 deletions int_tests/managers/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import unittest
import os

from vectara import Vectara


class TestAuthManager(unittest.TestCase):
client = None
client_id = None
client_secret = None
created_clients = None

@classmethod
def setUpClass(cls):
api_key = os.getenv("VECTARA_API_KEY")
if not api_key:
raise ValueError("VECTARA_API_KEY not found in environment variables or .env file")

cls.client = Vectara(api_key=api_key)
cls.created_clients = set()

# Create test client
response = cls.client.app_clients.create(name="test-client", api_roles=["owner"])
cls.client_id = response.client_id
cls.client_secret = response.client_secret
cls.created_clients.add(response.id)

def test_get_access_token(self):
response = self.client.auth.get_token(
client_id=self.client_id,
client_secret=self.client_secret,
grant_type="client_credentials"
)

self.assertIsNotNone(response.access_token)
self.assertIsNotNone(response.token_type)
self.assertIsNotNone(response.expires_in)

@classmethod
def tearDownClass(cls):
"""Clean up all test resources."""
for client_id in cls.created_clients:
try:
cls.client.app_clients.delete(client_id)
except Exception:
pass
Loading
Loading