Skip to content

Commit

Permalink
added another unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
anisha1607 committed Jul 19, 2023
1 parent 4445cd1 commit 863b6b7
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions tests/unit_tests/controllers/test_agent_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_edit_agent_template_success(mock_get_user_org, mock_auth_db, mock_db):
# mock_agent_goals = AgentTemplateConfig()

# Create a mock edited agent configuration
mock_edited_agent_configs = {
mock_updated_agent_configs = {
"name": "Updated Agent Template",
"description": "Updated Description",
"agent_configs": {
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_edit_agent_template_success(mock_get_user_org, mock_auth_db, mock_db):


# Call the endpoint
response = client.put("agent_templates/update_agent_template/1", json=mock_edited_agent_configs)
response = client.put("agent_templates/update_agent_template/1", json=mock_updated_agent_configs)

assert response.status_code == 200

Expand Down Expand Up @@ -84,4 +84,44 @@ def test_edit_agent_template_failure(mock_get_user_org, mock_auth_db, mock_db):

# Verify: The database commit method should not have been called because the agent template was not found.
session_mock.commit.assert_not_called()
session_mock.flush.assert_not_called()
session_mock.flush.assert_not_called()


@patch('superagi.controllers.agent_template.db')
@patch('superagi.helper.auth.db')
@patch('superagi.helper.auth.get_user_organisation')
def test_edit_agent_template_with_new_config_success(mock_get_user_org, mock_auth_db, mock_db):
# Create a mock agent template
mock_agent_template = AgentTemplate(id=1, name="Test Agent Template", description="Test Description")

# Create a mock edited agent configuration
mock_updated_agent_configs = {
"name": "Updated Agent Template",
"description": "Updated Description",
"agent_configs": {
"new_config_key": "New config value" # This is a new config
}
}

# Mocking the user organisation
mock_get_user_org.return_value = MagicMock(id=1)

# Create a session mock
session_mock = MagicMock()
mock_db.session = session_mock
mock_db.session.query.return_value.filter.return_value.first.return_value = mock_agent_template
mock_db.session.commit.return_value = None
mock_db.session.add.return_value = None
mock_db.session.flush.return_value = None

# Call the endpoint
response = client.put("agent_templates/update_agent_template/1", json=mock_updated_agent_configs)

assert response.status_code == 200

# Verify changes in the mock agent template
assert mock_agent_template.name == "Updated Agent Template"
assert mock_agent_template.description == "Updated Description"

session_mock.commit.assert_called()
session_mock.flush.assert_called()

0 comments on commit 863b6b7

Please sign in to comment.