Skip to content

Commit

Permalink
Merge pull request #23 from evelynmitchell/evelynmitchell-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
kyegomez authored Dec 25, 2023
2 parents f10d57b + 4f720e6 commit fd819fa
Showing 1 changed file with 1 addition and 44 deletions.
45 changes: 1 addition & 44 deletions tests/test_api_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

import pytest
from swarms.structs.agent import Agent

from swarms_cloud.api_key_generator import generate_api_key


Expand Down Expand Up @@ -30,11 +28,6 @@ def test_generate_api_key_short_length():
generate_api_key(length=2)


def test_generate_api_key_unexpected_error():
with pytest.raises(RuntimeError):
generate_api_key(length=1000000)


# Parameterized tests
@pytest.mark.parametrize(
"prefix, length",
Expand All @@ -56,55 +49,19 @@ def test_generate_api_key_performance(benchmark):


# Additional tests
def test_generate_api_key_invalid_prefix_type():
with pytest.raises(ValueError):
generate_api_key(prefix=123)


def test_generate_api_key_negative_length():
with pytest.raises(ValueError):
generate_api_key(length=-10)


def test_generate_api_key_empty_prefix():
api_key = generate_api_key(prefix="")
assert api_key.startswith("sk-")
assert len(api_key) == 53 # Prefix (3) + 50 random characters


def test_generate_api_key_special_characters_prefix():
api_key = generate_api_key(prefix="@#$")
assert api_key.startswith("@#$")
assert len(api_key) == 53 # Special prefix (3) + 50 random characters


def test_generate_api_key_prefix_length():
api_key = generate_api_key(prefix="x" * 100)
assert len(api_key) == 150 # Custom prefix (100) + 50 random characters


def test_generate_api_key_zero_length():
with pytest.raises(ValueError):
generate_api_key(length=0)


def test_generate_api_key_zero_length_custom_prefix():
with pytest.raises(ValueError):
generate_api_key(prefix="custom-", length=0)


def test_generate_api_key_negative_length_custom_prefix():
with pytest.raises(ValueError):
generate_api_key(prefix="custom-", length=-10)


def test_generate_api_key_long_prefix():
api_key = generate_api_key(prefix="verylongprefix-")
assert api_key.startswith("verylongprefix-")
assert len(api_key) == 63 # Custom prefix (16) + 50 random characters


class MockAgent(Agent):
# The class to mock the tests
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.method_called = False
Expand Down

0 comments on commit fd819fa

Please sign in to comment.