Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougollerenshaw committed Oct 10, 2024
1 parent 0b5a9a2 commit 8c67bbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
7 changes: 1 addition & 6 deletions tests/ui/test_chat_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from codeaide.utils.constants import (
AI_PROVIDERS,
DEFAULT_PROVIDER,
DEFAULT_MODEL,
MODEL_SWITCH_MESSAGE,
)

Expand Down Expand Up @@ -82,11 +81,7 @@ def test_model_switching(chat_window, mock_chat_handler, caplog):
test_provider = next(
provider for provider in AI_PROVIDERS.keys() if provider != DEFAULT_PROVIDER
)
test_model = next(
model
for model in AI_PROVIDERS[test_provider]["models"].keys()
if model != DEFAULT_MODEL
)
test_model = list(AI_PROVIDERS[test_provider]["models"].keys())[0]

window.provider_dropdown.setCurrentText(test_provider)
window.model_dropdown.setCurrentText(test_model)
Expand Down
23 changes: 12 additions & 11 deletions tests/utils/test_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
get_api_client,
)
from codeaide.utils.constants import (
DEFAULT_MODEL,
DEFAULT_PROVIDER,
SYSTEM_PROMPT,
AI_PROVIDERS,
)
Expand All @@ -28,8 +26,7 @@
pytest.mark.api_connection,
]

# Get the max_tokens value from the AI_PROVIDERS dictionary
MAX_TOKENS = AI_PROVIDERS[DEFAULT_PROVIDER]["models"][DEFAULT_MODEL]["max_tokens"]
MAX_TOKENS = 100 # Define this at the top of the file for use in tests


@pytest.fixture
Expand Down Expand Up @@ -222,12 +219,13 @@ def test_send_api_request_success_openai(self, mock_openai):
mock_client.chat.completions.create.return_value = mock_response
mock_openai.return_value = mock_client

model = list(AI_PROVIDERS["openai"]["models"].keys())[0]
result = send_api_request(
mock_client, conversation_history, MAX_TOKENS, DEFAULT_MODEL, "openai"
mock_client, conversation_history, MAX_TOKENS, model, "openai"
)

mock_client.chat.completions.create.assert_called_once_with(
model=DEFAULT_MODEL,
model=model,
max_tokens=MAX_TOKENS,
messages=[{"role": "system", "content": SYSTEM_PROMPT}]
+ conversation_history,
Expand All @@ -247,12 +245,13 @@ def test_send_api_request_empty_response(self, mock_anthropic):
mock_client.messages.create.return_value = mock_response
mock_anthropic.return_value = mock_client

model = list(AI_PROVIDERS["anthropic"]["models"].keys())[0]
result = send_api_request(
mock_client, conversation_history, MAX_TOKENS, DEFAULT_MODEL, "anthropic"
mock_client, conversation_history, MAX_TOKENS, model, "anthropic"
)

mock_client.messages.create.assert_called_once_with(
model=DEFAULT_MODEL,
model=model,
max_tokens=MAX_TOKENS,
messages=conversation_history,
system=SYSTEM_PROMPT,
Expand Down Expand Up @@ -283,11 +282,12 @@ def test_send_api_request_api_error(self, mock_anthropic_client):
body={"error": {"message": "API Error"}},
)

model = list(AI_PROVIDERS["anthropic"]["models"].keys())[0]
result = send_api_request(
mock_anthropic_client,
conversation_history,
MAX_TOKENS,
DEFAULT_MODEL,
model,
"anthropic",
)

Expand Down Expand Up @@ -318,16 +318,17 @@ def test_send_api_request_custom_max_tokens(self, mock_anthropic_client):
mock_response.content = [Mock(text="Hello! How can I assist you today?")]
mock_anthropic_client.messages.create.return_value = mock_response

model = list(AI_PROVIDERS["anthropic"]["models"].keys())[0]
result = send_api_request(
mock_anthropic_client,
conversation_history,
custom_max_tokens,
DEFAULT_MODEL,
model,
"anthropic",
)

mock_anthropic_client.messages.create.assert_called_once_with(
model=DEFAULT_MODEL,
model=model,
max_tokens=custom_max_tokens,
messages=conversation_history,
system=SYSTEM_PROMPT,
Expand Down

0 comments on commit 8c67bbf

Please sign in to comment.