Skip to content

Commit

Permalink
fix: ensure correct mocks called
Browse files Browse the repository at this point in the history
  • Loading branch information
beckermr committed Sep 21, 2024
1 parent aea9b0e commit 0ad4b14
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 35 deletions.
1 change: 1 addition & 0 deletions conda_forge_webservices/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"[lint skip]",
"[skip lint]",
]
LINT_VIA_GHA = True


class LintInfo(TypedDict):
Expand Down
95 changes: 61 additions & 34 deletions conda_forge_webservices/tests/test_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tornado.testing import AsyncHTTPTestCase

from conda_forge_webservices.webapp import create_webapp
from conda_forge_webservices import linting


class TestHandlerBase(AsyncHTTPTestCase):
Expand Down Expand Up @@ -44,6 +45,10 @@ def test_bad_hash(self):
)
self.assertIn(response.code, [403, 500])

@mock.patch(
"conda_forge_webservices.linting.lint_via_github_actions",
return_value=None,
)
@mock.patch(
"conda_forge_webservices.linting.compute_lint_message",
return_value={"message": mock.sentinel.message},
Expand All @@ -53,7 +58,13 @@ def test_bad_hash(self):
return_value=mock.MagicMock(html_url=mock.sentinel.html_url),
)
@mock.patch("conda_forge_webservices.linting.set_pr_status")
def test_good_header(self, set_pr_status, comment_on_pr, compute_lint_message):
def test_good_header(
self,
set_pr_status,
comment_on_pr,
compute_lint_message,
lint_via_gha,
):
PR_number = 16
body = {
"repository": {
Expand Down Expand Up @@ -88,24 +99,29 @@ def test_good_header(self, set_pr_status, comment_on_pr, compute_lint_message):

self.assertEqual(response.code, 200)

compute_lint_message.assert_called_once_with(
"conda-forge", "repo_name-feedstock", PR_number, False
)
if linting.LINT_VIA_GHA:
lint_via_gha.assert_called_once_with(
"conda-forge", "repo_name-feedstock", PR_number
)
else:
compute_lint_message.assert_called_once_with(
"conda-forge", "repo_name-feedstock", PR_number, False
)

comment_on_pr.assert_called_once_with(
"conda-forge",
"repo_name-feedstock",
PR_number,
mock.sentinel.message,
search="conda-forge-linting service",
)
comment_on_pr.assert_called_once_with(
"conda-forge",
"repo_name-feedstock",
PR_number,
mock.sentinel.message,
search="conda-forge-linting service",
)

set_pr_status.assert_called_once_with(
"conda-forge",
"repo_name-feedstock",
{"message": mock.sentinel.message},
target_url=mock.sentinel.html_url,
)
set_pr_status.assert_called_once_with(
"conda-forge",
"repo_name-feedstock",
{"message": mock.sentinel.message},
target_url=mock.sentinel.html_url,
)

@mock.patch(
"conda_forge_webservices.linting.lint_via_github_actions", return_value=None
Expand Down Expand Up @@ -326,6 +342,10 @@ def test_skip_commits(self, *args):
msg=f"event: {event}, slug: {slug}, hook: {hook}",
)

@mock.patch(
"conda_forge_webservices.linting.lint_via_github_actions",
return_value=None,
)
@mock.patch(
"conda_forge_webservices.linting.compute_lint_message",
return_value={"message": mock.sentinel.message},
Expand All @@ -335,7 +355,9 @@ def test_skip_commits(self, *args):
return_value=mock.MagicMock(html_url=mock.sentinel.html_url),
)
@mock.patch("conda_forge_webservices.linting.set_pr_status")
def test_staged_recipes(self, set_pr_status, comment_on_pr, compute_lint_message):
def test_staged_recipes(
self, set_pr_status, comment_on_pr, compute_lint_message, lint_via_gha
):
PR_number = 16
body = {
"repository": {
Expand Down Expand Up @@ -369,24 +391,29 @@ def test_staged_recipes(self, set_pr_status, comment_on_pr, compute_lint_message
)

self.assertEqual(response.code, 200)
compute_lint_message.assert_called_once_with(
"conda-forge", "staged-recipes", PR_number, True
)
if linting.LINT_VIA_GHA:
lint_via_gha.assert_called_once_with(
"conda-forge", "staged-recipes", PR_number
)
else:
compute_lint_message.assert_called_once_with(
"conda-forge", "staged-recipes", PR_number, True
)

comment_on_pr.assert_called_once_with(
"conda-forge",
"staged-recipes",
PR_number,
mock.sentinel.message,
search="conda-forge-linting service",
)
comment_on_pr.assert_called_once_with(
"conda-forge",
"staged-recipes",
PR_number,
mock.sentinel.message,
search="conda-forge-linting service",
)

set_pr_status.assert_called_once_with(
"conda-forge",
"staged-recipes",
{"message": mock.sentinel.message},
target_url=mock.sentinel.html_url,
)
set_pr_status.assert_called_once_with(
"conda-forge",
"staged-recipes",
{"message": mock.sentinel.message},
target_url=mock.sentinel.html_url,
)

@mock.patch(
"conda_forge_webservices.linting.compute_lint_message",
Expand Down
2 changes: 1 addition & 1 deletion conda_forge_webservices/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def post(self):
LOGGER.info("linting: %s", body["repository"]["full_name"])
LOGGER.info("===================================================")

if True:
if linting.LINT_VIA_GHA:
linting.lint_via_github_actions(
body["repository"]["full_name"],
pr_id,
Expand Down

0 comments on commit 0ad4b14

Please sign in to comment.