Skip to content

Commit

Permalink
added controller unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
luciferlinx101 committed Jul 4, 2023
1 parent 488d4fa commit b6d82ea
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/unit_tests/controllers/test_agent_execution_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from unittest.mock import patch

import pytest
from fastapi.testclient import TestClient

from main import app
from superagi.models.agent_execution_config import AgentExecutionConfiguration

client = TestClient(app)


@pytest.fixture
def mocks():
# Mock tool kit data for testing
mock_execution_config = AgentExecutionConfiguration(id=1, key="test_key", value="['test']")
return mock_execution_config


def test_get_agent_execution_configuration_success(mocks):
# Mock the database session and query functions
with patch('superagi.helper.auth.get_user_organisation') as mock_get_user_org, \
patch('superagi.controllers.agent_execution_config.db') as mock_db:

mock_execution_config = mocks
mock_db.session.query.return_value.filter.return_value.all.return_value = [mock_execution_config]

response = client.get("/agent_executions_configs/details/1")

assert response.status_code == 200
assert response.json() == {"test_key": ['test']}


def test_get_agent_execution_configuration_not_found():
with patch('main.check_auth') as mock_check_auth:
with patch('main.db') as mock_db:
mock_check_auth.return_value = True
mock_db.session.query.return_value.filter.return_value.all.return_value = []

response = client.get("/agent_executions_configs/details/1")

assert response.status_code == 404
assert response.json() == {"detail": "Agent Execution Configuration not found"}

0 comments on commit b6d82ea

Please sign in to comment.