Skip to content

Commit 9e81357

Browse files
committed
feat(#590): add "Testing Version" column to todo lists; include new fixtures for todolist
dev(#590): add missing fixtures for todo lists cleanup
1 parent a7a872f commit 9e81357

6 files changed

Lines changed: 287 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ probably want the following:
5252
uv run ./manage.py loaddata devel/fixtures/*.json
5353
uv run ./manage.py loaddata mirrors/fixtures/*.json
5454
uv run ./manage.py loaddata releng/fixtures/*.json
55+
uv run ./manage.py loaddata todolists/fixtures/*.json
5556
7. Use the following commands to start a service instance
5657

5758
uv run ./manage.py runserver

templates/todolists/view.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ <h3>Filter Todo List Packages</h3>
7575
<th>Name</th>
7676
<th>Current Version</th>
7777
<th>Staging Version</th>
78+
<th>Testing Version</th>
7879
<th>Maintainers</th>
7980
<th>Status</th>
8081
<th>Last Touched By</th>
@@ -96,6 +97,9 @@ <h3>Filter Todo List Packages</h3>
9697
{% with staging=pkg.staging %}
9798
<td>{% if staging %}{% pkg_details_link staging staging.full_version %}{% endif %}</td>
9899
{% endwith %}
100+
{% with testing=pkg.testing %}
101+
<td>{% if testing %}{% pkg_details_link testing testing.full_version %}{% endif %}</td>
102+
{% endwith %}
99103
<td>{{ pkg.maintainers|join:', ' }}</td>
100104
<td>
101105
{% if perms.todolists.change_todolistpackage %}

todolists/fixtures/todolist.json

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
[
2+
{
3+
"model": "auth.user",
4+
"pk": 1,
5+
"fields": {
6+
"username": "developer",
7+
"first_name": "Test",
8+
"last_name": "Developer",
9+
"email": "developer@archlinux.org",
10+
"password": "pbkdf2_sha256$1000000$5mOVHaWggfkqKGsKsVpWH8$kS2tNunBSv+rrDohZXeuP9L/kX8oDe09vzab+m3WQXo=",
11+
"is_staff": true,
12+
"is_active": true,
13+
"is_superuser": true,
14+
"date_joined": "2024-01-01T00:00:00Z",
15+
"last_login": null,
16+
"groups": [],
17+
"user_permissions": []
18+
}
19+
},
20+
{
21+
"model": "main.package",
22+
"pk": 6,
23+
"fields": {
24+
"repo": 3,
25+
"arch": 3,
26+
"pkgname": "linux",
27+
"pkgbase": "linux",
28+
"pkgver": "6.9.1",
29+
"pkgrel": "2",
30+
"epoch": 0,
31+
"pkgdesc": "The Linux kernel and modules",
32+
"url": "https://www.kernel.org/",
33+
"filename": "linux-6.9.1-2-x86_64.pkg.tar.zst",
34+
"compressed_size": 72000000,
35+
"installed_size": 91000000,
36+
"build_date": "2024-05-20T10:00:00Z",
37+
"last_update": "2024-05-20T10:00:00Z",
38+
"files_last_update": null,
39+
"created": "2024-05-20T10:00:00Z",
40+
"packager_str": "Test Developer <developer@archlinux.org>",
41+
"packager": null,
42+
"signature_bytes": null,
43+
"flag_date": null
44+
}
45+
},
46+
{
47+
"model": "main.package",
48+
"pk": 7,
49+
"fields": {
50+
"repo": 16,
51+
"arch": 3,
52+
"pkgname": "systemd",
53+
"pkgbase": "systemd",
54+
"pkgver": "256.1",
55+
"pkgrel": "1",
56+
"epoch": 0,
57+
"pkgdesc": "system and service manager",
58+
"url": "https://www.github.com/systemd/systemd",
59+
"filename": "systemd-256.1-1-x86_64.pkg.tar.zst",
60+
"compressed_size": 4100000,
61+
"installed_size": 19000000,
62+
"build_date": "2024-05-22T08:00:00Z",
63+
"last_update": "2024-05-22T08:00:00Z",
64+
"files_last_update": null,
65+
"created": "2024-05-22T08:00:00Z",
66+
"packager_str": "Test Developer <developer@archlinux.org>",
67+
"packager": null,
68+
"signature_bytes": null,
69+
"flag_date": null
70+
}
71+
},
72+
{
73+
"model": "todolists.todolist",
74+
"pk": 1,
75+
"fields": {
76+
"slug": "glibc-2-40-rebuild",
77+
"name": "glibc 2.40 rebuild",
78+
"description": "Rebuild of packages affected by the glibc 2.40 soname bump.",
79+
"creator": 1,
80+
"created": "2024-05-20T09:00:00Z",
81+
"kind": 0,
82+
"last_modified": "2024-05-22T08:00:00Z",
83+
"raw": "linux\ncoreutils\npacman\nsystemd"
84+
}
85+
},
86+
{
87+
"model": "todolists.todolistpackage",
88+
"pk": 1,
89+
"fields": {
90+
"todolist": 1,
91+
"pkg": 1,
92+
"pkgname": "linux",
93+
"pkgbase": "linux",
94+
"arch": 3,
95+
"repo": 1,
96+
"created": "2024-05-20T09:00:00Z",
97+
"last_modified": "2024-05-20T09:00:00Z",
98+
"removed": null,
99+
"status": 0,
100+
"user": null,
101+
"comments": null
102+
}
103+
},
104+
{
105+
"model": "todolists.todolistpackage",
106+
"pk": 2,
107+
"fields": {
108+
"todolist": 1,
109+
"pkg": 2,
110+
"pkgname": "coreutils",
111+
"pkgbase": "coreutils",
112+
"arch": 3,
113+
"repo": 1,
114+
"created": "2024-05-20T09:00:00Z",
115+
"last_modified": "2024-05-21T14:30:00Z",
116+
"removed": null,
117+
"status": 1,
118+
"user": 1,
119+
"comments": null
120+
}
121+
},
122+
{
123+
"model": "todolists.todolistpackage",
124+
"pk": 3,
125+
"fields": {
126+
"todolist": 1,
127+
"pkg": 4,
128+
"pkgname": "pacman",
129+
"pkgbase": "pacman",
130+
"arch": 3,
131+
"repo": 1,
132+
"created": "2024-05-20T09:00:00Z",
133+
"last_modified": "2024-05-22T10:00:00Z",
134+
"removed": null,
135+
"status": 2,
136+
"user": 1,
137+
"comments": null
138+
}
139+
},
140+
{
141+
"model": "todolists.todolistpackage",
142+
"pk": 4,
143+
"fields": {
144+
"todolist": 1,
145+
"pkg": 5,
146+
"pkgname": "systemd",
147+
"pkgbase": "systemd",
148+
"arch": 3,
149+
"repo": 1,
150+
"created": "2024-05-20T09:00:00Z",
151+
"last_modified": "2024-05-20T09:00:00Z",
152+
"removed": null,
153+
"status": 0,
154+
"user": null,
155+
"comments": null
156+
}
157+
}
158+
]

todolists/tests/test_utils.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from django.utils.timezone import now
2+
3+
import pytest
4+
5+
from main.models import Arch, Package, Repo
6+
from todolists.models import TodolistPackage
7+
from todolists.utils import attach_staging, attach_testing
8+
9+
10+
def make_package(pkgname, repo, arch):
11+
return Package.objects.create(
12+
pkgname=pkgname,
13+
pkgbase=pkgname,
14+
pkgver='1.0',
15+
pkgrel='1',
16+
epoch=0,
17+
pkgdesc='Test package',
18+
url='https://example.com',
19+
filename=f'{pkgname}-1.0-1-x86_64.pkg.tar.zst',
20+
compressed_size=1000,
21+
installed_size=2000,
22+
build_date=now(),
23+
last_update=now(),
24+
created=now(),
25+
packager_str='Test Packager',
26+
repo=repo,
27+
arch=arch,
28+
)
29+
30+
31+
@pytest.fixture
32+
def stable_pkg(repos, package):
33+
return Package.objects.get(pkgname='linux')
34+
35+
36+
@pytest.fixture
37+
def todolist_with_linux(todolist, stable_pkg, user):
38+
arch = stable_pkg.arch
39+
repo = stable_pkg.repo
40+
tlpkg = TodolistPackage.objects.create(
41+
todolist=todolist,
42+
pkg=stable_pkg,
43+
pkgname=stable_pkg.pkgname,
44+
pkgbase=stable_pkg.pkgbase,
45+
arch=arch,
46+
repo=repo,
47+
user=user,
48+
)
49+
yield todolist
50+
tlpkg.delete()
51+
52+
53+
def test_attach_testing_no_testing_pkg(todolist_with_linux):
54+
todolist = todolist_with_linux
55+
attach_testing(todolist.packages(), todolist.pk)
56+
for pkg in todolist.packages():
57+
assert pkg.testing is None
58+
59+
60+
def test_attach_testing_finds_testing_pkg(todolist_with_linux):
61+
todolist = todolist_with_linux
62+
stable_pkg = Package.objects.get(pkgname='linux', repo__testing=False, repo__staging=False)
63+
testing_repo = Repo.objects.get(name='Core-Testing')
64+
65+
testing_pkg = make_package('linux', testing_repo, stable_pkg.arch)
66+
try:
67+
attach_testing(todolist.packages(), todolist.pk)
68+
for pkg in todolist.packages():
69+
if pkg.pkgname == 'linux':
70+
assert pkg.testing is not None
71+
assert pkg.testing.repo.testing is True
72+
finally:
73+
testing_pkg.delete()
74+
75+
76+
def test_attach_testing_ignores_staging_repos(todolist_with_linux):
77+
todolist = todolist_with_linux
78+
stable_pkg = Package.objects.get(pkgname='linux', repo__testing=False, repo__staging=False)
79+
staging_repo = Repo.objects.get(name='Core-Staging')
80+
81+
staging_pkg = make_package('linux', staging_repo, stable_pkg.arch)
82+
try:
83+
attach_testing(todolist.packages(), todolist.pk)
84+
for pkg in todolist.packages():
85+
if pkg.pkgname == 'linux':
86+
assert pkg.testing is None
87+
finally:
88+
staging_pkg.delete()
89+
90+
91+
def test_attach_staging_still_works(todolist_with_linux):
92+
todolist = todolist_with_linux
93+
stable_pkg = Package.objects.get(pkgname='linux', repo__testing=False, repo__staging=False)
94+
staging_repo = Repo.objects.get(name='Core-Staging')
95+
96+
staging_pkg = make_package('linux', staging_repo, stable_pkg.arch)
97+
try:
98+
attach_staging(todolist.packages(), todolist.pk)
99+
for pkg in todolist.packages():
100+
if pkg.pkgname == 'linux':
101+
assert pkg.staging is not None
102+
assert pkg.staging.repo.staging is True
103+
finally:
104+
staging_pkg.delete()

todolists/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,22 @@ def attach_staging(packages, list_id):
5656

5757
return annotated
5858

59+
60+
def attach_testing(packages, list_id):
61+
'''Look for any testing version of the packages provided and attach them
62+
to the 'testing' attribute on each package if found.'''
63+
pkgnames = TodolistPackage.objects.filter(
64+
todolist_id=list_id).values('pkgname')
65+
testing_pkgs = Package.objects.normal().filter(repo__testing=True,
66+
pkgname__in=pkgnames)
67+
# now build a lookup dict to attach to the correct package
68+
lookup = {(p.pkgname, p.arch): p for p in testing_pkgs}
69+
70+
annotated = []
71+
for package in packages:
72+
in_testing = lookup.get((package.pkgname, package.arch), None)
73+
package.testing = in_testing
74+
75+
return annotated
76+
5977
# vim: set ts=4 sw=4 et:

todolists/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from packages.utils import PackageJSONEncoder, attach_maintainers
1717

1818
from .models import Todolist, TodolistPackage
19-
from .utils import attach_staging, get_annotated_todolists
19+
from .utils import attach_staging, attach_testing, get_annotated_todolists
2020

2121

2222
class TodoListForm(forms.ModelForm):
@@ -65,6 +65,7 @@ def view(request, slug):
6565
# so accessing maintainers in the template is now cheap
6666
attach_maintainers(todolist.packages())
6767
attach_staging(todolist.packages(), todolist.pk)
68+
attach_testing(todolist.packages(), todolist.pk)
6869
arches = {tp.arch for tp in todolist.packages()}
6970
repos = {tp.repo for tp in todolist.packages()}
7071
context = {

0 commit comments

Comments
 (0)