Skip to content

Commit 6fc5ccf

Browse files
praiskupFrostyX
authored andcommitted
frontend: implement a test for anitya rebuilds
1 parent db5409c commit 6fc5ccf

File tree

7 files changed

+4231
-21
lines changed

7 files changed

+4231
-21
lines changed

.pylintpath/copr_pylintrc.py

+1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ def init():
2727
# Those still need a special handling (and in future file movements).
2828
if gitsubdir.startswith("frontend"):
2929
sys.path.insert(0, os.path.join(gitrootdir, "frontend", "coprs_frontend"))
30+
sys.path.insert(0, os.path.join(gitrootdir, "frontend", "coprs_frontend", "run"))
3031
if gitsubdir.startswith("keygen"):
3132
sys.path.insert(0, os.path.join(gitrootdir, "keygen", "src"))

frontend/coprs_frontend/run/check_for_anitya_version_updates.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@
2525
log = logging.getLogger(__name__)
2626
log.addHandler(logging.StreamHandler(sys.stdout))
2727

28-
parser = argparse.ArgumentParser(description='Fetch package version updates by using datagrepper log of anitya emitted messages and issue rebuilds of the respective COPR packages for each such update. Requires httpie package.')
2928

30-
parser.add_argument('--backend', action='store', default='pypi', choices=['pypi', 'rubygems'],
31-
help='only check for updates from backend BACKEND, default pypi')
32-
parser.add_argument('--delta', action='store', type=int, metavar='SECONDS', default=86400,
33-
help='ignore updates older than SECONDS, default 86400')
34-
parser.add_argument('-v', '--version', action='version', version='1.0',
35-
help='print program version and exit')
29+
def _get_parser():
30+
parser = argparse.ArgumentParser(description='Fetch package version updates by using datagrepper log of anitya emitted messages and issue rebuilds of the respective COPR packages for each such update. Requires httpie package.')
3631

37-
args = parser.parse_args()
32+
parser.add_argument('--backend', action='store', default='pypi', choices=['pypi', 'rubygems'],
33+
help='only check for updates from backend BACKEND, default pypi')
34+
parser.add_argument('--delta', action='store', type=int, metavar='SECONDS', default=86400,
35+
help='ignore updates older than SECONDS, default 86400')
36+
parser.add_argument('-v', '--version', action='version', version='1.0',
37+
help='print program version and exit')
38+
return parser
3839

3940

4041
def run_cmd(cmd):
@@ -58,27 +59,27 @@ def to_json(data_bytes):
5859
log.exception(str(e))
5960
return data_json
6061

61-
def get_updates_messages():
62+
def get_updates_messages(delta):
6263
cmd_binary = 'curl'
6364
url_template = 'https://apps.fedoraproject.org/datagrepper/raw?category=anitya&delta={delta}&topic=org.release-monitoring.prod.anitya.project.version.update&rows_per_page=64&order=asc&page={page}'
64-
get_updates_cmd = [cmd_binary, url_template.format(delta=args.delta, page=1)]
65+
get_updates_cmd = [cmd_binary, url_template.format(delta=delta, page=1)]
6566
result_json = to_json(run_cmd(get_updates_cmd))
6667
messages = result_json['raw_messages']
6768
pages = result_json['pages']
6869

6970
for p in range(2, pages+1):
70-
get_updates_cmd = [cmd_binary, url_template.format(delta=args.delta, page=p)]
71+
get_updates_cmd = [cmd_binary, url_template.format(delta=delta, page=p)]
7172
result_json = to_json(run_cmd(get_updates_cmd))
7273
messages += result_json['raw_messages']
7374

7475
return messages
7576

76-
def get_updated_packages(updates_messages):
77+
def get_updated_packages(updates_messages, backend):
7778
updated_packages = {}
7879
for message in updates_messages:
7980
update = message['msg']
8081
project = update['project']
81-
if args.backend.lower() != project['backend'].lower():
82+
if backend != project['backend'].lower():
8283
continue
8384
updated_packages[project['name'].lower()] = project['version']
8485
return updated_packages
@@ -111,15 +112,14 @@ def build(self, copr, new_updated_version):
111112
background=True,
112113
)
113114

114-
115115
def package_from_source(backend, source_json):
116116
try:
117117
return {
118118
'pypi': PyPIPackage,
119119
'rubygems': RubyGemsPackage,
120120
}[backend](source_json)
121121
except KeyError:
122-
raise Exception('Unsupported backend {0} passed as command-line argument'.format(args.backend))
122+
raise Exception('Unsupported backend {0} passed as command-line argument'.format(backend))
123123

124124

125125
def is_prerelease(version: str) -> bool:
@@ -139,12 +139,14 @@ def is_prerelease(version: str) -> bool:
139139
return False
140140

141141
def main():
142-
updated_packages = get_updated_packages(get_updates_messages())
142+
args = _get_parser().parse_args()
143+
backend = args.backend.lower()
144+
updated_packages = get_updated_packages(get_updates_messages(args.delta), backend)
143145
log.info("Updated packages per datagrepper %s", len(updated_packages))
144146
for package, last_build in PackagesLogic.webhook_package_candidates(
145147
helpers.BuildSourceEnum(args.backend.lower())):
146148
source_json = json.loads(package.source_json)
147-
rebuilder = package_from_source(args.backend.lower(), source_json)
149+
rebuilder = package_from_source(backend, source_json)
148150
log.debug(
149151
"candidate %s package %s in %s",
150152
args.backend,

frontend/coprs_frontend/tests/coprs_test_case.py

+21
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def teardown_method(self, method):
8585
self.app.config = self.original_config.copy()
8686
cache.clear()
8787

88+
@staticmethod
89+
def load_test_data_file(filename):
90+
"""
91+
Load datafile from tests/data directory
92+
"""
93+
workdir = os.path.dirname(__file__)
94+
filename = os.path.join(workdir, "data", filename)
95+
with open(filename, encoding="utf-8") as fd:
96+
return fd.read()
97+
8898
@property
8999
def auth_header(self):
90100
return {"Authorization": b"Basic " +
@@ -830,6 +840,17 @@ def get_api3_with_auth(self, url, user):
830840
print(headers)
831841
return self.tc.get(url, headers=headers)
832842

843+
def rebuild_package_and_finish(self, project_dirname, pkgname,
844+
build_options=None, project_ownername=None,
845+
pkg_version="1.1"):
846+
"""
847+
Rebuild package using API, and mark it as succeeded
848+
"""
849+
out = self.api3.rebuild_package(project_dirname, pkgname, build_options,
850+
project_ownername)
851+
build_id = out.json["id"]
852+
self.backend.finish_build(build_id, pkg_version=pkg_version)
853+
833854

834855
class TransactionDecorator(object):
835856

0 commit comments

Comments
 (0)