Skip to content
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

fix:send email in unittest #57

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 21 additions & 3 deletions github_access/tests/test_approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def user(mocker):
user.email = "test_user@test.com"
return user


@pytest.fixture
def user_identity(mocker):
identity_mock = mocker.MagicMock()
Expand All @@ -23,6 +24,13 @@ def user_identity(mocker):
return identity_mock


@pytest.fixture
def request_obj(mocker):
request_obj = mocker.MagicMock()
request_obj.request_id = "123"
return request_obj


@pytest.fixture(scope="function")
def context():
return {}
Expand Down Expand Up @@ -190,8 +198,12 @@ def labels():


@when("I pass approval request", target_fixture="context_output")
def add_user_approve(user_identity, labels):
def add_user_approve(mocker, user_identity, labels):
github_access = access.get_object()
mocker.patch(
"Access.access_modules.github_access.access.GithubAccess._GithubAccess__send_approve_email",
return_value=""
)
return github_access.approve(user_identity, labels, "test-approver", "123")


Expand All @@ -208,13 +220,19 @@ def push_labels():


@when("I pass approval request for push", target_fixture="context_output")
def push_approve(user_identity, push_labels):
def push_approve(mocker, user_identity, push_labels, request_obj):

mocker.patch(
"Access.access_modules.github_access.access.GithubAccess._GithubAccess__send_approve_email",
return_value=""
)

github_access = access.get_object()
return github_access.approve(
user_identity,
push_labels,
"test-approver",
"123"
request_obj
)


Expand Down
16 changes: 14 additions & 2 deletions github_access/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def user_identity(mocker):
return identity_mock


@pytest.fixture
def request_obj(mocker):
request_obj = mocker.MagicMock()
request_obj.request_id = "123"
return request_obj


@scenario("features/user.feature", "User does not exist on github")
def test_user_does_not_exist_on_github():
pass
Expand Down Expand Up @@ -230,9 +237,14 @@ def repo_does_not_exist(requests_mock, context):


@when("I pass approval request", target_fixture="context_output")
def add_user_approve(user, labels, user_identity):
def add_user_approve(mocker, user, labels, user_identity, request_obj):
github_access = access.get_object()
return github_access.approve(user_identity, labels, "test-approver", "123")

mocker.patch(
"Access.access_modules.github_access.access.GithubAccess._GithubAccess__send_approve_email",
return_value=""
)
return github_access.approve(user_identity, labels, "test-approver", request_obj)


@then("return value should be False")
Expand Down
2 changes: 1 addition & 1 deletion opsgenie_access/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,6 @@ def false_value(context_output):

@then("return value should be true")
def true_value(context_output):
"""return value should be False."""
"""return value should be True."""
return_value = context_output[0]
assert return_value is True
6 changes: 5 additions & 1 deletion zoom_access/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ def user_name():


@when("I pass approval request", target_fixture="context_output")
def revoke_request(usera, user_identity_a, labels):
def revoke_request(mocker, usera, user_identity_a, labels):
zoom_access = access.get_object()
mocker.patch(
"Access.access_modules.zoom_access.access.Zoom._Zoom__send_approve_email",
return_value=True
)
return zoom_access.approve(user_identity_a, labels, "test-approver", usera)


Expand Down