Skip to content
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
57 changes: 57 additions & 0 deletions bert_e/tests/unit/test_handle_pull_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Unit tests for gitwaterflow.handle_pull_request routing."""
from types import SimpleNamespace
from unittest.mock import patch

from bert_e.workflow.gitwaterflow import handle_pull_request


class _FakeRepo:
def __init__(self):
self._url = ''
self._remote_branches = {}


def _make_job(author, src_branch):
"""Return a minimal PullRequestJob stub."""
pull_request = SimpleNamespace(
author=author,
src_branch=src_branch,
id=5171,
)
settings = SimpleNamespace(robot=author)
bert_e = SimpleNamespace(settings=settings)
git = SimpleNamespace(cascade=None, repo=_FakeRepo())
return SimpleNamespace(
pull_request=pull_request,
settings=settings,
bert_e=bert_e,
git=git,
)


def test_robot_authored_integration_branch_routes_to_parent():
"""Robot PR on w/... branch routes to handle_parent_pull_request."""
job = _make_job(author='bert-e',
src_branch='w/4.2/improvement/ARTESCA-17563-something')

parent_path = 'bert_e.workflow.gitwaterflow.handle_parent_pull_request'
handle_path = 'bert_e.workflow.gitwaterflow._handle_pull_request'
with patch(parent_path) as mock_parent, patch(handle_path) as mock_handle:
handle_pull_request(job)
mock_parent.assert_called_once_with(job, job.pull_request)
mock_handle.assert_not_called()


def test_robot_authored_feature_branch_does_not_route_to_parent():
"""Robot PR on feature/... branch (CID bump) is not an integration PR."""
job = _make_job(
author='bert-e',
src_branch='feature/ARTESCA-17576-bump-identity-ui-0.41.0',
)

parent_path = 'bert_e.workflow.gitwaterflow.handle_parent_pull_request'
handle_path = 'bert_e.workflow.gitwaterflow._handle_pull_request'
with patch(parent_path) as mock_parent, patch(handle_path) as mock_handle:
handle_pull_request(job)
mock_parent.assert_not_called()
mock_handle.assert_called_once_with(job)
3 changes: 2 additions & 1 deletion bert_e/workflow/gitwaterflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
@handler(PullRequestJob)
def handle_pull_request(job: PullRequestJob):
"""Analyse and handle a pull request that has just been updated."""
if job.pull_request.author == job.settings.robot:
if job.pull_request.author == job.settings.robot and re.match(
IntegrationBranch.pattern, job.pull_request.src_branch):
return handle_parent_pull_request(job, job.pull_request)
try:
_handle_pull_request(job)
Expand Down
Loading