Add manual way to run scm_request_processor toddler
This is helpful when trying to test the toddler manually. It now has main and could be ran as separate script. It just needs configuration file and ticket number on releng/fedora-scm-requests. Signed-off-by: Michal Konečný <mkonecny@redhat.com>
This commit is contained in:
parent
151820072a
commit
c242621af0
2 changed files with 138 additions and 1 deletions
|
@ -2519,3 +2519,49 @@ class TestValidEpelPackage:
|
|||
)
|
||||
|
||||
assert result is True
|
||||
|
||||
|
||||
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
|
||||
mock_process.assert_called_with(config={}, message=message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue