-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for agent code fetcher
- Loading branch information
Showing
4 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import shutil | ||
from pathlib import Path | ||
from unittest import IsolatedAsyncioTestCase | ||
|
||
import aiohttp | ||
|
||
import agent_code_fetcher | ||
|
||
CODE_ID = "a09f660a-e0e6-41ac-b721-f8ece8e71f33" | ||
HTTP_BASE_URL = "https://api.dev.saiblo.net" | ||
|
||
|
||
class TestAgentCodeFetcher(IsolatedAsyncioTestCase): | ||
_session: aiohttp.ClientSession | ||
|
||
async def asyncSetUp(self) -> None: | ||
shutil.rmtree( | ||
Path("data"), | ||
ignore_errors=True, | ||
) | ||
|
||
self._session = aiohttp.ClientSession(HTTP_BASE_URL) | ||
|
||
def tearDown(self) -> None: | ||
shutil.rmtree( | ||
Path("data"), | ||
ignore_errors=True, | ||
) | ||
|
||
async def test_clean_no_dir(self): | ||
# Arrange. | ||
fetcher = agent_code_fetcher.AgentCodeFetcher(self._session) | ||
|
||
# Act. | ||
await fetcher.clean() | ||
|
||
# Assert. | ||
self.assertTrue(Path("data/agent_code").is_dir()) | ||
|
||
async def test_clean_dir_exists(self): | ||
# Arrange. | ||
Path("data/agent_code").mkdir(parents=True, exist_ok=True) | ||
fetcher = agent_code_fetcher.AgentCodeFetcher(self._session) | ||
|
||
# Act. | ||
await fetcher.clean() | ||
|
||
# Assert. | ||
self.assertTrue( | ||
Path("data/agent_code").is_dir(), | ||
) | ||
|
||
async def test_fetch_cached(self): | ||
# Arrange. | ||
Path("data/agent_code").mkdir(parents=True, exist_ok=True) | ||
path = Path("data/agent_code") / f"{CODE_ID}.tar" | ||
path.touch() | ||
fetcher = agent_code_fetcher.AgentCodeFetcher(self._session) | ||
|
||
# Act. | ||
result = await fetcher.fetch(CODE_ID) | ||
|
||
# Assert. | ||
self.assertEqual(path.absolute(), result) | ||
|
||
async def test_fetch_not_cached(self): | ||
# Arrange. | ||
path = Path("data/agent_code") / f"{CODE_ID}.tar" | ||
fetcher = agent_code_fetcher.AgentCodeFetcher(self._session) | ||
|
||
# Act. | ||
result = await fetcher.fetch(CODE_ID) | ||
|
||
# Assert. | ||
self.assertEqual(path.absolute(), result) | ||
self.assertTrue(path.is_file()) | ||
|
||
async def test_list(self): | ||
# Arrange. | ||
Path("data/agent_code").mkdir(parents=True, exist_ok=True) | ||
path = Path("data/agent_code") / f"{CODE_ID}.tar" | ||
path.touch() | ||
fetcher = agent_code_fetcher.AgentCodeFetcher(self._session) | ||
|
||
# Act. | ||
result = await fetcher.list() | ||
|
||
# Assert. | ||
self.assertEqual({CODE_ID: path.absolute()}, result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters