Skip to content

Commit

Permalink
✨ feat: add async tests for project
Browse files Browse the repository at this point in the history
  • Loading branch information
guptadev21 committed Dec 2, 2024
1 parent e78652f commit 3e84554
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 1 deletion.
99 changes: 99 additions & 0 deletions tests/async_tests/test_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import pytest
import pytest_asyncio

Check failure on line 2 in tests/async_tests/test_project.py

View workflow job for this annotation

GitHub Actions / Perform checks (3.10)

Ruff (F401)

tests/async_tests/test_project.py:2:8: F401 `pytest_asyncio` imported but unused
import httpx
from munch import Munch
from asyncmock import AsyncMock

from tests.utils.test_util import (
async_client as client, # noqa: F401
project_body,
)


@pytest.mark.asyncio
async def test_list_projects_success(client, mocker: AsyncMock): # noqa: F811
mock_get = mocker.patch("httpx.AsyncClient.get")

mock_get.return_value = httpx.Response(
status_code=200,
json={
"metadata": {"continue": 1},
"items": [{"name": "test-project", "guid": "mock_project_guid"}],
},
)

response = await client.list_projects()

assert isinstance(response, Munch)
assert response["items"] == [{"name": "test-project", "guid": "mock_project_guid"}]


@pytest.mark.asyncio
async def test_create_project_success(client, mocker: AsyncMock):

Check failure on line 32 in tests/async_tests/test_project.py

View workflow job for this annotation

GitHub Actions / Perform checks (3.10)

Ruff (F811)

tests/async_tests/test_project.py:32:39: F811 Redefinition of unused `client` from line 8
mock_post = mocker.patch("httpx.AsyncClient.post")

mock_post.return_value = httpx.Response(
status_code=200,
json={
"kind": "Project",
"metadata": {"name": "test-project", "guid": "mock_project_guid"},
"spec": {
"users": [
{"userGUID": "mock_user_guid", "emailID": "[email protected]"}
]
},
},
)

response = await client.create_project(project_body)

assert isinstance(response, Munch)
assert response["metadata"]["guid"] == "mock_project_guid"

@pytest.mark.asyncio
async def test_get_project_success(client, mocker: AsyncMock):

Check failure on line 54 in tests/async_tests/test_project.py

View workflow job for this annotation

GitHub Actions / Perform checks (3.10)

Ruff (F811)

tests/async_tests/test_project.py:54:36: F811 Redefinition of unused `client` from line 8
mock_get = mocker.patch("httpx.AsyncClient.get")

mock_get.return_value = httpx.Response(
status_code=200,
json={
"kind": "Project",
"metadata": {"name": "test-project", "guid": "mock_project_guid"},
}
)

response = await client.get_project("mock_project_guid")

assert isinstance(response, Munch)
assert response["metadata"]["guid"] == "mock_project_guid"

@pytest.mark.asyncio
async def test_update_project_success(client, mocker: AsyncMock):

Check failure on line 71 in tests/async_tests/test_project.py

View workflow job for this annotation

GitHub Actions / Perform checks (3.10)

Ruff (F811)

tests/async_tests/test_project.py:71:39: F811 Redefinition of unused `client` from line 8
mock_put = mocker.patch("httpx.AsyncClient.put")

mock_put.return_value = httpx.Response(
status_code=200,
json={
"kind": "Project",
"metadata": {"name": "test-project", "guid": "mock_project_guid"},
}
)

response = await client.update_project("mock_project_guid", project_body)

assert isinstance(response, Munch)
assert response["metadata"]["guid"] == "mock_project_guid"

@pytest.mark.asyncio
async def test_delete_project_success(client, mocker: AsyncMock):

Check failure on line 88 in tests/async_tests/test_project.py

View workflow job for this annotation

GitHub Actions / Perform checks (3.10)

Ruff (F811)

tests/async_tests/test_project.py:88:39: F811 Redefinition of unused `client` from line 8
mock_delete = mocker.patch("httpx.AsyncClient.delete")

mock_delete.return_value = httpx.Response(
status_code=200,
json={"success": True}
)

response = await client.delete_project("mock_project_guid")

assert isinstance(response, Munch)
assert response["success"] is True
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 11 additions & 1 deletion tests/utils/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from rapyuta_io_sdk_v2 import Client, Configuration
from rapyuta_io_sdk_v2 import Client, Configuration, AsyncClient


# Fixture to initialize the Client
Expand All @@ -14,6 +14,16 @@ def client():
return client


@pytest.fixture
def async_client():
client = AsyncClient()
client.config.hosts["v2api_host"] = "https://mock-api.rapyuta.io"
client.auth_token = "mock_token"
client.organization_guid = "mock_org_guid"
client.project = "mock_project_guid"
return client


@pytest.fixture
def mock_response_project():
return {
Expand Down

0 comments on commit 3e84554

Please sign in to comment.