Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

test(e2e): move openai client to fixture #953

Merged
Merged
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
12 changes: 12 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from openai import OpenAI

from .utils import create_test_user


@pytest.fixture(scope="module")
def client():
return OpenAI(
base_url="https://leapfrogai-api.uds.dev/openai/v1", api_key=create_test_user()
)
12 changes: 3 additions & 9 deletions tests/e2e/test_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
import pytest
from openai import InternalServerError, OpenAI

from .utils import create_test_user

client = OpenAI(
base_url="https://leapfrogai-api.uds.dev/openai/v1", api_key=create_test_user()
)

model_name = "llama-cpp-python"


def test_chat_completions():
def test_chat_completions(client: OpenAI):
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is your name?"},
Expand All @@ -28,7 +22,7 @@ def test_chat_completions():
assert len(chat_completion.choices[0].message.content) < 500


def test_embeddings():
def test_embeddings(client: OpenAI):
with pytest.raises(InternalServerError) as excinfo:
client.embeddings.create(
model=model_name,
Expand All @@ -37,7 +31,7 @@ def test_embeddings():
assert str(excinfo.value) == "Internal Server Error"


def test_transcriptions():
def test_transcriptions(client: OpenAI):
with pytest.raises(InternalServerError) as excinfo:
client.audio.transcriptions.create(
model=model_name, file=Path("tests/data/0min12sec.wav")
Expand Down
14 changes: 4 additions & 10 deletions tests/e2e/test_text_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
import pytest
from openai import InternalServerError, OpenAI

from .utils import create_test_user

client = OpenAI(
base_url="https://leapfrogai-api.uds.dev/openai/v1", api_key=create_test_user()
)

model_name = "text-embeddings"


def test_completions():
def test_completions(client: OpenAI):
with pytest.raises(InternalServerError) as excinfo:
client.completions.create(
model=model_name,
Expand All @@ -21,7 +15,7 @@ def test_completions():
assert str(excinfo.value) == "Internal Server Error"


def test_chat_completions():
def test_chat_completions(client: OpenAI):
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "This should result in a failure"},
Expand All @@ -32,7 +26,7 @@ def test_chat_completions():
assert str(excinfo.value) == "Internal Server Error"


def test_embeddings():
def test_embeddings(client: OpenAI):
embedding_response = client.embeddings.create(
model=model_name,
input="This should result in a failure",
Expand All @@ -44,7 +38,7 @@ def test_embeddings():
assert len(embedding_response.data[0].embedding) < 1000


def test_transcriptions():
def test_transcriptions(client: OpenAI):
with pytest.raises(InternalServerError) as excinfo:
client.audio.transcriptions.create(
model=model_name, file=Path("tests/data/0min12sec.wav")
Expand Down
16 changes: 5 additions & 11 deletions tests/e2e/test_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
from openai import InternalServerError, OpenAI
import unicodedata

from .utils import create_test_user

client = OpenAI(
base_url="https://leapfrogai-api.uds.dev/openai/v1", api_key=create_test_user()
)


def test_completions():
def test_completions(client: OpenAI):
with pytest.raises(InternalServerError) as excinfo:
client.completions.create(
model="whisper",
Expand All @@ -21,7 +15,7 @@ def test_completions():
assert str(excinfo.value) == "Internal Server Error"


def test_chat_completions():
def test_chat_completions(client: OpenAI):
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "This should result in a failure"},
Expand All @@ -32,7 +26,7 @@ def test_chat_completions():
assert str(excinfo.value) == "Internal Server Error"


def test_embeddings():
def test_embeddings(client: OpenAI):
with pytest.raises(InternalServerError) as excinfo:
client.embeddings.create(
model="whisper",
Expand All @@ -41,7 +35,7 @@ def test_embeddings():
assert str(excinfo.value) == "Internal Server Error"


def test_transcriptions():
def test_transcriptions(client: OpenAI):
transcription = client.audio.transcriptions.create(
model="whisper",
file=Path("tests/data/0min12sec.wav"),
Expand All @@ -56,7 +50,7 @@ def test_transcriptions():
assert len(transcription.text) < 500, "The transcription should not be too long"


def test_translations():
def test_translations(client: OpenAI):
translation = client.audio.translations.create(
model="whisper",
file=Path("tests/data/arabic-audio.wav"),
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import json
import os

import pytest
import requests

# This is the anon_key for supabase, it provides access to the endpoints that would otherwise be inaccessible
ANON_KEY = os.environ["ANON_KEY"]

ANON_KEY = os.getenv("ANON_KEY")
DEFAULT_TEST_EMAIL = "fakeuser1@test.com"
DEFAULT_TEST_PASSWORD = "password"

Expand Down
Loading