Skip to content

Commit

Permalink
Merge pull request #4 from airtai/check-mailchimp-endpoints
Browse files Browse the repository at this point in the history
Test few mailchimp endpoints
  • Loading branch information
rjambrecic authored Nov 13, 2024
2 parents 0856605 + 850c2f7 commit 8d2f875
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ disallow_any_unimported = false
[tool.ruff]
fix = true
line-length = 88
include = ["mailchimp_api/**/*.py", "mailchimp_api/**/*.pyi", "pyproject.toml"]
include = ["mailchimp_api/**/*.py", "mailchimp_api/**/*.pyi", "tests/**/*.py", "pyproject.toml"]
exclude = []

[tool.ruff.lint]
Expand Down
79 changes: 56 additions & 23 deletions tests/test_mailchimp_openapi_spec.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
from collections.abc import Iterator
from unittest.mock import MagicMock, patch

import pytest
from autogen import UserProxyAgent
from fastagency.api.openapi.client import OpenAPI

from mailchimp_api.utils.create_api import create_api

from unittest.mock import MagicMock, patch
import pytest

@pytest.fixture(scope="class")
def setup_api() -> OpenAPI:
return create_api(mailchimp_api_key="test Key") # pragma: allowlist secret


class TestMailchimpOpenapiSpec:
@pytest.fixture(autouse=True)
def setup(
def _setup(
self,
) -> Iterator[None]:
self.api = create_api(mailchimp_api_key="test Key")
yield

) -> None:
self.headers = {
"Content-Type": "application/json",
"Authorization": "Basic YW55c3RyaW5nOnRlc3QgS2V5",
}
return

def test_create_api(self) -> None:
assert isinstance(self.api, OpenAPI)
url = self.api.servers[0]["url"]
def test_create_api(self, setup_api: OpenAPI) -> None:
assert isinstance(setup_api, OpenAPI)
url = setup_api.servers[0]["url"]
assert url == "https://us14.api.mailchimp.com/3.0", url

@patch("fastagency.api.openapi.client.requests.get")
def test_mailchimp_api(
def _test_mailchimp_api(
self,
mock_post: MagicMock,
setup_api: OpenAPI,
function: str,
) -> None:
mock_response = MagicMock()
mock_response.status_code = 200
Expand All @@ -38,19 +45,45 @@ def test_mailchimp_api(
code_execution_config=False,
)

functions = ["get_ping"]
self.api._register_for_execution(user_proxy, functions=functions)
setup_api._register_for_execution(user_proxy, functions=[function])

assert tuple(user_proxy._function_map.keys()) == (function,)

assert tuple(user_proxy._function_map.keys()) == ("get_ping",)
func = user_proxy._function_map[function]
func(body={})

get_ping = user_proxy._function_map["get_ping"]
get_ping(body={})
@patch("fastagency.api.openapi.client.requests.get")
def test_mailchimp_api_ping(
self,
mock_post: MagicMock,
setup_api: OpenAPI,
) -> None:
self._test_mailchimp_api(
mock_post=mock_post,
setup_api=setup_api,
function="get_ping",
)

mock_post.assert_called_once_with(
f"{setup_api.servers[0]['url']}/ping",
params={},
headers=self.headers,
)

@patch("fastagency.api.openapi.client.requests.get")
def test_mailchimp_api_get_lists(
self,
mock_post: MagicMock,
setup_api: OpenAPI,
) -> None:
self._test_mailchimp_api(
mock_post=mock_post,
setup_api=setup_api,
function="get_lists",
)

mock_post.assert_called_once_with(
f"{self.api.servers[0]['url']}/ping",
f"{setup_api.servers[0]['url']}/lists",
params={},
headers={
'Content-Type': 'application/json',
'Authorization': 'Basic YW55c3RyaW5nOnRlc3QgS2V5',
},
headers=self.headers,
)

0 comments on commit 8d2f875

Please sign in to comment.