diff options
author | 2023-01-08 22:17:13 +0200 | |
---|---|---|
committer | 2023-03-01 21:18:47 +0200 | |
commit | 6819d87b2e1a65aa57f959f07b8d226578dda634 (patch) | |
tree | 613aa470f4ca32930d5415f87c7c825ab5fc47fb /tests | |
parent | commit: update help text for `--edit` (diff) | |
download | pkgdev-6819d87b2e1a65aa57f959f07b8d226578dda634.tar.gz pkgdev-6819d87b2e1a65aa57f959f07b8d226578dda634.tar.bz2 pkgdev-6819d87b2e1a65aa57f959f07b8d226578dda634.zip |
pkgdev bugs: new tool for filing stable bugs
This new tool isn't complete, and any usage should be manually monitored
for failures or incorrect results. This tool will be improved in the
future, but for now it's a good start.
Resolves: https://github.com/pkgcore/pkgdev/issues/113
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scripts/test_pkgdev_bugs.py | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/scripts/test_pkgdev_bugs.py b/tests/scripts/test_pkgdev_bugs.py new file mode 100644 index 0000000..f23051e --- /dev/null +++ b/tests/scripts/test_pkgdev_bugs.py @@ -0,0 +1,104 @@ +import itertools +import os +import sys +import json +import textwrap +from types import SimpleNamespace +from unittest.mock import patch + +import pytest +from pkgcore.ebuild.atom import atom +from pkgcore.test.misc import FakePkg +from pkgdev.scripts import pkgdev_bugs as bugs +from snakeoil.formatters import PlainTextFormatter +from snakeoil.osutils import pjoin + +def mk_pkg(repo, cpvstr, maintainers, **kwargs): + kwargs.setdefault("KEYWORDS", ["~amd64"]) + pkgdir = os.path.dirname(repo.create_ebuild(cpvstr, **kwargs)) + # stub metadata + with open(pjoin(pkgdir, 'metadata.xml'), 'w') as f: + f.write(textwrap.dedent(f"""\ + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd"> + <pkgmetadata> + <maintainer type="person"> + {' '.join(f'<email>{maintainer}@gentoo.org</email>' for maintainer in maintainers)} + </maintainer> + </pkgmetadata> + """)) + + +def mk_repo(repo): + mk_pkg(repo, 'cat/u-0', ['dev1']) + mk_pkg(repo, 'cat/z-0', [], RDEPEND=['cat/u', 'cat/x']) + mk_pkg(repo, 'cat/v-0', ['dev2'], RDEPEND='cat/x') + mk_pkg(repo, 'cat/y-0', ['dev1'], RDEPEND=['cat/z', 'cat/v']) + mk_pkg(repo, 'cat/x-0', ['dev3'], RDEPEND='cat/y') + mk_pkg(repo, 'cat/w-0', ['dev3'], RDEPEND='cat/x') + + +class BugsSession: + def __init__(self): + self.counter = iter(itertools.count(1)) + self.calls = [] + + def __enter__(self): + return self + + def __exit__(self, *_args): + ... + + def read(self): + return json.dumps({'id': next(self.counter)}).encode('utf-8') + + def __call__(self, request, *_args, **_kwargs): + self.calls.append(json.loads(request.data)) + return self + + +class TestBugFiling: + def test_bug_filing(self, repo): + mk_repo(repo) + session = BugsSession() + pkg = max(repo.itermatch(atom('=cat/u-0'))) + with patch('pkgdev.scripts.pkgdev_bugs.urllib.urlopen', session): + bugs.GraphNode(((pkg, {'*'}), )).file_bug("API", frozenset()) + assert len(session.calls) == 1 + call = session.calls[0] + assert call['Bugzilla_api_key'] == 'API' + assert call['summary'] == 'cat/u-0: stablereq' + assert call['assigned_to'] == 'dev1@gentoo.org' + assert not call['cc'] + assert call['cf_stabilisation_atoms'] == '=cat/u-0 *' + assert not call['depends_on'] + + def test_bug_filing_maintainer_needed(self, repo): + mk_repo(repo) + session = BugsSession() + pkg = max(repo.itermatch(atom('=cat/z-0'))) + with patch('pkgdev.scripts.pkgdev_bugs.urllib.urlopen', session): + bugs.GraphNode(((pkg, {'*'}), )).file_bug("API", frozenset()) + assert len(session.calls) == 1 + call = session.calls[0] + assert call['assigned_to'] == 'maintainer-needed@gentoo.org' + assert not call['cc'] + + def test_bug_filing_multiple_pkgs(self, repo): + mk_repo(repo) + session = BugsSession() + pkgX = max(repo.itermatch(atom('=cat/x-0'))) + pkgY = max(repo.itermatch(atom('=cat/y-0'))) + pkgZ = max(repo.itermatch(atom('=cat/z-0'))) + dep = bugs.GraphNode((), 2) + node = bugs.GraphNode(((pkgX, {'*'}), (pkgY, {'*'}), (pkgZ, {'*'}))) + node.edges.add(dep) + with patch('pkgdev.scripts.pkgdev_bugs.urllib.urlopen', session): + node.file_bug("API", frozenset()) + assert len(session.calls) == 1 + call = session.calls[0] + assert call['summary'] == 'cat/x-0, cat/y-0, cat/z-0: stablereq' + assert call['assigned_to'] == 'dev3@gentoo.org' + assert call['cc'] == ['dev1@gentoo.org'] + assert call['cf_stabilisation_atoms'] == '=cat/x-0 *\n=cat/y-0 *\n=cat/z-0 *' + assert call['depends_on'] == [2] |