Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
test: Adds unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Dec 11, 2023
1 parent 112060d commit a0de0a4
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 4 deletions.
26 changes: 26 additions & 0 deletions src/tests/endpoints/test_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,29 @@ async def test_add_repo_to_waitlist(
assert response.status_code == status_code, print(response.json())
if isinstance(status_detail, str):
assert response.json()["detail"] == status_detail


@pytest.mark.parametrize(
("user_idx", "repo_id", "status_code", "status_detail"),
[
(None, 12345, 401, "Not authenticated"),
(0, 100, 404, "Not Found"),
],
)
@pytest.mark.asyncio()
async def test_parse_guidelines_from_github(
async_client: AsyncClient,
guideline_session: AsyncSession,
user_idx: Union[int, None],
repo_id: int,
status_code: int,
status_detail: Union[str, None],
):
auth = None
if isinstance(user_idx, int):
auth = await pytest.get_token(USER_TABLE[user_idx]["id"], USER_TABLE[user_idx]["scope"].split())

response = await async_client.post(f"/repos/{repo_id}/parse", headers=auth)
assert response.status_code == status_code, print(response.json())
if isinstance(status_detail, str):
assert response.json()["detail"] == status_detail
97 changes: 93 additions & 4 deletions src/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from fastapi import HTTPException

from app.services.github import GitHubClient
from app.services.utils import execute_in_parallel


@pytest.mark.parametrize(
Expand Down Expand Up @@ -105,20 +106,108 @@ async def test_githubclient_list_pulls(repo_name, status_code, status_detail):
github_client.list_pulls(repo_name)


@pytest.mark.parametrize(
("repo_name", "issue_number", "status_code", "status_detail"),
[
("frgfm/hola", 1, 404, "Not Found"),
("frgfm/torch-cam", 181, 200, None),
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_comments_from_issue(repo_name, issue_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_comments_from_issue(issue_number, repo_name)
assert isinstance(response, list)
assert all(isinstance(elt, dict) for elt in response)
else:
with pytest.raises(HTTPException):
github_client.list_comments_from_issue(issue_number, repo_name)


@pytest.mark.parametrize(
("repo_name", "pull_number", "status_code", "status_detail"),
[
("frgfm/hola", 1, 404, "Not Found"),
("frgfm/Holocron", 279, 200, None),
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_reviews_from_pull(repo_name, pull_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_reviews_from_pull(repo_name, pull_number)
assert isinstance(response, list)
assert all(isinstance(elt, dict) for elt in response)
else:
with pytest.raises(HTTPException):
github_client.list_reviews_from_pull(repo_name, pull_number)


@pytest.mark.parametrize(
("repo_name", "pull_number", "status_code", "status_detail"),
[
("frgfm/hola", 1, 404, "Not Found"),
("frgfm/Holocron", 279, 200, None),
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_review_comments_from_pull(repo_name, pull_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_review_comments_from_pull(pull_number, repo_name)
assert isinstance(response, list)
assert all(isinstance(elt, dict) for elt in response)
else:
with pytest.raises(HTTPException):
github_client.list_review_comments_from_pull(pull_number, repo_name)


@pytest.mark.parametrize(
("repo_name", "status_code", "status_detail"),
[
("frgfm/hola", 404, "Not Found"),
("frgfm/torch-cam", 200, None),
("frgfm/Holocron", 200, None),
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_review_comments(repo_name, status_code, status_detail):
async def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_review_comments(repo_name)
response = github_client.fetch_reviews_from_repo(repo_name, num_pulls=1)
assert isinstance(response, list)
assert all(isinstance(elt, dict) for elt in response)
else:
with pytest.raises(HTTPException):
github_client.list_review_comments(repo_name)
github_client.fetch_reviews_from_repo(repo_name, num_pulls=1)


@pytest.mark.parametrize(
("repo_name", "status_code", "status_detail"),
[
("frgfm/hola", 404, "Not Found"),
("frgfm/Holocron", 200, None),
],
)
@pytest.mark.asyncio()
async def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.fetch_pull_comments_from_repo(repo_name, num_pulls=1)
assert isinstance(response, list)
assert all(isinstance(elt, dict) for elt in response)
else:
with pytest.raises(HTTPException):
github_client.fetch_pull_comments_from_repo(repo_name, num_pulls=1)


@pytest.mark.parametrize(
("func", "arr", "output"),
[
(lambda x: x**2, [1, 2, 3], [1, 4, 9]),
],
)
@pytest.mark.asyncio()
async def test_execute_in_parallel(func, arr, output):
assert list(execute_in_parallel(func, arr, num_threads=1)) == output
assert list(execute_in_parallel(func, arr, num_threads=2)) == output

0 comments on commit a0de0a4

Please sign in to comment.