Skip to content

chore: fix tests setup #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Required to run tests
GITGUARDIAN_API_KEY=----fillme----
# This is used to select the member that will be deleted in the tests
DELETE_MEMBER_EMAIL=----fillme----
6 changes: 3 additions & 3 deletions scripts/setup_test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
PaginatedDataType = TypeVar("PaginatedDataType", bound=FromDictWithBase)

MIN_NB_TEAM = 2
MIN_NB_MEMBER = 3 # 1 owner, 1 manager and at least one member
MIN_NB_MEMBER = 4 # 1 owner, 1 manager and at least two members
MIN_NB_TEAM_MEMBER = 2
# This is the team that is created in the tests, it should be deleted before we run the tests
PYGITGUARDIAN_TEST_TEAM = "PyGitGuardian team"
Expand Down Expand Up @@ -106,8 +106,8 @@ def ensure_member_coherence():
members = ensure_success(client.list_members(MembersParameters(per_page=5)))

assert (
len(members.data) > MIN_NB_MEMBER
), "There must be at least 3 members in the workspace"
len(members.data) >= MIN_NB_MEMBER
), f"There must be at least {MIN_NB_MEMBER} members in the workspace"


def add_source_to_team(team: Team, available_sources: Iterable[Source] | None = None):
Expand Down
10 changes: 8 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import re
import tarfile
from collections import OrderedDict
Expand Down Expand Up @@ -1248,11 +1249,16 @@ def test_delete_member(client: GGClient):
WHEN calling DELETE /members/{id} endpoint
THEN the member is deleted
"""

# To be able to quickly recreate the membership, the email of the member to delete
# can be provided via an env var
email = os.environ.get("DELETE_MEMBER_EMAIL")
members = client.list_members(MembersParameters(access_level=AccessLevel.MEMBER))
assert isinstance(members, CursorPaginatedResponse), "Could not fetch members"

member = members.data[0]
member = next(
(member for member in members.data if member.email == email), members.data[0]
)

result = client.delete_member(DeleteMemberParameters(id=member.id))

assert result is None, result
Expand Down
Loading