-
Notifications
You must be signed in to change notification settings - Fork 2
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
adeelehsan
wants to merge
3
commits into
main
Choose a base branch
from
update-int-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Update int tests #50
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,5 +5,6 @@ poetry.toml | |
.ruff_cache/ | ||
|
||
.idea | ||
.env | ||
|
||
**/.ipynb_checkpoints |
This file contains hidden or 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,6 @@ | ||
from pathlib import Path | ||
from dotenv import load_dotenv | ||
|
||
# Load environment variables from .env file | ||
env_path = Path(__file__).parent / '.env' | ||
load_dotenv(dotenv_path=env_path) |
File renamed without changes.
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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