Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k-shlomi committed Aug 21, 2023
1 parent b9f106f commit 564cf44
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tests/test_clients.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from src.shared.clients.frontegg import get_jwt_token, FRONTEGG_AUTH_URL
from src.shared.clients.github import get_repos_from_github
from src.shared.clients.github import get_teams_from_github_topics
from src.shared.clients.jit import list_assets, get_existing_teams, create_teams, add_teams_to_asset
from src.shared.models import RepositoryDetails, BaseTeam, Asset
from src.shared.models import RepositoryDetails, BaseTeam, Asset, TeamStructure, TeamTemplate, Resource


class MockRepo:
Expand All @@ -18,13 +18,16 @@ def get_topics(self):
@pytest.mark.parametrize(
"mock_repos, expected_result",
[
([], []),
([MockRepo("repo1", [])], []),
([], TeamStructure(teams=[])),
([MockRepo("repo1", [])], TeamStructure(teams=[])),
([MockRepo("repo1", ["topic1"]), MockRepo("repo2", ["topic2"])],
[RepositoryDetails(name="repo1", topics=["topic1"]), RepositoryDetails(name="repo2", topics=["topic2"])]),
TeamStructure(teams=[
TeamTemplate(name="topic1", members=[], resources=[Resource(type="github_repo", name="repo1")]),
TeamTemplate(name="topic2", members=[], resources=[Resource(type="github_repo", name="repo2")])
])),
]
)
def test_get_repos_from_github(mock_repos, expected_result, mocker):
def test_get_teams_from_github_topics(mock_repos, expected_result, mocker):
# Mocking Github instance methods
github_mock = mocker.Mock()
organization_mock = mocker.Mock()
Expand All @@ -34,18 +37,18 @@ def test_get_repos_from_github(mock_repos, expected_result, mocker):
mocker.patch("src.shared.clients.github.Github", return_value=github_mock) # Adjust the import path.

# Run the function
repositories = get_repos_from_github()
repositories = get_teams_from_github_topics()

assert repositories == expected_result


def test_get_repos_from_github_exception(mocker):
def test_get_teams_from_github_topics_exception(mocker):
# Mocking Github to raise an exception
mocker.patch("src.shared.clients.github.Github", side_effect=Exception("Sample exception")) # Adjust the import path.

# Test that the function logs an error and returns None
result = get_repos_from_github()
assert result is None
result = get_teams_from_github_topics()
assert result == TeamStructure(teams=[])


@pytest.mark.parametrize(
Expand Down

0 comments on commit 564cf44

Please sign in to comment.