Skip to content

Commit

Permalink
[CLEANUP OPERATION]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Dec 19, 2023
1 parent 9a5ee19 commit 298a536
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 96 deletions.
Empty file removed errors.txt
Empty file.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "swarms-cloud"
version = "0.0.8"
version = "0.1.0"
description = "Swarms Cloud - Pytorch"
license = "MIT"
authors = ["Kye Gomez <[email protected]>"]
Expand Down
2 changes: 0 additions & 2 deletions swarms_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from swarms_cloud.api_key_generator import generate_api_key
from swarms_cloud.func_api_wrapper import SwarmCloud
from swarms_cloud.main import agent_api_wrapper
from swarms_cloud.rate_limiter import rate_limiter
from swarms_cloud.sky_api import SkyInterface

__all__ = [
"agent_api_wrapper",
"rate_limiter",
"SwarmCloud",
"generate_api_key",
Expand Down
93 changes: 0 additions & 93 deletions tests/test_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from swarms.structs.agent import Agent

from swarms_cloud.api_key_generator import generate_api_key
from swarms_cloud.main import agent_api_wrapper


# Basic tests
Expand Down Expand Up @@ -115,95 +114,3 @@ def __init__(self, *args, **kwargs):
def mock_method(self):
self.method_called = True
return "Hello World"


@pytest.mark.parametrize(
"http_method",
["get", "post"],
)
def test_decorator_registers_endpoint(http_method):
# Arrange
app = FastAPI()
path = "/agent"

# Act
@agent_api_wrapper(MockAgent, app, path, http_method=http_method)
def mock_method():
return "Hello World"

# Assert
if http_method == "get":
assert "GET" in app.routes
else:
assert "POST" in app.routes

assert path in app.routes


def test_decorator_logs_correctly():
# Arrange
app = FastAPI()
path = "/agent"
logger = MagicMock()

# Act
@agent_api_wrapper(MockAgent, app, path, logging=True)
def mock_method():
return "Hello World"

# Assert
assert logger.info.call_count == 3
assert logger.error.call_count == 0


def test_endpoint_wrapper_calls_agent_method():
# Arrange
app = FastAPI()
path = "/agent"
agent_instance = MockAgent()

# Act
@agent_api_wrapper(MockAgent, app, path)
def mock_method():
return "Hello World"

# Assert
assert agent_instance.mock_method.called


def test_endpoint_wrapper_returns_result():
# Arrange
app = FastAPI()
path = "/agent"
MockAgent()
expected_result = "Hello World"

# Act
@agent_api_wrapper(MockAgent, app, path)
def mock_method():
return expected_result

# Assert
response = app.get(path)
assert response.status_code == 200
assert response.json() == expected_result


def test_endpoint_wrapper_raises_exception():
# Arrange
app = FastAPI()
path = "/agent"
MockAgent()
expected_error = Exception("Test error")

# Act
@agent_api_wrapper(MockAgent, app, path)
def mock_method():
raise expected_error

# Assert
with pytest.raises(HTTPException) as error:
app.get(path)

assert error.value.status_code == 500
assert error.value.detail == str(expected_error)

0 comments on commit 298a536

Please sign in to comment.