Fix tests

This will fix the RemovedInErrors for setup method in pytest and fixes the issue
with pagure message schema which made some fields required.

Signed-off-by: Michal Konecny <mkonecny@redhat.com>
This commit is contained in:
Michal Konecny 2024-02-07 17:00:41 +01:00
parent 916ab9ee62
commit ee49ffdd41
13 changed files with 132 additions and 93 deletions

View file

@ -1,6 +1,7 @@
"""
Unit tests for `toddler.plugins.pdc_unretire_packages`
"""
import datetime
import logging
from unittest.mock import call, MagicMock, Mock, patch
@ -56,8 +57,11 @@ class TestProcess:
"""
caplog.set_level(logging.INFO)
msg = IssueNewV1()
msg.body = {"project": {"fullname": "foo/bar"}}
body = {
"project": {"fullname": "foo/bar"},
"issue": {"user": {"name": "zlopez"}},
}
msg = IssueNewV1(body=body)
with patch(
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages.process_ticket"
@ -76,11 +80,16 @@ class TestProcess:
"""
caplog.set_level(logging.INFO)
msg = IssueNewV1()
msg.body = {
body = {
"project": {"fullname": pdc_unretire_packages.PROJECT_NAMESPACE},
"issue": {"id": 100, "status": "Close", "title": "unrere popa"},
"issue": {
"id": 100,
"status": "Closed",
"title": "unrere popa",
"user": {"name": "zlopez"},
},
}
msg = IssueNewV1(body=body)
with patch(
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages.process_ticket"
@ -99,11 +108,16 @@ class TestProcess:
"""
caplog.set_level(logging.INFO)
msg = IssueNewV1()
msg.body = {
body = {
"project": {"fullname": pdc_unretire_packages.PROJECT_NAMESPACE},
"issue": {"id": 100, "status": "Open", "title": "unrere popa"},
"issue": {
"id": 100,
"status": "Open",
"title": "unrere popa",
"user": {"name": "zlopez"},
},
}
msg = IssueNewV1(body=body)
with patch(
"toddlers.plugins.pdc_unretire_packages.PDCUnretirePackages.process_ticket"
@ -127,12 +141,17 @@ class TestProcess:
"""
Assert that ticket will be close if BaseException will appear during ticket process
"""
msg = IssueNewV1()
issue = {"id": 100, "status": "Open", "title": "Unretire package_name"}
msg.body = {
issue = {
"id": 100,
"status": "Open",
"title": "Unretire package_name",
"user": {"name": "zlopez"},
}
body = {
"project": {"fullname": pdc_unretire_packages.PROJECT_NAMESPACE},
"issue": issue,
}
msg = IssueNewV1(body=body)
config = {
"dist_git_url": "https://src.fedoraproject.org",
"dist_git_token": "Private API Key",
@ -161,12 +180,17 @@ class TestProcess:
Assert that message toddler will be initialized correctly, if message passes
initial processing.
"""
msg = IssueNewV1()
issue = {"id": 100, "status": "Open", "title": "unretire package"}
msg.body = {
issue = {
"id": 100,
"status": "Open",
"title": "unretire package",
"user": {"name": "zlopez"},
}
body = {
"project": {"fullname": pdc_unretire_packages.PROJECT_NAMESPACE},
"issue": issue,
}
msg = IssueNewV1(body=body)
config = {
"dist_git_url": "dist_git_url",
"dist_git_token": "dist_git_token",
@ -200,7 +224,7 @@ class TestProcessTicket:
method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler
"""
@ -474,7 +498,7 @@ class TestIsPackageReadyForUnretirement:
._is_package_ready_for_unretirement` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler
"""
@ -564,7 +588,7 @@ class TestVerifyPackageNotRetiredForReason:
._verify_package_not_retired_for_reason` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -599,7 +623,7 @@ class TestVerifyBugzillaNeedToBeChecked:
._verify_bugzilla_need_to_be_checked` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -659,7 +683,7 @@ class TestVerifyBugzillaTicket:
._verify_bugzilla_ticket` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -766,7 +790,7 @@ class TestGetTagsToUnblock:
method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -812,7 +836,7 @@ class TestGetLastFedoraVersionBranchName:
._get_last_fedora_version_branch_name` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -878,7 +902,7 @@ class TestIsNeedToUnblockTagsOnKoji:
._is_need_to_unblock_tags_on_koji` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -993,7 +1017,7 @@ class TestUnblockTagsOnKoji:
._is_need_to_unblock_tags_on_koji` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -1038,7 +1062,7 @@ class TestAdjustEolPdc:
._adjust_eol_pdc` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -1141,7 +1165,7 @@ class TestNamespaceToPdc:
._namespace_to_pdc` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -1173,7 +1197,7 @@ class TestGetProperEolForBranches:
.get_proper_eol_for_branches` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -1276,7 +1300,7 @@ class TestIsUrlExist:
._is_url_exist` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -1336,7 +1360,7 @@ class TestMain:
# Prepare
toml_load_mock.return_value = {}
pagure_io_mock = Mock()
issue_mock = {"id": 100}
issue_mock = {"id": 100, "user": {"name": "zlopez"}}
pagure_io_mock.get_issue.return_value = issue_mock
pagure_mock.set_pagure.return_value = pagure_io_mock
@ -1350,7 +1374,9 @@ class TestMain:
pagure_io_mock.get_issue.assert_called_with(
100, pdc_unretire_packages.PROJECT_NAMESPACE
)
message = IssueNewV1()
message.body["issue"] = issue_mock
message.body["project"] = {"fullname": pdc_unretire_packages.PROJECT_NAMESPACE}
body = {
"project": {"fullname": pdc_unretire_packages.PROJECT_NAMESPACE},
"issue": issue_mock,
}
message = IssueNewV1(body=body)
process_mock.assert_called_with(config={}, message=message)

View file

@ -1,6 +1,7 @@
"""
Unit tests for `toddlers.plugins.scm_request_processor`
"""
import json
import logging
import re
@ -63,8 +64,11 @@ class TestProcess:
"""
caplog.set_level(logging.INFO)
msg = IssueNewV1()
msg.body = {"project": {"fullname": "foo/bar"}}
body = {
"project": {"fullname": "foo/bar"},
"issue": {"user": {"name": "zlopez"}},
}
msg = IssueNewV1(body=body)
with patch(
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
@ -84,11 +88,11 @@ class TestProcess:
"""
caplog.set_level(logging.INFO)
msg = IssueNewV1()
msg.body = {
body = {
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
"issue": {"id": 100, "status": "Closed"},
"issue": {"id": 100, "status": "Closed", "user": {"name": "zlopez"}},
}
msg = IssueNewV1(body=body)
with patch(
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
@ -110,12 +114,12 @@ class TestProcess:
pagure_user = "pagure_user"
config = {"pagure_user": pagure_user}
msg = IssueCommentAddedV1()
msg.body = {
body = {
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
"issue": {"status": "Open"},
"issue": {"status": "Open", "user": {"name": "zlopez"}},
"agent": pagure_user,
}
msg = IssueCommentAddedV1(body=body)
with patch(
"toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket"
@ -141,13 +145,13 @@ class TestProcess:
Assert that message toddler will be initialized correctly, if message passes
initial processing.
"""
msg = IssueNewV1()
issue = {"id": 100, "status": "Open"}
msg.body = {
issue = {"id": 100, "status": "Open", "user": {"name": "zlopez"}}
body = {
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
"issue": issue,
"agent": "agent",
}
msg = IssueNewV1(body=body)
config = {
"branch_slas": {},
"monitoring_choices": [],
@ -194,13 +198,13 @@ class TestProcess:
Assert that message toddler will be initialized correctly, if message passes
initial processing.
"""
msg = IssueNewV1()
issue = {"id": 100, "status": "Open"}
msg.body = {
issue = {"id": 100, "status": "Open", "user": {"name": "zlopez"}}
body = {
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
"issue": issue,
"agent": "agent",
}
msg = IssueNewV1(body=body)
config = {
"branch_slas": {},
"monitoring_choices": [],
@ -240,7 +244,7 @@ class TestProcessTicket:
method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -444,7 +448,7 @@ class TestVerifySLAs:
Test class for `toddlers.plugins.scm_request_processor.SCMRequestProcessor.verify_slas` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -583,7 +587,7 @@ class TestCreateNewRepo:
method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -1447,7 +1451,7 @@ class TestCreateNewBranch:
method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -2047,7 +2051,7 @@ class TestValidateReviewBug:
method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -2786,7 +2790,7 @@ class TestValidEpelPackage:
method.
"""
def setup(self):
def setup_method(self):
"""
Initialize toddler.
"""
@ -3009,7 +3013,7 @@ class TestMain:
# Preparation
mock_toml.return_value = {}
mock_pagure_io = Mock()
mock_issue = {"id": 100}
mock_issue = {"id": 100, "user": {"name": "zlopez"}}
mock_pagure_io.get_issue.return_value = mock_issue
mock_pagure.set_pagure.return_value = mock_pagure_io
@ -3023,7 +3027,9 @@ class TestMain:
mock_pagure_io.get_issue.assert_called_with(
100, scm_request_processor.PROJECT_NAMESPACE
)
message = IssueNewV1()
message.body["issue"] = mock_issue
message.body["project"] = {"fullname": scm_request_processor.PROJECT_NAMESPACE}
body = {
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
"issue": mock_issue,
}
message = IssueNewV1(body=body)
mock_process.assert_called_with(config={}, message=message)

View file

@ -1,6 +1,7 @@
"""
Unit tests for `toddlers.utils.git`.
"""
from unittest.mock import Mock, patch
from toddlers.utils.git import clone_repo, GitRepo
@ -50,7 +51,7 @@ class TestGitRepoFirstCommit:
Test class for `toddlers.utils.git.GitRepo.first_commit` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize the GitRepo object.
"""
@ -101,7 +102,7 @@ class TestGitRepoGetLastCommitMessage:
Test class for `toddlers.utils.git.GitRepo.get_last_commit_message` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize the GitRepo object.
"""
@ -148,7 +149,7 @@ class TestGitRepoGetLastCommitDate:
Test class for `toddlers.utils.git.GitRepo.get_last_commit_date` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize the GitRepo object.
"""
@ -195,7 +196,7 @@ class TestGitRepoRevertLastCommit:
Test class for `toddlers.utils.git.GitRepo.revert_last_commit` method.
"""
def setup(self):
def setup_method(self):
"""
Initialize the GitRepo object.
"""

View file

@ -1,6 +1,7 @@
"""
Module for testing `toddlers.utils.package_summaries`.
"""
import bz2
import gzip
import hashlib
@ -18,7 +19,7 @@ from toddlers.utils.package_summaries import PackageSummaries
class TestGetPrimaryXML:
"""Test class for `toddlers.utils.package_summaries.PackageSummaries.get_primary_xml`."""
def setup(self):
def setup_method(self):
"""This will be run before every test case in this class."""
self.ps = PackageSummaries()
@ -427,7 +428,7 @@ class TestGetPrimaryXML:
class TestGetPackageSummaries:
"""Test class for `toddlers.utils.package_summaries.PackageSummaries.get_package_summaries`."""
def setup(self):
def setup_method(self):
"""This will be run before every test case in this class."""
self.ps = PackageSummaries()

View file

@ -1,6 +1,7 @@
"""
Unit tests for `toddlers.utils.pagure`.
"""
import json
from unittest.mock import call, Mock, patch
@ -54,7 +55,7 @@ class TestPagureGetAuthHeader:
Test class for `toddlers.pagure.Pagure.get_auth_header` function.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -84,7 +85,7 @@ class TestPagureGetIssue:
Test class for `toddlers.pagure.Pagure.get_issue` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -148,7 +149,7 @@ class TestPagureCloseIssue:
Test class for `toddlers.pagure.Pagure.close_issue` function.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -218,7 +219,7 @@ class TestPagureAddCommentToIssue:
Test class for `toddlers.pagure.Pagure.add_comment_to_issue` function.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -280,7 +281,7 @@ class TestPagureUserExists:
Test class for `toddlers.pagure.Pagure.user_exists` function.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -357,7 +358,7 @@ class TestPagureNewProject:
Test class for `toddlers.pagure.Pagure.new_project` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -655,7 +656,7 @@ class TestPagureNewBranch:
Test class for `toddlers.pagure.Pagure.new_branch` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -804,7 +805,7 @@ class TestPagureSetMonitoringStatus:
Test class for `toddlers.pagure.Pagure.set_monitoring_status` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -868,7 +869,7 @@ class TestPagureChangeProjectMainAdmin:
Test class for `toddlers.pagure.Pagure.change_project_main_admin` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -932,7 +933,7 @@ class TestPagureGetProjectContributors:
Test class for `toddlers.pagure.Pagure.get_project_contributors` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -1024,7 +1025,7 @@ class TestPagureGetBranches:
Test class for `toddlers.pagure.Pagure.get_branches` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -1116,7 +1117,7 @@ class TestPagureGetDefaultBranch:
Test class for `toddlers.pagure.Pagure.get_default_branch` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -1208,7 +1209,7 @@ class TestPagureGetProject:
Test class for `toddlers.pagure.Pagure.get_project` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -1296,7 +1297,7 @@ class TestPagureIsProjectOrphaned:
Test class for `toddlers.pagure.Pagure.is_project_orphaned` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""
@ -1389,7 +1390,7 @@ class TestPagureAssignMaintainerToProject:
Test class for `toddlers.pagure.Pagure.assign_maintainer_to_project` method.
"""
def setup(self):
def setup_method(self):
"""
Setup method for the test class.
"""

View file

@ -1,6 +1,7 @@
"""
Unit tests for `toddlers.utils.pdc`.
"""
from unittest.mock import call, MagicMock
import pytest
@ -89,7 +90,7 @@ class TestPdcGetSla:
Test class for `toddlers.utils.pdc.get_sla` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -125,7 +126,7 @@ class TestPdcGetSlaForBranch:
Test class for `toddlers.utils.pdc.get_sla_for_branch` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -179,7 +180,7 @@ class TestPdcNewSLAToBranch:
Test class for `toddlers.utils.pdc.new_sla_to_branch` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -248,7 +249,7 @@ class TestPdcGetBranch:
Test class for `toddlers.utils.pdc.get_branch` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -300,7 +301,7 @@ class TestPdcNewBranch:
Test class for `toddlers.utils.pdc.new_branch` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -357,7 +358,7 @@ class TestPdcGetGlobalComponent:
Test class for `toddlers.utils.pdc.get_global_component` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -405,7 +406,7 @@ class TestPdcNewGlobalComponent:
Test class for `toddlers.utils.pdc.new_global_component` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -454,7 +455,7 @@ class TestPdcGetBranchSlas:
Test class for `toddlers.utils.pdc.get_branch_slas` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""
@ -510,7 +511,7 @@ class TestPdcAdjustEol:
Test class for `toddlers.utils.pdc.adjust_eol` function.
"""
def setup(self):
def setup_method(self):
"""
Setup the PDC module.
"""

View file

@ -6,6 +6,7 @@ from distgit to bugzilla.
Authors: Michal Konecny <mkonecny@redhat.com>
"""
import argparse
import collections
import logging

View file

@ -4,6 +4,7 @@ This is a script to automate unretirement of package automatically, when ticket
Authors: Anton Medvedev <amedvede@redhat.com>
"""
import argparse
import datetime
import json
@ -673,9 +674,8 @@ def main(args):
issue = pagure_io.get_issue(ticket, PROJECT_NAMESPACE)
# Convert issue to message
message = IssueNewV1()
message.body["issue"] = issue
message.body["project"] = {"fullname": PROJECT_NAMESPACE}
body = {"project": {"fullname": PROJECT_NAMESPACE}, "issue": issue}
message = IssueNewV1(body=body)
_log.debug("Message prepared: {}".format(message.body))
PDCUnretirePackages().process(

View file

@ -6,6 +6,7 @@ https://pagure.io/releng/fedora-scm-requests/issues.
Authors: Michal Konecny <mkonecny@redhat.com>
"""
import argparse
import fnmatch
import json
@ -1125,9 +1126,8 @@ def main(args):
issue = pagure_io.get_issue(ticket, PROJECT_NAMESPACE)
# Convert issue to message
message = IssueNewV1()
message.body["issue"] = issue
message.body["project"] = {"fullname": PROJECT_NAMESPACE}
body = {"project": {"fullname": PROJECT_NAMESPACE}, "issue": issue}
message = IssueNewV1(body=body)
_log.debug("Message prepared: {}".format(message.body))
SCMRequestProcessor().process(

View file

@ -35,7 +35,6 @@ def get_fasjson() -> Client:
def __get_fas_grp_member(group: str = "packager") -> List[Any]:
"""Retrieve from FAS the list of users in the packager group."""
fasjson = get_fasjson()
try:
return fasjson.list_group_members(groupname=group).result or []
@ -71,7 +70,7 @@ def get_bz_email_user(
bz_email = bz_email.lower().strip()
bz_email = email_overrides.get(bz_email, bz_email)
return bz_email.strip()
return str(bz_email.strip())
def get_bz_email_group(

View file

@ -3,6 +3,7 @@ Wrapper for git operations using GitPython library.
Author: mkonecny@redhat.com
"""
from typing import Optional, Union
import git

View file

@ -11,6 +11,7 @@ This prevents relying on remote services such as mdapi (of which a lot of
code here is coming from) when needing to access the summary of a lot of
packages.
"""
import contextlib
import hashlib
import logging

View file

@ -15,6 +15,7 @@ Examples:
pagure_io.close_issue("<repo>", <issue_id>)
"""
import json
import logging
from typing import Any, Optional