Skip to content

Commit 9029c74

Browse files
committed
wip tests
1 parent d060bd0 commit 9029c74

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

devel/management/commands/read_bumpbuddy_status.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
import logging
12+
from urllib.parse import quote as urlquote
1213

1314
import requests
1415
from django.conf import settings
@@ -17,6 +18,7 @@
1718
from django.utils.timezone import now
1819

1920
from main.models import Package
21+
from main.utils import gitlab_project_name_to_path
2022
from packages.alpm import AlpmAPI
2123
from packages.models import FlagRequest
2224

@@ -63,11 +65,16 @@ def process_package(self, pkgdata):
6365
current_time = now()
6466
# Compatibility for old json output without issue
6567
if 'issue' in pkgdata:
66-
issue_url = f"{settings.GITLAB_PACKAGES_REPO}/{pkgbase}/-/issues/{pkgdata['issue']}"
68+
scm_pkgbase = urlquote(gitlab_project_name_to_path(pkgbase))
69+
issue_url = f"{settings.GITLAB_PACKAGES_REPO}/{scm_pkgbase}/-/issues/{pkgdata['issue']}"
6770
message = f"New version {pkgdata['upstream_version']} is available: {issue_url}"
6871
else:
6972
message = f"New version {pkgdata['upstream_version']} is available."
70-
packages.update(flag_date=current_time)
73+
74+
for pkg in ood_packages:
75+
pkg.flag_date = current_time
76+
pkg.save()
77+
7178
flag_request = FlagRequest(created=current_time,
7279
user_email="[email protected]",
7380
message=message,
@@ -114,9 +121,6 @@ def handle(self, *args, **options):
114121

115122
flagged_packages = []
116123
for pkgdata in req.json().values():
117-
if not pkgdata['out_of_date']:
118-
continue
119-
120124
package = self.process_package(pkgdata)
121125
if package is not None:
122126
flagged_packages.append(package)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
from django.test import TransactionTestCase
3+
from django.utils.timezone import now
4+
5+
from devel.management.commands.read_bumpbuddy_status import Command as BumpBuddyCommand
6+
from main.models import Arch, Package, Repo
7+
from packages.models import FlagRequest
8+
9+
10+
class RetireUsertest(TransactionTestCase):
11+
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json']
12+
13+
def setUp(self):
14+
pass
15+
16+
def process_package(self, pkgdata):
17+
cmd = BumpBuddyCommand()
18+
cmd.process_package(pkgdata)
19+
20+
def test_ood_package(self):
21+
arch = Arch.objects.get(name='x86_64')
22+
extra = Repo.objects.get(name='Extra')
23+
created = now()
24+
pkg = Package.objects.create(arch=arch, repo=extra, pkgname='systemd',
25+
pkgbase='systemd', pkgver=100,
26+
pkgrel=1, pkgdesc='Linux kernel',
27+
compressed_size=10, installed_size=20,
28+
last_update=created, created=created)
29+
30+
self.process_package({
31+
'pkgbase': 'systemd',
32+
'local_version': 100,
33+
'upstream_version': 100,
34+
'out_of_date': False,
35+
'issue': 12
36+
})
37+
38+
flag_requests = FlagRequest.objects.all()
39+
assert len(flag_requests) == 0

0 commit comments

Comments
 (0)