From 7fa90209cd17b9c7f9b6e707e8c5c6fdf7fa7e07 Mon Sep 17 00:00:00 2001 From: Carly Gundy Date: Thu, 19 Oct 2023 16:07:49 +0200 Subject: [PATCH 1/5] dont raise exception --- .../check_membership/check_membership.py | 7 +++++-- reusable_workflows/tests/test_membership.py | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/reusable_workflows/check_membership/check_membership.py b/reusable_workflows/check_membership/check_membership.py index d05090c..0c2d716 100644 --- a/reusable_workflows/check_membership/check_membership.py +++ b/reusable_workflows/check_membership/check_membership.py @@ -18,9 +18,12 @@ def main() -> None: gh = github3.login(token=gh_token) if not gh: - raise Exception("github login failed - maybe GH_TOKEN was not correctly set") + # Todo: change to Exception once GH_TOKEN can be passed in from forked repositories + print("github login failed - maybe GH_TOKEN was not correctly set") + is_member = False - is_member = is_member_of_org(gh, org, user) + else: + is_member = is_member_of_org(gh, org, user) if is_member: print(f"{user} is member of {org} and can contribute.") diff --git a/reusable_workflows/tests/test_membership.py b/reusable_workflows/tests/test_membership.py index 1345132..5bf4bb5 100644 --- a/reusable_workflows/tests/test_membership.py +++ b/reusable_workflows/tests/test_membership.py @@ -90,16 +90,19 @@ def test_end_to_end_api_fails(os_system, github_login_mock): os_system.assert_not_called() -@mock.patch.dict( - os.environ, {"GH_ORG": "my_org", "GH_TOKEN": "", "USER": "username"} -) +@mock.patch.dict(os.environ, {"GH_ORG": "my_org", "GH_TOKEN": "", "USER": "username"}) @mock.patch("github3.login") def test_github_token_not_passed_in(github_login_mock): github_login_mock.return_value = None - with pytest.raises(Exception) as exc: - main() + main() + + assert is_member is False + + # Todo: switch back once exception is added back + # with pytest.raises(Exception) as exc: + # main() - assert ( - str(exc.value) == "github login failed - maybe GH_TOKEN was not correctly set" - ) + # assert ( + # str(exc.value) == "github login failed - maybe GH_TOKEN was not correctly set" + # ) From aa2680b554735abb773fa7127e605569f35c03b6 Mon Sep 17 00:00:00 2001 From: Carly Gundy Date: Thu, 19 Oct 2023 16:12:16 +0200 Subject: [PATCH 2/5] try again --- reusable_workflows/tests/test_membership.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/reusable_workflows/tests/test_membership.py b/reusable_workflows/tests/test_membership.py index 5bf4bb5..61149b7 100644 --- a/reusable_workflows/tests/test_membership.py +++ b/reusable_workflows/tests/test_membership.py @@ -92,12 +92,13 @@ def test_end_to_end_api_fails(os_system, github_login_mock): @mock.patch.dict(os.environ, {"GH_ORG": "my_org", "GH_TOKEN": "", "USER": "username"}) @mock.patch("github3.login") -def test_github_token_not_passed_in(github_login_mock): +def test_github_token_not_passed_in(github_login_mock, capfd): github_login_mock.return_value = None main() + out, err = capfd.readouterr() - assert is_member is False + assert out == "username is member of my_org and can contribute.\n" # Todo: switch back once exception is added back # with pytest.raises(Exception) as exc: From 734af43dc7cc8b37a38bb83a931439428502df2e Mon Sep 17 00:00:00 2001 From: Carly Gundy Date: Thu, 19 Oct 2023 16:24:55 +0200 Subject: [PATCH 3/5] oops --- reusable_workflows/tests/test_membership.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reusable_workflows/tests/test_membership.py b/reusable_workflows/tests/test_membership.py index 61149b7..1fad6ec 100644 --- a/reusable_workflows/tests/test_membership.py +++ b/reusable_workflows/tests/test_membership.py @@ -98,7 +98,7 @@ def test_github_token_not_passed_in(github_login_mock, capfd): main() out, err = capfd.readouterr() - assert out == "username is member of my_org and can contribute.\n" + assert out == "username is an external contributor.\n" # Todo: switch back once exception is added back # with pytest.raises(Exception) as exc: From 3bf4805e63bc874d300ff8b71c15085fc3df7b43 Mon Sep 17 00:00:00 2001 From: Carly Gundy Date: Thu, 19 Oct 2023 16:27:07 +0200 Subject: [PATCH 4/5] try again --- reusable_workflows/tests/test_membership.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reusable_workflows/tests/test_membership.py b/reusable_workflows/tests/test_membership.py index 1fad6ec..a2306bd 100644 --- a/reusable_workflows/tests/test_membership.py +++ b/reusable_workflows/tests/test_membership.py @@ -98,7 +98,10 @@ def test_github_token_not_passed_in(github_login_mock, capfd): main() out, err = capfd.readouterr() - assert out == "username is an external contributor.\n" + assert ( + out + == "github login failed - maybe GH_TOKEN was not correctly set\nusername is an external contributor.\n" + ) # Todo: switch back once exception is added back # with pytest.raises(Exception) as exc: From cdae7cc0d81ea6fd01555c44ed7142ae1ae9dd95 Mon Sep 17 00:00:00 2001 From: Carly Gundy Date: Thu, 19 Oct 2023 16:36:59 +0200 Subject: [PATCH 5/5] ignore linter warning --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index ce2267c..f55234b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,4 +9,4 @@ ignore_missing_imports = True ignore_missing_imports = True [flake8] -ignore = E501 +ignore = E501, W503