2022-03-15 15:52:27 +01:00
|
|
|
"""
|
|
|
|
Unit tests for `toddlers.plugins.scm_request_processor`
|
|
|
|
"""
|
|
|
|
import json
|
|
|
|
import logging
|
2022-03-18 17:38:22 +01:00
|
|
|
import re
|
2022-03-21 13:44:45 +01:00
|
|
|
from unittest.mock import call, MagicMock, Mock, patch
|
2022-08-24 15:33:03 +02:00
|
|
|
import xmlrpc.client
|
2022-03-15 15:52:27 +01:00
|
|
|
|
2022-03-18 17:38:22 +01:00
|
|
|
import arrow
|
2022-07-21 17:16:52 +02:00
|
|
|
from pagure_messages.issue_schema import IssueCommentAddedV1, IssueNewV1
|
2022-03-15 15:52:27 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from toddlers.exceptions import ValidationError
|
2022-03-21 13:44:45 +01:00
|
|
|
import toddlers.plugins.scm_request_processor as scm_request_processor
|
2022-03-15 15:52:27 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
|
2022-03-15 15:52:27 +01:00
|
|
|
class TestAcceptsTopic:
|
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.accepts_topic`
|
|
|
|
method.
|
2022-03-15 15:52:27 +01:00
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
|
2022-03-15 15:52:27 +01:00
|
|
|
toddler_cls = scm_request_processor.SCMRequestProcessor
|
|
|
|
|
|
|
|
def test_accetps_topic_invalid(self, toddler):
|
|
|
|
"""
|
|
|
|
Assert that invalid topic is not accepted.
|
|
|
|
"""
|
|
|
|
assert toddler.accepts_topic("foo.bar") is False
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"topic",
|
|
|
|
[
|
2022-07-21 14:57:11 +02:00
|
|
|
"io.pagure.*.pagure.issue.new",
|
|
|
|
"io.pagure.*.pagure.issue.edit",
|
|
|
|
"io.pagure.*.pagure.issue.comment.added",
|
|
|
|
"io.pagure.stg.pagure.issue.new",
|
|
|
|
"io.pagure.stg.pagure.issue.edit",
|
|
|
|
"io.pagure.stg.pagure.issue.comment.added",
|
|
|
|
"io.pagure.prod.pagure.issue.new",
|
|
|
|
"io.pagure.prod.pagure.issue.edit",
|
|
|
|
"io.pagure.prod.pagure.issue.comment.added",
|
2022-03-21 13:25:42 +01:00
|
|
|
],
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
def test_accetps_topic_valid(self, topic, toddler):
|
|
|
|
"""
|
|
|
|
Assert that valid topics are accepted.
|
|
|
|
"""
|
|
|
|
assert toddler.accepts_topic(topic)
|
|
|
|
|
|
|
|
|
|
|
|
class TestProcess:
|
|
|
|
"""
|
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.process` method.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
|
2022-03-15 15:52:27 +01:00
|
|
|
toddler_cls = scm_request_processor.SCMRequestProcessor
|
|
|
|
|
|
|
|
def test_process_invalid_project(self, caplog, toddler):
|
|
|
|
"""
|
|
|
|
Assert that messages from other projects than fedora_scm_requests will be skipped.
|
|
|
|
"""
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
|
|
|
msg = IssueNewV1()
|
2022-03-21 13:25:42 +01:00
|
|
|
msg.body = {"project": {"fullname": "foo/bar"}}
|
2022-03-15 15:52:27 +01:00
|
|
|
|
|
|
|
with patch(
|
2022-03-21 13:25:42 +01:00
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
|
2022-03-15 15:52:27 +01:00
|
|
|
) as mock_process_ticket:
|
|
|
|
toddler.process({}, msg)
|
|
|
|
|
|
|
|
mock_process_ticket.assert_not_called()
|
|
|
|
|
|
|
|
assert (
|
2022-03-21 13:25:42 +01:00
|
|
|
caplog.records[-1].message
|
|
|
|
== "The message doesn't belong to project releng/fedora-scm-requests. Skipping message."
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_issue_not_open(self, caplog, toddler):
|
|
|
|
"""
|
|
|
|
Assert that messages with closed issues will be skipped.
|
|
|
|
"""
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
|
|
|
msg = IssueNewV1()
|
|
|
|
msg.body = {
|
2022-03-21 13:25:42 +01:00
|
|
|
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
|
2022-03-24 17:57:29 +01:00
|
|
|
"issue": {"id": 100, "status": "Closed"},
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
with patch(
|
2022-03-21 13:25:42 +01:00
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
|
2022-03-15 15:52:27 +01:00
|
|
|
) as mock_process_ticket:
|
|
|
|
toddler.process({}, msg)
|
|
|
|
|
|
|
|
mock_process_ticket.assert_not_called()
|
|
|
|
|
|
|
|
assert (
|
2022-03-21 13:25:42 +01:00
|
|
|
caplog.records[-1].message == "The issue 100 is not open. Skipping message."
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
2022-07-21 18:35:56 +02:00
|
|
|
def test_process_change_done_by_toddler(self, caplog, toddler):
|
2022-07-21 17:16:52 +02:00
|
|
|
"""
|
2022-07-21 18:35:56 +02:00
|
|
|
Assert that toddler will ignore messages that were emitted by it.
|
2022-07-21 17:16:52 +02:00
|
|
|
"""
|
|
|
|
caplog.set_level(logging.INFO)
|
|
|
|
|
|
|
|
pagure_user = "pagure_user"
|
|
|
|
config = {"pagure_user": pagure_user}
|
|
|
|
|
|
|
|
msg = IssueCommentAddedV1()
|
|
|
|
msg.body = {
|
|
|
|
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
|
2022-07-21 18:35:56 +02:00
|
|
|
"issue": {"status": "Open"},
|
|
|
|
"agent": pagure_user,
|
2022-07-21 17:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
|
|
|
|
) as mock_process_ticket:
|
|
|
|
toddler.process(config, msg)
|
|
|
|
|
|
|
|
mock_process_ticket.assert_not_called()
|
|
|
|
|
|
|
|
assert caplog.records[
|
|
|
|
-1
|
2022-07-21 18:35:56 +02:00
|
|
|
].message == "Last change on the ticket was done by {0}. Ignoring the message.".format(
|
2022-07-21 17:16:52 +02:00
|
|
|
pagure_user
|
|
|
|
)
|
|
|
|
|
2022-03-15 15:52:27 +01:00
|
|
|
@patch("toddlers.utils.pdc.set_pdc")
|
|
|
|
@patch("toddlers.utils.pagure.set_pagure")
|
2022-07-22 11:54:07 +02:00
|
|
|
@patch("toddlers.utils.fedora_account.set_fasjson")
|
|
|
|
@patch("toddlers.utils.bugzilla_system.set_bz")
|
|
|
|
def test_process_exception(
|
|
|
|
self, mock_bugzilla, mock_fasjson, mock_pagure, mock_pdc, toddler
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Assert that message toddler will be initialized correctly, if message passes
|
|
|
|
initial processing.
|
|
|
|
"""
|
|
|
|
msg = IssueNewV1()
|
|
|
|
issue = {"id": 100, "status": "Open"}
|
|
|
|
msg.body = {
|
|
|
|
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
|
|
|
|
"issue": issue,
|
|
|
|
"agent": "agent",
|
|
|
|
}
|
|
|
|
config = {
|
|
|
|
"branch_slas": {},
|
|
|
|
"monitoring_choices": [],
|
|
|
|
"pagure_namespace_to_component": {},
|
|
|
|
"pagure_namespace_to_product": {},
|
|
|
|
"temp_dir": "",
|
|
|
|
"dist_git_url": "https://src.fedoraproject.org",
|
|
|
|
"dist_git_token": "Private API Key",
|
|
|
|
}
|
|
|
|
|
|
|
|
mock_pagure_io = Mock()
|
|
|
|
mock_pagure.return_value = mock_pagure_io
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
|
|
|
|
) as mock_process_ticket:
|
|
|
|
mock_process_ticket.side_effect = Exception("Exception")
|
|
|
|
toddler.process(config, msg)
|
|
|
|
|
|
|
|
mock_process_ticket.assert_called_with(issue)
|
|
|
|
|
|
|
|
mock_pdc.assert_called_with(config)
|
|
|
|
mock_pagure.assert_has_calls(
|
|
|
|
[
|
|
|
|
call(config),
|
|
|
|
call(
|
|
|
|
{
|
|
|
|
"pagure_url": "https://src.fedoraproject.org",
|
|
|
|
"pagure_api_key": "Private API Key",
|
|
|
|
}
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
mock_fasjson.assert_called_with(config)
|
|
|
|
mock_bugzilla.assert_called_with(config)
|
|
|
|
mock_pagure_io.add_comment_to_issue.assert_called_once()
|
|
|
|
|
|
|
|
@patch("toddlers.utils.pdc.set_pdc")
|
|
|
|
@patch("toddlers.utils.pagure.set_pagure")
|
2022-03-15 15:52:27 +01:00
|
|
|
@patch("toddlers.utils.fedora_account.set_fasjson")
|
|
|
|
@patch("toddlers.utils.bugzilla_system.set_bz")
|
|
|
|
def test_process(self, mock_bugzilla, mock_fasjson, mock_pagure, mock_pdc, toddler):
|
|
|
|
"""
|
|
|
|
Assert that message toddler will be initialized correctly, if message passes
|
|
|
|
initial processing.
|
|
|
|
"""
|
|
|
|
msg = IssueNewV1()
|
2022-03-24 17:57:29 +01:00
|
|
|
issue = {"id": 100, "status": "Open"}
|
2022-03-15 15:52:27 +01:00
|
|
|
msg.body = {
|
2022-03-21 13:25:42 +01:00
|
|
|
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
|
|
|
|
"issue": issue,
|
2022-07-21 18:35:56 +02:00
|
|
|
"agent": "agent",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
config = {
|
|
|
|
"branch_slas": {},
|
|
|
|
"monitoring_choices": [],
|
|
|
|
"pagure_namespace_to_component": {},
|
|
|
|
"pagure_namespace_to_product": {},
|
|
|
|
"temp_dir": "",
|
|
|
|
"dist_git_url": "https://src.fedoraproject.org",
|
2022-03-21 13:25:42 +01:00
|
|
|
"dist_git_token": "Private API Key",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
with patch(
|
2022-03-21 13:25:42 +01:00
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
|
2022-03-15 15:52:27 +01:00
|
|
|
) as mock_process_ticket:
|
|
|
|
toddler.process(config, msg)
|
|
|
|
|
|
|
|
mock_process_ticket.assert_called_with(issue)
|
|
|
|
|
|
|
|
mock_pdc.assert_called_with(config)
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_pagure.assert_has_calls(
|
|
|
|
[
|
|
|
|
call(config),
|
|
|
|
call(
|
|
|
|
{
|
|
|
|
"pagure_url": "https://src.fedoraproject.org",
|
|
|
|
"pagure_api_key": "Private API Key",
|
|
|
|
}
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
2022-03-15 15:52:27 +01:00
|
|
|
mock_fasjson.assert_called_with(config)
|
|
|
|
mock_bugzilla.assert_called_with(config)
|
|
|
|
|
|
|
|
|
|
|
|
class TestProcessTicket:
|
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket`
|
|
|
|
method.
|
2022-03-15 15:52:27 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
"""
|
|
|
|
Initialize toddler.
|
|
|
|
"""
|
|
|
|
self.toddler = scm_request_processor.SCMRequestProcessor()
|
|
|
|
self.toddler.pagure_io = Mock()
|
|
|
|
self.toddler.dist_git = Mock()
|
|
|
|
|
|
|
|
def test_process_ticket_invalid_json(self):
|
|
|
|
"""
|
|
|
|
Assert that invalid json in issue will end the processing.
|
|
|
|
"""
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": "invalid JSON",
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-15 15:52:27 +01:00
|
|
|
message="Invalid JSON provided",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_ticket_invalid_slas(self):
|
|
|
|
"""
|
|
|
|
Assert that invalid SLAs in issue will end the processing.
|
|
|
|
"""
|
|
|
|
content = {
|
|
|
|
"sls": {},
|
|
|
|
"branch": "branch",
|
|
|
|
}
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": json.dumps(content),
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
with patch(
|
2022-03-21 13:25:42 +01:00
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.verify_slas"
|
2022-03-15 15:52:27 +01:00
|
|
|
) as mock_verify_slas:
|
|
|
|
mock_verify_slas.side_effect = ValidationError("error")
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
mock_verify_slas.assert_called_with("branch", {})
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-15 15:52:27 +01:00
|
|
|
message="error",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_ticket_missing_action(self):
|
|
|
|
"""
|
|
|
|
Assert that missing action in issue will end the processing.
|
|
|
|
"""
|
|
|
|
content = {
|
|
|
|
"sls": {},
|
|
|
|
"branch": "branch",
|
|
|
|
}
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": json.dumps(content),
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-15 15:52:27 +01:00
|
|
|
message="Invalid or missing action field",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_ticket_missing_sla(self):
|
|
|
|
"""
|
|
|
|
Assert that missing SLA for branch will end the processing.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
content = {"branch": "branch", "action": "new_repo"}
|
2022-03-15 15:52:27 +01:00
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": json.dumps(content),
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-15 15:52:27 +01:00
|
|
|
message="Couldn't find standard SLA for branch 'branch'",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_ticket_invalid_branch_name(self):
|
|
|
|
"""
|
|
|
|
Assert that invalid name for branch in specific namespace will end the processing.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
content = {"branch": "branch/", "action": "new_repo", "namespace": "flatpaks"}
|
2022-03-15 15:52:27 +01:00
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": json.dumps(content),
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
self.toddler.branch_slas = {"branch/": "SLA"}
|
|
|
|
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
|
|
|
message=(
|
|
|
|
"Only characters, numbers, periods, dashes, underscores, "
|
|
|
|
"and pluses are allowed in flatpak branch names"
|
|
|
|
),
|
|
|
|
reason="Invalid",
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_ticket_invalid_monitoring_setting(self):
|
|
|
|
"""
|
|
|
|
Assert that invalid monitoring setting for repo will end the processing.
|
|
|
|
"""
|
|
|
|
content = {
|
|
|
|
"branch": "branch",
|
|
|
|
"action": "new_repo",
|
|
|
|
"namespace": "flatpaks",
|
2022-03-21 13:25:42 +01:00
|
|
|
"monitor": "monitor",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": json.dumps(content),
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
self.toddler.branch_slas = {"branch": "SLA"}
|
|
|
|
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-15 15:52:27 +01:00
|
|
|
message='The monitor choice of "monitor" is invalid',
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_ticket_action_new_repo(self):
|
|
|
|
"""
|
|
|
|
Assert that action new_repo is correctly processed.
|
|
|
|
"""
|
|
|
|
content = {
|
|
|
|
"branch": "branch",
|
|
|
|
"action": "new_repo",
|
|
|
|
}
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": json.dumps(content),
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
self.toddler.branch_slas = {"branch": "SLA"}
|
|
|
|
|
|
|
|
with patch(
|
2022-03-21 13:25:42 +01:00
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_repo"
|
2022-03-15 15:52:27 +01:00
|
|
|
) as mock_new_repo:
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
content["sls"] = "SLA"
|
|
|
|
mock_new_repo.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
issue,
|
|
|
|
content,
|
|
|
|
initial_commit=True,
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_process_ticket_action_new_branch(self):
|
|
|
|
"""
|
|
|
|
Assert that action new_branch is correctly processed.
|
|
|
|
"""
|
|
|
|
content = {
|
|
|
|
"branch": "branch",
|
|
|
|
"action": "new_branch",
|
|
|
|
}
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"content": json.dumps(content),
|
2022-03-21 13:25:42 +01:00
|
|
|
"full_url": "https://blacklibrary.wh40k",
|
2022-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
self.toddler.branch_slas = {"branch": "SLA"}
|
|
|
|
|
|
|
|
with patch(
|
2022-03-21 13:25:42 +01:00
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_branch"
|
2022-03-15 15:52:27 +01:00
|
|
|
) as mock_new_branch:
|
|
|
|
self.toddler.process_ticket(issue)
|
|
|
|
|
|
|
|
content["sls"] = "SLA"
|
|
|
|
mock_new_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
issue,
|
|
|
|
content,
|
2022-03-15 15:52:27 +01:00
|
|
|
)
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestVerifySLAs:
|
|
|
|
"""
|
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.verify_slas` method.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
"""
|
|
|
|
Initialize toddler.
|
|
|
|
"""
|
|
|
|
self.toddler = scm_request_processor.SCMRequestProcessor()
|
|
|
|
self.toddler.pagure_io = Mock()
|
|
|
|
self.toddler.dist_git = Mock()
|
|
|
|
|
|
|
|
def test_verify_slas_not_dict(self):
|
|
|
|
"""
|
|
|
|
Assert that SLA verification will fail if SLA isn't dict.
|
|
|
|
"""
|
|
|
|
sla = []
|
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="The object provided is not a dict"):
|
|
|
|
self.toddler.verify_slas("", sla)
|
|
|
|
|
|
|
|
def test_verify_slas_no_branch(self):
|
|
|
|
"""
|
|
|
|
Assert that the validation will not fail if no branch is provided.
|
|
|
|
This will fail later in create method, but the verification passes.
|
|
|
|
"""
|
|
|
|
sla = {}
|
|
|
|
branch = None
|
|
|
|
|
|
|
|
self.toddler.verify_slas(branch, sla)
|
|
|
|
|
|
|
|
def test_verify_slas_branch_sla_correct(self):
|
|
|
|
"""
|
|
|
|
Assert that the validation will not fail if provided branch SLAs are
|
|
|
|
correct.
|
|
|
|
"""
|
|
|
|
branch = "branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": "2022-06-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.branch_slas = {branch: {"rawhide": "2022-06-01"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
self.toddler.verify_slas(branch, sla)
|
|
|
|
|
|
|
|
def test_verify_slas_branch_sla_incorrect(self):
|
|
|
|
"""
|
|
|
|
Assert that the validation will fail if provided branch SLAs are
|
|
|
|
incorrect.
|
|
|
|
"""
|
|
|
|
branch = "branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": "2022-01-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.branch_slas = {branch: {"rawhide": "2022-06-01"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
error = 'The SLAs for the branch "{0}" are incorrect'.format(branch)
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.verify_slas(branch, sla)
|
|
|
|
|
|
|
|
def test_verify_slas_eol_not_string(self):
|
|
|
|
"""
|
|
|
|
Assert that the validation will fail if provided SLA EOL is
|
|
|
|
not string.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": 100}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = 'The SL\'s EOL is not a string. It was type "{0}"'.format(
|
|
|
|
type(100).__name__
|
|
|
|
)
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.verify_slas("", sla)
|
|
|
|
|
|
|
|
def test_verify_slas_eol_invalid_format(self):
|
|
|
|
"""
|
|
|
|
Assert that the validation will fail if provided SLA EOL date is in invalid format.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": "01-01-2022"}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
error = 'The EOL date "{0}" is in an invalid format'.format("01-01-2022")
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.verify_slas("", sla)
|
|
|
|
|
|
|
|
def test_verify_slas_eol_expired(self):
|
|
|
|
"""
|
|
|
|
Assert that the validation will fail if provided SLA EOL date is already expired.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": "2022-01-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
error = 'The SL "{0}" is already expired'.format("2022-01-01")
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.verify_slas("", sla)
|
|
|
|
|
|
|
|
def test_verify_slas_eol_date_invalid(self):
|
|
|
|
"""
|
|
|
|
Assert that the validation will fail if provided SLA EOL date is invalid.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": "2050-01-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = 'The SL "{0}" must expire on June 1st or December 1st'.format(
|
|
|
|
"2050-01-01"
|
|
|
|
)
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.verify_slas("", sla)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
@patch("toddlers.utils.pdc.get_sla")
|
2022-03-16 16:55:58 +01:00
|
|
|
def test_verify_slas_not_in_pdc(self, mock_pdc):
|
|
|
|
"""
|
|
|
|
Assert that the validation will fail if SLA is not in PDC.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": "2050-06-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
error = 'The SL "{0}" is not in PDC'.format("rawhide")
|
|
|
|
|
|
|
|
mock_pdc.return_value = None
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.verify_slas("", sla)
|
|
|
|
|
|
|
|
mock_pdc.assert_called_with("rawhide")
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
@patch("toddlers.utils.pdc.get_sla")
|
2022-03-16 16:55:58 +01:00
|
|
|
def test_verify_slas_in_pdc(self, mock_pdc):
|
|
|
|
"""
|
|
|
|
Assert that the validation will pass if SLA is in PDC.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
sla = {"rawhide": "2050-06-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
mock_pdc.return_value = sla
|
|
|
|
|
|
|
|
self.toddler.verify_slas("", sla)
|
|
|
|
|
|
|
|
mock_pdc.assert_called_with("rawhide")
|
|
|
|
|
|
|
|
|
|
|
|
class TestCreateNewRepo:
|
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_repo`
|
|
|
|
method.
|
2022-03-16 16:55:58 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
"""
|
|
|
|
Initialize toddler.
|
|
|
|
"""
|
|
|
|
self.toddler = scm_request_processor.SCMRequestProcessor()
|
|
|
|
self.toddler.pagure_io = Mock()
|
|
|
|
self.toddler.dist_git = Mock()
|
|
|
|
|
|
|
|
def test_create_new_repo_missing_required_key(self):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if required key is missing in request.
|
|
|
|
"""
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
}
|
|
|
|
self.toddler.create_new_repo(issue, {})
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-16 16:55:58 +01:00
|
|
|
message="Invalid body, missing required field: repo",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-16 16:55:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_create_new_repo_invalid_repo_name(self):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if provided repository name is invalid.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"repo": "+a",
|
|
|
|
"branch": "rawhide",
|
|
|
|
"namespace": "namespace",
|
|
|
|
"bug_id": "123",
|
|
|
|
"action": "new_repo",
|
2022-03-21 13:25:42 +01:00
|
|
|
"sls": {"rawhide": "2050-06-01"},
|
|
|
|
"monitor": "monitor",
|
2022-03-16 16:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = (
|
|
|
|
"The repository name is invalid. It must be at least two "
|
|
|
|
"characters long with only letters, numbers, hyphens, "
|
|
|
|
"underscores, plus signs, and/or periods. Please note that "
|
|
|
|
"the project cannot start with a period or a plus sign."
|
|
|
|
)
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-16 16:55:58 +01:00
|
|
|
message=error,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-16 16:55:58 +01:00
|
|
|
)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
def test_create_new_repo_exception_validated_by_invalid_user(self):
|
|
|
|
"""
|
|
|
|
Assert that processing will be interrupted if the ticket is validated by
|
|
|
|
wrong user.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
user = "zlopez"
|
|
|
|
invalid_user = "Tzeentch"
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"user": {"name": user},
|
2022-04-01 13:26:28 +02:00
|
|
|
"comments": [
|
|
|
|
{
|
|
|
|
"comment": "valid",
|
|
|
|
"user": {"name": invalid_user},
|
|
|
|
"notification": False,
|
|
|
|
}
|
|
|
|
],
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "main"
|
|
|
|
namespace = "tests"
|
|
|
|
bug_id = ""
|
|
|
|
action = "new_repo"
|
|
|
|
sls = {branch: "2050-06-01"}
|
|
|
|
monitor = "monitor"
|
|
|
|
exception = False
|
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
|
|
|
"exception": exception,
|
|
|
|
}
|
|
|
|
self.toddler.pagure_io.get_project_contributors.return_value = {
|
2022-03-23 17:20:18 +01:00
|
|
|
"users": {"admin": [user], "commit": [], "ticket": []}
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
|
|
|
self.toddler.validation_comment = "valid"
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
|
|
|
self.toddler.pagure_io.get_project_contributors.assert_called_with(
|
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[0],
|
2022-03-23 17:20:18 +01:00
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[1],
|
2022-03-23 16:24:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_create_new_repo_exception_no_validation_comment(self):
|
|
|
|
"""
|
|
|
|
Assert that processing will be interrupted if the ticket validation comment
|
|
|
|
is not found.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
user = "zlopez"
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"user": {"name": user},
|
2022-04-01 13:26:28 +02:00
|
|
|
"comments": [
|
|
|
|
{"comment": "comment", "user": {"name": user}, "notification": False}
|
|
|
|
],
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "main"
|
|
|
|
namespace = "tests"
|
|
|
|
bug_id = ""
|
|
|
|
action = "new_repo"
|
|
|
|
sls = {branch: "2050-06-01"}
|
|
|
|
monitor = "monitor"
|
|
|
|
exception = False
|
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
|
|
|
"exception": exception,
|
|
|
|
}
|
|
|
|
self.toddler.pagure_io.get_project_contributors.return_value = {
|
2022-03-23 17:20:18 +01:00
|
|
|
"users": {"admin": [user], "commit": [], "ticket": []}
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
|
|
|
self.toddler.validation_comment = "valid"
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
|
|
|
self.toddler.pagure_io.get_project_contributors.assert_called_with(
|
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[0],
|
2022-03-23 17:20:18 +01:00
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[1],
|
2022-03-23 16:24:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_create_new_repo_exception_notify_maintainers(self):
|
|
|
|
"""
|
|
|
|
Assert that comment will be added when the ticket needs manual
|
|
|
|
validation.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
user = "zlopez"
|
2022-03-23 17:20:18 +01:00
|
|
|
issue = {"id": 100, "user": {"name": user}, "comments": []}
|
2022-03-23 16:24:16 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "main"
|
|
|
|
namespace = "tests"
|
|
|
|
bug_id = ""
|
|
|
|
action = "new_repo"
|
|
|
|
sls = {branch: "2050-06-01"}
|
|
|
|
monitor = "monitor"
|
|
|
|
exception = False
|
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
|
|
|
"exception": exception,
|
|
|
|
}
|
|
|
|
self.toddler.pagure_io.get_project_contributors.return_value = {
|
2022-03-23 17:20:18 +01:00
|
|
|
"users": {"admin": [user, "Tzeentch"], "commit": [], "ticket": []}
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
|
|
|
self.toddler.ping_comment = "Look at this comment {maintainers}"
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
|
|
|
self.toddler.pagure_io.get_project_contributors.assert_called_with(
|
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[0],
|
2022-03-23 17:20:18 +01:00
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[1],
|
2022-03-23 16:24:16 +01:00
|
|
|
)
|
|
|
|
|
2022-03-23 17:20:18 +01:00
|
|
|
message = "Look at this comment @Tzeentch @{}".format(user)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.add_comment_to_issue.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
100, namespace=scm_request_processor.PROJECT_NAMESPACE, comment=message
|
2022-03-23 16:24:16 +01:00
|
|
|
)
|
|
|
|
|
2022-04-01 13:26:28 +02:00
|
|
|
def test_create_new_repo_exception_not_valid_notification_comment_present(self):
|
|
|
|
"""
|
|
|
|
Assert that comment will not be added if the toddler already commented on the
|
|
|
|
ticket.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
user = "zlopez"
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"user": {"name": user},
|
|
|
|
"comments": [
|
|
|
|
{"comment": "comment", "user": {"name": user}, "notification": False}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "main"
|
|
|
|
namespace = "tests"
|
|
|
|
bug_id = ""
|
|
|
|
action = "new_repo"
|
|
|
|
sls = {branch: "2050-06-01"}
|
|
|
|
monitor = "monitor"
|
|
|
|
exception = False
|
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
|
|
|
"exception": exception,
|
|
|
|
}
|
|
|
|
self.toddler.pagure_io.get_project_contributors.return_value = {
|
|
|
|
"users": {"admin": ["Tzeentch"], "commit": [], "ticket": []}
|
|
|
|
}
|
|
|
|
self.toddler.pagure_user = user
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
|
|
|
self.toddler.pagure_io.get_project_contributors.assert_called_with(
|
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[0],
|
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[1],
|
|
|
|
)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.add_comment_to_issue.assert_not_called()
|
|
|
|
|
2022-03-16 16:55:58 +01:00
|
|
|
def test_create_new_repo_missing_bug_id(self):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if Bugzilla bug id is not provided.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"repo": "repo",
|
|
|
|
"branch": "rawhide",
|
|
|
|
"namespace": "namespace",
|
|
|
|
"bug_id": "",
|
|
|
|
"action": "new_repo",
|
2022-03-21 13:25:42 +01:00
|
|
|
"sls": {"rawhide": "2050-06-01"},
|
|
|
|
"monitor": "monitor",
|
2022-03-16 16:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-16 16:55:58 +01:00
|
|
|
message="An invalid Bugzilla bug was provided",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-16 16:55:58 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
2022-03-16 16:55:58 +01:00
|
|
|
def test_create_new_repo_invalid_review_bug(self, mock_validate_review_bug):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if Bugzilla bug is not valid.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
json = {
|
|
|
|
"repo": "repo",
|
|
|
|
"branch": "rawhide",
|
|
|
|
"namespace": "namespace",
|
|
|
|
"bug_id": "123",
|
|
|
|
"action": "new_repo",
|
2022-03-21 13:25:42 +01:00
|
|
|
"sls": {"rawhide": "2050-06-01"},
|
|
|
|
"monitor": "monitor",
|
2022-03-16 16:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mock_validate_review_bug.side_effect = ValidationError("error")
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
"123", "repo", "rawhide", namespace="namespace", pagure_user="zlopez"
|
2022-03-16 16:55:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-16 16:55:58 +01:00
|
|
|
message="error",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-16 16:55:58 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.valid_epel_package"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
2022-03-23 17:20:18 +01:00
|
|
|
def test_create_new_repo_invalid_epel(
|
|
|
|
self, mock_validate_review_bug, mock_valid_epel_package
|
|
|
|
):
|
2022-03-16 16:55:58 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if repo is invalid EPEL repo.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "epel8"
|
|
|
|
namespace = "rpms"
|
|
|
|
bug_id = "123"
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-16 16:55:58 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-16 16:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mock_valid_epel_package.return_value = False
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_valid_epel_package.assert_called_with(repo, branch)
|
2022-03-16 16:55:58 +01:00
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
bug_id, repo, branch, namespace=namespace, pagure_user="zlopez"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
2022-03-16 16:55:58 +01:00
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-16 16:55:58 +01:00
|
|
|
message=scm_request_processor.INVALID_EPEL_ERROR,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-16 16:55:58 +01:00
|
|
|
)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
|
|
|
def test_create_new_repo_requester_not_in_dist_git(self, mock_validate_review_bug):
|
2022-03-16 16:55:58 +01:00
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Assert that ticket will be commented on when requester doesn't
|
|
|
|
have a valid dist git account.
|
2022-03-16 16:55:58 +01:00
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
bug_id = "123"
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-16 16:55:58 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-16 16:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.toddler.dist_git.user_exists.return_value = False
|
|
|
|
self.toddler.dist_git._pagure_url = "https://src.fedoraproject.org"
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
bug_id, repo, branch, namespace=namespace, pagure_user="zlopez"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.user_exists.assert_called_with("zlopez")
|
2022-03-16 16:55:58 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
message = "@zlopez needs to login to {0} to sync accounts before we can proceed.".format(
|
|
|
|
self.toddler.dist_git._pagure_url
|
|
|
|
)
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.add_comment_to_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-16 16:55:58 +01:00
|
|
|
comment=message,
|
|
|
|
)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
|
|
|
def test_create_new_repo_project_exists(self, mock_validate_review_bug):
|
2022-03-16 16:55:58 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be closed when repo already exists in dist git.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
bug_id = "123"
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-16 16:55:58 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-16 16:55:58 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-16 16:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.toddler.dist_git.get_project.return_value = "project"
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
bug_id, repo, branch, namespace=namespace, pagure_user="zlopez"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project.assert_called_with(namespace, repo)
|
2022-03-16 16:55:58 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-16 16:55:58 +01:00
|
|
|
message="The Pagure project already exists",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-16 16:55:58 +01:00
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
|
|
|
def test_create_new_repo_master_branch(self, mock_validate_review_bug):
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be closed when branch is set to master branch.
|
|
|
|
Master branch is no longer allowed.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "master"
|
|
|
|
namespace = "rpms"
|
|
|
|
bug_id = "123"
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-17 16:44:11 +01:00
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project.return_value = None
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
bug_id, repo, branch, namespace=namespace, pagure_user="zlopez"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project.assert_called_with(namespace, repo)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message="Branch `master` cannot be created, please request the right branch.",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
|
|
|
def test_create_new_repo_unsupported_namespace(self, mock_validate_review_bug):
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be closed when requested namespace is not recognized.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "invalid"
|
|
|
|
bug_id = "123"
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-17 16:44:11 +01:00
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project.return_value = None
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
bug_id, repo, branch, namespace=namespace, pagure_user="zlopez"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project.assert_called_with(namespace, repo)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = (
|
|
|
|
"The requested namespace '{0}' is not recognized. "
|
|
|
|
"Currently supported namespaces are: "
|
|
|
|
"rpms, container, flatpaks, modules, tests.".format(namespace)
|
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message=error,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"namespace, branch",
|
|
|
|
[
|
|
|
|
("rpms", "rawhide"),
|
|
|
|
("container", "rawhide"),
|
|
|
|
("flatpaks", "stable"),
|
|
|
|
("modules", "rawhide"),
|
2022-03-21 13:25:42 +01:00
|
|
|
],
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.pdc")
|
|
|
|
def test_create_new_repo_namespaces(self, mock_pdc, namespace, branch):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be processed when everything is in order and namespace is correct.
|
|
|
|
"""
|
2022-03-23 16:24:16 +01:00
|
|
|
# Preparation
|
|
|
|
user = "zlopez"
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"user": {"name": user},
|
2022-04-01 13:26:28 +02:00
|
|
|
"comments": [
|
|
|
|
{"comment": "valid", "user": {"name": user}, "notification": False}
|
|
|
|
],
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
bug_id = ""
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {branch: "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
monitor = "monitor"
|
|
|
|
exception = True
|
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-17 16:44:11 +01:00
|
|
|
}
|
|
|
|
dist_git_url = "https://src.fp.o"
|
|
|
|
self.toddler.dist_git.get_project.return_value = None
|
|
|
|
self.toddler.dist_git._pagure_url = dist_git_url
|
2022-03-23 16:24:16 +01:00
|
|
|
self.toddler.pagure_io.get_project_contributors.return_value = {
|
2022-03-23 17:20:18 +01:00
|
|
|
"users": {"admin": [user], "commit": [], "ticket": []}
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
|
|
|
self.toddler.validation_comment = "valid"
|
2022-03-17 16:44:11 +01:00
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
# Method to test
|
2022-03-17 16:44:11 +01:00
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project.assert_called_with(namespace, repo)
|
2022-03-17 16:44:11 +01:00
|
|
|
self.toddler.dist_git.new_project.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
namespace, repo, "", "", branch, initial_commit=True, alias=True
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
self.toddler.dist_git.set_monitoring_status.assert_called_with(
|
|
|
|
namespace, repo, monitor
|
|
|
|
)
|
|
|
|
self.toddler.dist_git.change_project_main_admin.assert_called_with(
|
|
|
|
namespace, repo, "zlopez"
|
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_global_component.assert_called_with(
|
|
|
|
repo, "{0}/{1}/{2}".format(dist_git_url, namespace, repo)
|
|
|
|
)
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_pdc.new_branch.assert_called_with(repo, branch, namespace.rstrip("s"))
|
2022-03-17 16:44:11 +01:00
|
|
|
mock_pdc.new_sla_to_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
branch, sls[branch], repo, branch, namespace.rstrip("s")
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
message = "The Pagure repository was created at {0}/{1}/{2}".format(
|
2022-03-21 13:25:42 +01:00
|
|
|
dist_git_url, namespace, repo
|
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message=message,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Processed",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
2022-08-26 13:59:39 +02:00
|
|
|
def test_create_new_repo_tests_namespace(self):
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Assert that ticket will be processed when everything is in order and namespace
|
|
|
|
is set to tests.
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
2022-03-23 16:24:16 +01:00
|
|
|
# Preparation
|
|
|
|
user = "zlopez"
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
"user": {"name": user},
|
2022-04-01 13:26:28 +02:00
|
|
|
"comments": [
|
|
|
|
{"comment": "valid", "user": {"name": user}, "notification": False}
|
|
|
|
],
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "main"
|
|
|
|
namespace = "tests"
|
|
|
|
bug_id = ""
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {branch: "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-17 16:44:11 +01:00
|
|
|
}
|
|
|
|
dist_git_url = "https://src.fp.o"
|
|
|
|
self.toddler.dist_git.get_project.return_value = None
|
|
|
|
self.toddler.dist_git._pagure_url = dist_git_url
|
2022-03-23 16:24:16 +01:00
|
|
|
self.toddler.pagure_io.get_project_contributors.return_value = {
|
2022-03-23 17:20:18 +01:00
|
|
|
"users": {"admin": [user], "commit": [], "ticket": []}
|
2022-03-23 16:24:16 +01:00
|
|
|
}
|
|
|
|
self.toddler.validation_comment = "valid"
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
2022-03-23 16:24:16 +01:00
|
|
|
self.toddler.pagure_io.get_project_contributors.assert_called_with(
|
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[0],
|
2022-03-23 17:20:18 +01:00
|
|
|
scm_request_processor.PROJECT_NAMESPACE.split("/")[1],
|
2022-03-23 16:24:16 +01:00
|
|
|
)
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project.assert_called_with(namespace, repo)
|
2022-03-17 16:44:11 +01:00
|
|
|
self.toddler.dist_git.new_project.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
namespace, repo, "", "", branch, initial_commit=True, alias=True
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
self.toddler.dist_git.set_monitoring_status.assert_called_with(
|
|
|
|
namespace, repo, monitor
|
|
|
|
)
|
|
|
|
self.toddler.dist_git.change_project_main_admin.assert_called_with(
|
|
|
|
namespace, repo, "zlopez"
|
|
|
|
)
|
|
|
|
|
|
|
|
message = "The Pagure repository was created at {0}/{1}/{2}".format(
|
2022-03-21 13:25:42 +01:00
|
|
|
dist_git_url, namespace, repo
|
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message=message,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Processed",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
2022-03-17 16:44:11 +01:00
|
|
|
@patch("toddlers.plugins.scm_request_processor.pdc")
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
2022-03-23 17:20:18 +01:00
|
|
|
def test_create_new_repo_non_default_branch(
|
|
|
|
self, mock_validate_review_bug, mock_pdc, mock_bz
|
|
|
|
):
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Assert that ticket will be processed when everything is in order and requested
|
|
|
|
branch is not default.
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "f35"
|
|
|
|
namespace = "rpms"
|
2022-03-23 16:24:16 +01:00
|
|
|
bug_id = "123"
|
2022-03-17 16:44:11 +01:00
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {branch: "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-17 16:44:11 +01:00
|
|
|
}
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.branch_slas = {"rawhide": {"rawhide": "2050-06-01"}}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
dist_git_url = "https://src.fp.o"
|
|
|
|
self.toddler.dist_git.get_project.return_value = None
|
|
|
|
self.toddler.dist_git._pagure_url = dist_git_url
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
bug_id, repo, branch, namespace=namespace, pagure_user="zlopez"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project.assert_called_with(namespace, repo)
|
2022-03-17 16:44:11 +01:00
|
|
|
self.toddler.dist_git.new_project.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
namespace, repo, "", "", "rawhide", initial_commit=True, alias=True
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
self.toddler.dist_git.set_monitoring_status.assert_called_with(
|
|
|
|
namespace, repo, monitor
|
|
|
|
)
|
|
|
|
self.toddler.dist_git.change_project_main_admin.assert_called_with(
|
|
|
|
namespace, repo, "zlopez"
|
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_global_component.assert_called_with(
|
|
|
|
repo, "{0}/{1}/{2}".format(dist_git_url, namespace, repo)
|
|
|
|
)
|
|
|
|
mock_pdc.new_branch.assert_has_calls(
|
|
|
|
[
|
2022-03-21 13:25:42 +01:00
|
|
|
call(repo, "rawhide", namespace.rstrip("s")),
|
|
|
|
call(repo, branch, namespace.rstrip("s")),
|
2022-03-17 16:44:11 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
mock_pdc.new_sla_to_branch.assert_has_calls(
|
|
|
|
[
|
2022-03-21 13:25:42 +01:00
|
|
|
call("rawhide", "2050-06-01", repo, "rawhide", namespace.rstrip("s")),
|
|
|
|
call(branch, sls[branch], repo, branch, namespace.rstrip("s")),
|
2022-03-17 16:44:11 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
message = (
|
|
|
|
"The Pagure repository was created at {0}/{1}/{2}. "
|
|
|
|
'You may commit to the branch "{3}" in about '
|
|
|
|
"10 minutes.".format(dist_git_url, namespace, repo, branch)
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message=message,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Processed",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_bz.comment_on_bug.assert_called_with(bug_id, message)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.pdc")
|
2022-03-23 16:24:16 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug"
|
|
|
|
)
|
2022-03-23 17:20:18 +01:00
|
|
|
def test_create_new_repo_default_brach(
|
|
|
|
self, mock_validate_review_bug, mock_pdc, mock_bz
|
|
|
|
):
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
2022-03-23 16:24:16 +01:00
|
|
|
Assert that repo will be created with default branch when everything is in order.
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
bug_id = "123"
|
|
|
|
action = "new_repo"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {branch: "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
monitor = "monitor"
|
2022-03-23 16:24:16 +01:00
|
|
|
exception = False
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"monitor": monitor,
|
2022-03-21 13:25:42 +01:00
|
|
|
"exception": exception,
|
2022-03-17 16:44:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dist_git_url = "https://src.fp.o"
|
|
|
|
self.toddler.dist_git.get_project.return_value = None
|
|
|
|
self.toddler.dist_git._pagure_url = dist_git_url
|
|
|
|
|
|
|
|
self.toddler.create_new_repo(issue, json)
|
|
|
|
|
|
|
|
# asserts
|
2022-03-23 16:24:16 +01:00
|
|
|
mock_validate_review_bug.assert_called_with(
|
2022-03-23 17:20:18 +01:00
|
|
|
bug_id, repo, branch, namespace=namespace, pagure_user="zlopez"
|
|
|
|
)
|
2022-03-23 16:24:16 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project.assert_called_with(namespace, repo)
|
2022-03-17 16:44:11 +01:00
|
|
|
self.toddler.dist_git.new_project.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
namespace, repo, "", "", branch, initial_commit=True, alias=True
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
self.toddler.dist_git.set_monitoring_status.assert_called_with(
|
|
|
|
namespace, repo, monitor
|
|
|
|
)
|
|
|
|
self.toddler.dist_git.change_project_main_admin.assert_called_with(
|
|
|
|
namespace, repo, "zlopez"
|
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_global_component.assert_called_with(
|
|
|
|
repo, "{0}/{1}/{2}".format(dist_git_url, namespace, repo)
|
|
|
|
)
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_pdc.new_branch.assert_called_with(repo, branch, namespace.rstrip("s"))
|
2022-03-17 16:44:11 +01:00
|
|
|
mock_pdc.new_sla_to_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
branch, sls[branch], repo, branch, namespace.rstrip("s")
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
message = "The Pagure repository was created at {0}/{1}/{2}".format(
|
2022-03-21 13:25:42 +01:00
|
|
|
dist_git_url, namespace, repo
|
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message=message,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Processed",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_bz.comment_on_bug.assert_called_with(bug_id, message)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
|
2022-03-17 16:44:11 +01:00
|
|
|
class TestCreateNewBranch:
|
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.create_new_branch`
|
|
|
|
method.
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
"""
|
|
|
|
Initialize toddler.
|
|
|
|
"""
|
|
|
|
self.toddler = scm_request_processor.SCMRequestProcessor()
|
|
|
|
self.toddler.pagure_io = Mock()
|
|
|
|
self.toddler.dist_git = Mock()
|
|
|
|
|
|
|
|
def test_create_new_branch_missing_required_key(self):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if required key is missing in request.
|
|
|
|
"""
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
}
|
|
|
|
self.toddler.create_new_branch(issue, {})
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message="Invalid body, missing required field: action",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_create_new_branch_no_contributors(self):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if contributors are not retrieved.
|
|
|
|
"""
|
|
|
|
issue = {
|
|
|
|
"id": 100,
|
|
|
|
}
|
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
action = "new_branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {branch: "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project_contributors.return_value = None
|
|
|
|
|
|
|
|
self.toddler.create_new_branch(issue, json)
|
|
|
|
|
|
|
|
# Asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project_contributors.assert_called_with(
|
|
|
|
namespace, repo
|
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message="The dist git repository doesn't exist",
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
@patch(
|
|
|
|
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.valid_epel_package"
|
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
def test_create_new_branch_invalid_epel(self, mock_valid_epel_package):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if repo is invalid EPEL repo.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "epel8"
|
|
|
|
namespace = "rpms"
|
|
|
|
action = "new_branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
}
|
|
|
|
|
|
|
|
mock_valid_epel_package.return_value = False
|
|
|
|
|
|
|
|
self.toddler.create_new_branch(issue, json)
|
|
|
|
|
|
|
|
# Asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project_contributors.assert_called_with(
|
|
|
|
namespace, repo
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_valid_epel_package.assert_called_with(repo, branch)
|
|
|
|
|
2022-03-17 16:44:11 +01:00
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message=scm_request_processor.INVALID_EPEL_ERROR,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
2022-08-26 13:59:39 +02:00
|
|
|
def test_create_new_branch_requester_is_not_maintainer(self, mock_fedora_account):
|
2022-03-17 16:44:11 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if requester is not a maintainer of package.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
action = "new_branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-17 16:44:11 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project_contributors.return_value = {
|
2022-03-21 13:25:42 +01:00
|
|
|
"users": {"admin": [], "commit": [], "collaborators": []},
|
|
|
|
"groups": {"admin": ["group"], "commit": [], "collaborators": []},
|
2022-03-17 16:44:11 +01:00
|
|
|
}
|
|
|
|
mock_fedora_account.user_member_of.return_value = False
|
|
|
|
|
|
|
|
self.toddler.create_new_branch(issue, json)
|
|
|
|
|
|
|
|
# Asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project_contributors.assert_called_with(
|
|
|
|
namespace, repo
|
|
|
|
)
|
2022-03-17 16:44:11 +01:00
|
|
|
|
|
|
|
mock_fedora_account.user_member_of.assert_called_with(
|
|
|
|
mock_fedora_account.get_user_by_username(), "group"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-17 16:44:11 +01:00
|
|
|
message="zlopez is not a maintainer of the {0} package".format(repo),
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Invalid",
|
2022-03-17 16:44:11 +01:00
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.TemporaryDirectory")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.git")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.pdc")
|
2022-03-21 13:25:42 +01:00
|
|
|
def test_create_new_branch_default_branch_missing(
|
|
|
|
self, mock_pdc, mock_fedora_account, mock_git, mock_temp_dir
|
|
|
|
):
|
2022-03-18 17:38:22 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be closed if there is no default branch in project and
|
|
|
|
new branch in git should be created.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
action = "new_branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-18 17:38:22 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project_contributors.return_value = {
|
2022-03-21 13:25:42 +01:00
|
|
|
"users": {"admin": [], "commit": [], "collaborators": []},
|
|
|
|
"groups": {"admin": ["group"], "commit": [], "collaborators": []},
|
2022-03-18 17:38:22 +01:00
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_default_branch.return_value = None
|
|
|
|
self.toddler.dist_git._pagure_url = "https://fp.o"
|
|
|
|
mock_fedora_account.user_member_of.return_value = True
|
|
|
|
|
|
|
|
mock_dir = MagicMock()
|
|
|
|
mock_dir.__enter__.return_value = "dir"
|
|
|
|
|
|
|
|
mock_temp_dir.return_value = mock_dir
|
|
|
|
|
|
|
|
self.toddler.create_new_branch(issue, json)
|
|
|
|
|
|
|
|
# Asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project_contributors.assert_called_with(
|
|
|
|
namespace, repo
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_fedora_account.user_member_of.assert_called_with(
|
|
|
|
mock_fedora_account.get_user_by_username(), "group"
|
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_global_component.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo,
|
|
|
|
"{0}/{1}/{2}".format(self.toddler.dist_git._pagure_url, namespace, repo),
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_sla_to_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
branch, "2050-06-01", repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_git.clone_repo.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
"{0}/{1}/{2}".format(self.toddler.dist_git._pagure_url, namespace, repo),
|
|
|
|
"dir",
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_default_branch.assert_called_with(namespace, repo)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
|
|
|
message="There is no default branch set for {0}/{1}".format(
|
|
|
|
namespace, repo
|
|
|
|
),
|
|
|
|
reason="Invalid",
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.TemporaryDirectory")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.git")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.pdc")
|
2022-03-21 13:25:42 +01:00
|
|
|
def test_create_new_branch_with_git(
|
|
|
|
self, mock_pdc, mock_fedora_account, mock_git, mock_temp_dir
|
|
|
|
):
|
2022-03-18 17:38:22 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be processed and branch created in git.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
default_branch = "rawhide"
|
|
|
|
branch = "f36"
|
|
|
|
namespace = "rpms"
|
|
|
|
action = "new_branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-18 17:38:22 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project_contributors.return_value = {
|
2022-03-21 13:25:42 +01:00
|
|
|
"users": {"admin": [], "commit": [], "collaborators": []},
|
|
|
|
"groups": {"admin": ["group"], "commit": [], "collaborators": []},
|
2022-03-18 17:38:22 +01:00
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_default_branch.return_value = default_branch
|
|
|
|
self.toddler.dist_git._pagure_url = "https://fp.o"
|
|
|
|
mock_fedora_account.user_member_of.return_value = True
|
|
|
|
|
|
|
|
mock_dir = MagicMock()
|
|
|
|
mock_dir.__enter__.return_value = "dir"
|
|
|
|
mock_temp_dir.return_value = mock_dir
|
|
|
|
|
|
|
|
mock_git_repo = Mock()
|
|
|
|
mock_git_repo.first_commit.return_value = "SHA256"
|
|
|
|
|
|
|
|
mock_git.clone_repo.return_value = mock_git_repo
|
|
|
|
|
|
|
|
self.toddler.create_new_branch(issue, json)
|
|
|
|
|
|
|
|
# Asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project_contributors.assert_called_with(
|
|
|
|
namespace, repo
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_fedora_account.user_member_of.assert_called_with(
|
|
|
|
mock_fedora_account.get_user_by_username(), "group"
|
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_global_component.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo,
|
|
|
|
"{0}/{1}/{2}".format(self.toddler.dist_git._pagure_url, namespace, repo),
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_sla_to_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
default_branch, "2050-06-01", repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_git.clone_repo.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
"{0}/{1}/{2}".format(self.toddler.dist_git._pagure_url, namespace, repo),
|
|
|
|
"dir",
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_default_branch.assert_called_with(namespace, repo)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_git_repo.first_commit.assert_called_with(default_branch)
|
|
|
|
|
|
|
|
self.toddler.dist_git.new_branch.assert_called_with(
|
|
|
|
namespace, repo, branch, from_commit="SHA256"
|
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
message = (
|
|
|
|
"The branch was created in PDC and git. It "
|
|
|
|
"may take up to 10 minutes before you have "
|
|
|
|
"write access on the branch."
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-18 17:38:22 +01:00
|
|
|
message=message,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Processed",
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.pdc")
|
|
|
|
def test_create_new_branch_only_PDC(self, mock_pdc, mock_fedora_account):
|
|
|
|
"""
|
|
|
|
Assert that ticket will be processed and branch created in PDC.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
action = "new_branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-18 17:38:22 +01:00
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"action": action,
|
|
|
|
"sls": sls,
|
|
|
|
"create_git_branch": False,
|
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project_contributors.return_value = {
|
2022-03-21 13:25:42 +01:00
|
|
|
"users": {"admin": [], "commit": [], "collaborators": []},
|
|
|
|
"groups": {"admin": ["group"], "commit": [], "collaborators": []},
|
2022-03-18 17:38:22 +01:00
|
|
|
}
|
|
|
|
self.toddler.dist_git._pagure_url = "https://fp.o"
|
|
|
|
mock_fedora_account.user_member_of.return_value = True
|
|
|
|
|
|
|
|
self.toddler.create_new_branch(issue, json)
|
|
|
|
|
|
|
|
# Asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project_contributors.assert_called_with(
|
|
|
|
namespace, repo
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_fedora_account.user_member_of.assert_called_with(
|
|
|
|
mock_fedora_account.get_user_by_username(), "group"
|
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_global_component.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo,
|
|
|
|
"{0}/{1}/{2}".format(self.toddler.dist_git._pagure_url, namespace, repo),
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_sla_to_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
branch, "2050-06-01", repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
message = (
|
|
|
|
"The branch in PDC was created. Pagure is still processing "
|
|
|
|
"the request, but in about 10 minutes, you may create the "
|
|
|
|
"branch in Pagure using git."
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-18 17:38:22 +01:00
|
|
|
message=message,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Processed",
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.pdc")
|
2022-03-21 13:25:42 +01:00
|
|
|
def test_create_new_branch_comment_on_bug(
|
|
|
|
self, mock_pdc, mock_fedora_account, mock_bz
|
|
|
|
):
|
2022-03-18 17:38:22 +01:00
|
|
|
"""
|
|
|
|
Assert that ticket will be processed and comment added to bugzilla bug, if provided.
|
|
|
|
"""
|
2022-03-21 13:25:42 +01:00
|
|
|
issue = {"id": 100, "user": {"name": "zlopez"}}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
namespace = "rpms"
|
|
|
|
action = "new_branch"
|
2022-03-21 13:25:42 +01:00
|
|
|
sls = {"rawhide": "2050-06-01"}
|
2022-03-18 17:38:22 +01:00
|
|
|
bug_id = "123"
|
|
|
|
json = {
|
|
|
|
"repo": repo,
|
|
|
|
"branch": branch,
|
|
|
|
"namespace": namespace,
|
|
|
|
"action": action,
|
|
|
|
"bug_id": bug_id,
|
|
|
|
"sls": sls,
|
|
|
|
"create_git_branch": False,
|
|
|
|
}
|
|
|
|
self.toddler.dist_git.get_project_contributors.return_value = {
|
2022-03-21 13:25:42 +01:00
|
|
|
"users": {"admin": [], "commit": [], "collaborators": []},
|
|
|
|
"groups": {"admin": ["group"], "commit": [], "collaborators": []},
|
2022-03-18 17:38:22 +01:00
|
|
|
}
|
|
|
|
self.toddler.dist_git._pagure_url = "https://fp.o"
|
|
|
|
mock_fedora_account.user_member_of.return_value = True
|
|
|
|
|
|
|
|
self.toddler.create_new_branch(issue, json)
|
|
|
|
|
|
|
|
# Asserts
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.dist_git.get_project_contributors.assert_called_with(
|
|
|
|
namespace, repo
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_fedora_account.user_member_of.assert_called_with(
|
|
|
|
mock_fedora_account.get_user_by_username(), "group"
|
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_global_component.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo,
|
|
|
|
"{0}/{1}/{2}".format(self.toddler.dist_git._pagure_url, namespace, repo),
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_pdc.new_sla_to_branch.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
branch, "2050-06-01", repo, branch, namespace.strip().rstrip("s")
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
message = (
|
|
|
|
"The branch in PDC was created. Pagure is still processing "
|
|
|
|
"the request, but in about 10 minutes, you may create the "
|
|
|
|
"branch in Pagure using git."
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
self.toddler.pagure_io.close_issue.assert_called_with(
|
2022-03-21 13:25:42 +01:00
|
|
|
100,
|
|
|
|
namespace=scm_request_processor.PROJECT_NAMESPACE,
|
2022-03-18 17:38:22 +01:00
|
|
|
message=message,
|
2022-03-21 13:25:42 +01:00
|
|
|
reason="Processed",
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
mock_bz.comment_on_bug.assert_called_with(bug_id, message)
|
|
|
|
|
|
|
|
|
|
|
|
class TestValidateReviewBug:
|
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.validate_review_bug`
|
|
|
|
method.
|
2022-03-18 17:38:22 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
"""
|
|
|
|
Initialize toddler.
|
|
|
|
"""
|
|
|
|
self.toddler = scm_request_processor.SCMRequestProcessor()
|
|
|
|
self.toddler.pagure_io = Mock()
|
|
|
|
self.toddler.dist_git = Mock()
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_bug_retrieve_error(self, mock_bz):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug couldn't be retrieved.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
bug_id = "123"
|
|
|
|
|
|
|
|
mock_bz.get_bug.side_effect = Exception("error")
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = (
|
|
|
|
"The Bugzilla bug could not be verified. The following "
|
|
|
|
"error was encountered: error"
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_no_bug(self, mock_bz):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when the bug is not found in bugzilla.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
branch = "rawhide"
|
|
|
|
bug_id = "123"
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = None
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = "The Bugzilla bug doesn't exist"
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_epel_branch_invalid_bug(self, mock_bz):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when the requested branch is for EPEL, but
|
|
|
|
the review bug isn't.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
branch = "epel8"
|
|
|
|
bug_id = "123"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.product = "Fedora"
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = (
|
|
|
|
'The Bugzilla bug is for "Fedora" but the '
|
|
|
|
"requested branch is an EPEL branch"
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_not_epel_branch_epel_bug(self, mock_bz):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when the requested branch isn't for EPEL, but
|
|
|
|
the review bug is.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.product = "Fedora EPEL"
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = (
|
|
|
|
'The Bugzilla bug is for "Fedora EPEL" but the ' 'requested branch is "{0}"'
|
|
|
|
).format(branch)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_invalid_component(self, mock_bz):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when the namespace provided is not known.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = None
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
|
|
|
self.toddler.pagure_namespace_to_component = {}
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = "The Bugzilla bug provided is not the proper type"
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_invalid_product(self, mock_bz):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when the namespace provided is not a valid product.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = "invalid"
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
error = 'The Bugzilla bug provided is not for "{0}" or "{0}"'.format(namespace)
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_not_assigned(self, mock_bz):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when the bug is not assigned to anybody.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = None
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = "The Bugzilla bug provided is not assigned to anyone"
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_user_not_in_FAS(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug creator doesn't exists in FAS.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = user
|
|
|
|
mock_bug.creator = user
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
|
|
|
mock_fas.get_user_by_email.return_value = None
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
error = (
|
2022-03-21 13:25:42 +01:00
|
|
|
"The Bugzilla review bug creator could not be found in "
|
|
|
|
"FAS. Make sure your FAS email address is the same as in "
|
|
|
|
"Bugzilla."
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
mock_fas.get_user_by_email.assert_called_with(user)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_user_not_matching_requester(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug creator doesn't match the ticket requester.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = user
|
|
|
|
mock_bug.creator = user
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.return_value = {"username": "not_zlopez"}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
error = (
|
2022-03-21 13:25:42 +01:00
|
|
|
"The Bugzilla review bug creator " "didn't match the requester in Pagure."
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
|
|
|
mock_fas.get_user_by_email.assert_called_with(user)
|
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_reviewer_not_in_FAS(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug reviewer isn't in FAS.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = user
|
|
|
|
mock_bug.creator = user
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_bug.flags = [{"name": "fedora-review", "status": ""}]
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.side_effect = [{"username": user}, None]
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
error = (
|
|
|
|
'The email address "{0}" of the Bugzilla reviewer '
|
2022-03-21 13:25:42 +01:00
|
|
|
"is not tied to a user in FAS or FAS check failed. "
|
|
|
|
"Group membership can't be validated.".format(user)
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(user)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_reviewer_not_packager(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug reviewer is not in packager group.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = user
|
|
|
|
mock_bug.creator = user
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_bug.flags = [{"name": "fedora-review", "status": ""}]
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.return_value = {"username": user}
|
2022-03-18 17:38:22 +01:00
|
|
|
mock_fas.user_member_of.return_value = False
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
error = (
|
2022-03-21 13:25:42 +01:00
|
|
|
"The Bugzilla bug's review "
|
2022-03-18 17:38:22 +01:00
|
|
|
'is approved by a user "{0}" that is '
|
2022-03-21 13:25:42 +01:00
|
|
|
"not a packager or FAS check failed".format(user)
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(user)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.user_member_of.assert_called_with({"username": user}, "packager")
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_submitter_not_packager(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug submitter is not in packager group.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = user
|
|
|
|
mock_bug.creator = user
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_bug.flags = [{"name": "fedora-review", "status": ""}]
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.return_value = {"username": user}
|
2022-03-18 17:38:22 +01:00
|
|
|
mock_fas.user_member_of.side_effect = [True, False]
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = 'The Bugzilla reporter "{0}"' "is not a packager".format(user)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(user)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.user_member_of.assert_has_calls(
|
|
|
|
[
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
]
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_approved_by_creator(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug is approved by creator.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = user
|
|
|
|
mock_bug.creator = user
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_bug.flags = [{"name": "fedora-review", "status": "", "setter": user}]
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.return_value = {"username": user}
|
2022-03-18 17:38:22 +01:00
|
|
|
mock_fas.user_member_of.return_value = True
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
error = (
|
2022-03-21 13:25:42 +01:00
|
|
|
"The Bugzilla bug's review is approved "
|
|
|
|
"by the person creating the bug. This is "
|
|
|
|
"not allowed."
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(user)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.user_member_of.assert_has_calls(
|
|
|
|
[
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
]
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_not_approved_by_assignee(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug is not approved by assignee.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = user
|
|
|
|
mock_bug.creator = user
|
|
|
|
mock_bug.flags = [
|
2022-03-21 13:25:42 +01:00
|
|
|
{"name": "fedora-review", "status": "", "setter": "not@setter.com"}
|
2022-03-18 17:38:22 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.return_value = {"username": user, "emails": []}
|
2022-03-18 17:38:22 +01:00
|
|
|
mock_fas.user_member_of.return_value = True
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = "The review is not approved by " "the assignee of the Bugzilla " "bug"
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(user)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.user_member_of.assert_has_calls(
|
|
|
|
[
|
|
|
|
call({"username": user, "emails": []}, "packager"),
|
|
|
|
call({"username": user, "emails": []}, "packager"),
|
|
|
|
]
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_approved_in_past(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug was approved more than 60 days ago.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
assignee = "assignee"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = assignee
|
|
|
|
mock_bug.creator = user
|
|
|
|
|
|
|
|
mock_bug.flags = [
|
|
|
|
{
|
|
|
|
"name": "fedora-review",
|
|
|
|
"status": "",
|
|
|
|
"setter": assignee,
|
2022-08-24 15:33:03 +02:00
|
|
|
"modification_date": xmlrpc.client.DateTime(
|
|
|
|
arrow.utcnow().shift(days=-61).datetime
|
|
|
|
),
|
2022-03-18 17:38:22 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
|
|
|
mock_fas.get_user_by_email.return_value = {
|
|
|
|
"username": user,
|
|
|
|
}
|
|
|
|
mock_fas.user_member_of.return_value = True
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = "The Bugzilla bug's review " "was approved over 60 days ago"
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(assignee)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.user_member_of.assert_has_calls(
|
|
|
|
[
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
]
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_flags_missing(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that error will be raised when the bug flags are missing.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.creator = user
|
|
|
|
mock_bug.flags = []
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
|
|
|
mock_fas.get_user_by_email.return_value = {
|
|
|
|
"username": user,
|
|
|
|
}
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
error = "The Bugzilla bug is not approved yet"
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"summary, error",
|
|
|
|
[
|
|
|
|
("", 'Invalid title for this Bugzilla bug (no ":" present)'),
|
|
|
|
("Review: package", 'Invalid title for this Bugzilla bug (no "-" present)'),
|
2022-03-21 13:25:42 +01:00
|
|
|
(
|
|
|
|
"Review: package - 1.0",
|
|
|
|
(
|
2022-03-18 17:38:22 +01:00
|
|
|
'The package in the Bugzilla bug "package" doesn\'t match '
|
|
|
|
'the one provided "repo"'
|
2022-03-21 13:25:42 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-03-18 17:38:22 +01:00
|
|
|
)
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
2022-03-21 13:25:42 +01:00
|
|
|
def test_validate_review_bug_invalid_summary(
|
|
|
|
self, mock_bz, mock_fas, summary, error
|
|
|
|
):
|
2022-03-18 17:38:22 +01:00
|
|
|
"""
|
|
|
|
Assert that error will be raised when bug summary is not correct.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
assignee = "assignee"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = assignee
|
|
|
|
mock_bug.creator = user
|
|
|
|
mock_bug.summary = summary
|
|
|
|
|
|
|
|
mock_bug.flags = [
|
|
|
|
{
|
|
|
|
"name": "fedora-review",
|
|
|
|
"status": "+",
|
|
|
|
"setter": assignee,
|
2022-08-24 15:33:03 +02:00
|
|
|
"modification_date": xmlrpc.client.DateTime(arrow.utcnow().datetime),
|
2022-03-18 17:38:22 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
|
|
|
mock_fas.get_user_by_email.return_value = {
|
|
|
|
"username": user,
|
|
|
|
}
|
|
|
|
mock_fas.user_member_of.return_value = True
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=re.escape(error)):
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(assignee)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.user_member_of.assert_has_calls(
|
|
|
|
[
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
]
|
|
|
|
)
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.fedora_account")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.bugzilla_system")
|
|
|
|
def test_validate_review_bug_valid(self, mock_bz, mock_fas):
|
|
|
|
"""
|
|
|
|
Assert that no error will be raised when bug is valid.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
repo = "repo"
|
|
|
|
namespace = "rpms"
|
|
|
|
branch = "f36"
|
|
|
|
bug_id = "123"
|
|
|
|
user = "zlopez"
|
|
|
|
assignee = "assignee"
|
|
|
|
|
|
|
|
mock_bug = Mock()
|
|
|
|
mock_bug.component = namespace
|
|
|
|
mock_bug.product = namespace
|
|
|
|
mock_bug.assigned_to = assignee
|
|
|
|
mock_bug.creator = user
|
|
|
|
mock_bug.summary = "Review: repo - Project for everyday work"
|
|
|
|
|
|
|
|
mock_bug.flags = [
|
|
|
|
{
|
|
|
|
"name": "fedora-review",
|
|
|
|
"status": "+",
|
|
|
|
"setter": assignee,
|
2022-08-24 15:33:03 +02:00
|
|
|
"modification_date": xmlrpc.client.DateTime(arrow.utcnow().datetime),
|
2022-03-18 17:38:22 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "random-flag",
|
2022-03-21 13:25:42 +01:00
|
|
|
},
|
2022-03-18 17:38:22 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
mock_bz.get_bug.return_value = mock_bug
|
|
|
|
|
|
|
|
mock_fas.get_user_by_email.return_value = {
|
|
|
|
"username": user,
|
|
|
|
}
|
|
|
|
mock_fas.user_member_of.return_value = True
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
self.toddler.pagure_namespace_to_component = {namespace: namespace}
|
|
|
|
self.toddler.pagure_namespace_to_product = {namespace: [namespace, namespace]}
|
2022-03-18 17:38:22 +01:00
|
|
|
|
|
|
|
# Method to test
|
|
|
|
self.toddler.validate_review_bug(bug_id, repo, branch, pagure_user=user)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
mock_bz.get_bug.assert_called_with(bug_id)
|
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.get_user_by_email.assert_has_calls([call(user), call(assignee)])
|
2022-03-18 17:38:22 +01:00
|
|
|
|
2022-03-21 13:25:42 +01:00
|
|
|
mock_fas.user_member_of.assert_has_calls(
|
|
|
|
[
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
call({"username": user}, "packager"),
|
|
|
|
]
|
|
|
|
)
|
2022-03-21 13:22:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestValidEpelPackage:
|
|
|
|
"""
|
2022-03-21 13:44:45 +01:00
|
|
|
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.valid_epel_package`
|
|
|
|
method.
|
2022-03-21 13:22:10 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def setup(self):
|
|
|
|
"""
|
|
|
|
Initialize toddler.
|
|
|
|
"""
|
|
|
|
self.toddler = scm_request_processor.SCMRequestProcessor()
|
|
|
|
self.toddler.pagure_io = Mock()
|
|
|
|
self.toddler.dist_git = Mock()
|
|
|
|
self.toddler.requests_session = Mock()
|
|
|
|
|
|
|
|
def test_valid_epel_package_bad_response(self):
|
|
|
|
"""
|
|
|
|
Assert that method will raise error when bad response is retrieved.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
name = "package"
|
|
|
|
branch = "epel8"
|
|
|
|
|
|
|
|
mock_response = Mock()
|
|
|
|
mock_response.status_code = 500
|
|
|
|
self.toddler.requests_session.get.return_value = mock_response
|
|
|
|
|
|
|
|
error = "Couldn't retrieve the list of official EL packages"
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
with pytest.raises(ValidationError, match=error):
|
|
|
|
self.toddler.valid_epel_package(name=name, branch=branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
self.toddler.requests_session.get.assert_called_with(
|
|
|
|
"https://infrastructure.fedoraproject.org/repo/json/pkg_el8.json"
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_valid_epel_package_epel6_noarch(self):
|
|
|
|
"""
|
|
|
|
Assert that method will return False when epel6 noarch package is introduced.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
name = "package"
|
|
|
|
branch = "epel6"
|
|
|
|
|
|
|
|
mock_response = Mock()
|
|
|
|
mock_response.status_code = 200
|
|
|
|
mock_response.json.return_value = {
|
|
|
|
"arches": ["noarch", "ppc", "i386"],
|
2022-03-21 13:25:42 +01:00
|
|
|
"packages": {name: {"arch": ["noarch"]}},
|
2022-03-21 13:22:10 +01:00
|
|
|
}
|
|
|
|
self.toddler.requests_session.get.return_value = mock_response
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
result = self.toddler.valid_epel_package(name=name, branch=branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
self.toddler.requests_session.get.assert_called_with(
|
|
|
|
"https://infrastructure.fedoraproject.org/repo/json/pkg_el6.json"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
def test_valid_epel_package_epel7_noarch(self):
|
|
|
|
"""
|
|
|
|
Assert that method will return False when epel7 noarch package is introduced.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
name = "package"
|
|
|
|
branch = "epel7"
|
|
|
|
|
|
|
|
mock_response = Mock()
|
|
|
|
mock_response.status_code = 200
|
|
|
|
mock_response.json.return_value = {
|
|
|
|
"arches": ["noarch", "ppc", "i386"],
|
2022-03-21 13:25:42 +01:00
|
|
|
"packages": {name: {"arch": ["noarch"]}},
|
2022-03-21 13:22:10 +01:00
|
|
|
}
|
|
|
|
self.toddler.requests_session.get.return_value = mock_response
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
result = self.toddler.valid_epel_package(name=name, branch=branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
self.toddler.requests_session.get.assert_called_with(
|
|
|
|
"https://infrastructure.fedoraproject.org/repo/json/pkg_el7.json"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result is False
|
|
|
|
|
|
|
|
def test_valid_epel_package_valid_package(self):
|
|
|
|
"""
|
|
|
|
Assert that method will return True when package is valid.
|
|
|
|
"""
|
|
|
|
# Preparation
|
|
|
|
name = "package"
|
|
|
|
branch = "epel8"
|
|
|
|
|
|
|
|
mock_response = Mock()
|
|
|
|
mock_response.status_code = 200
|
|
|
|
mock_response.json.return_value = {
|
|
|
|
"arches": ["noarch", "ppc", "i386"],
|
2022-03-21 13:25:42 +01:00
|
|
|
"packages": {name: {"arch": ["x86_64"]}},
|
2022-03-21 13:22:10 +01:00
|
|
|
}
|
|
|
|
self.toddler.requests_session.get.return_value = mock_response
|
|
|
|
|
|
|
|
# Method to test
|
|
|
|
result = self.toddler.valid_epel_package(name=name, branch=branch)
|
|
|
|
|
|
|
|
# Asserts
|
|
|
|
self.toddler.requests_session.get.assert_called_with(
|
|
|
|
"https://infrastructure.fedoraproject.org/repo/json/pkg_el8.json"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result is True
|
2022-03-22 16:16:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestMain:
|
|
|
|
"""
|
|
|
|
Test class for `toddlers.plugins.scm_request_processor.main` function.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def test_main_no_args(self, capsys):
|
|
|
|
"""Assert that help is printed if no arg is provided."""
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
scm_request_processor.main([])
|
|
|
|
|
|
|
|
out, err = capsys.readouterr()
|
|
|
|
assert out == ""
|
|
|
|
# Expecting something along these lines, but don't make the test too tight:
|
|
|
|
#
|
|
|
|
# usage: pytest [-h] [--dry-run] [-q | --debug] conf [username]
|
|
|
|
# pytest: error: the following arguments are required: conf
|
|
|
|
assert err.startswith("usage:")
|
|
|
|
assert "error: the following arguments are required:" in err
|
|
|
|
|
|
|
|
@patch("toml.load")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.SCMRequestProcessor.process")
|
|
|
|
@patch("toddlers.plugins.scm_request_processor.pagure")
|
|
|
|
def test_main(self, mock_pagure, mock_process, mock_toml):
|
|
|
|
"""Assert that main is initializing config and message correctly."""
|
|
|
|
# Preparation
|
|
|
|
mock_toml.return_value = {}
|
|
|
|
mock_pagure_io = Mock()
|
|
|
|
mock_issue = {"id": 100}
|
|
|
|
mock_pagure_io.get_issue.return_value = mock_issue
|
|
|
|
|
|
|
|
mock_pagure.set_pagure.return_value = mock_pagure_io
|
|
|
|
|
|
|
|
# Function to test
|
|
|
|
scm_request_processor.main(["--config", "test.cfg", "100"])
|
|
|
|
|
|
|
|
# Assertions
|
|
|
|
mock_toml.assert_called_with("test.cfg")
|
|
|
|
mock_pagure.set_pagure.assert_called_with({})
|
|
|
|
mock_pagure_io.get_issue.assert_called_with(
|
|
|
|
100, scm_request_processor.PROJECT_NAMESPACE
|
|
|
|
)
|
|
|
|
message = IssueNewV1()
|
|
|
|
message.body["issue"] = mock_issue
|
2022-03-24 17:57:29 +01:00
|
|
|
message.body["project"] = {"fullname": scm_request_processor.PROJECT_NAMESPACE}
|
2022-03-22 16:16:30 +01:00
|
|
|
mock_process.assert_called_with(config={}, message=message)
|