Skip to content

Commit a8dd637

Browse files
woodruffwdimiketheman
authored
profile: add archived projects section (#17571)
* profile: add archived projects section Signed-off-by: William Woodruff <[email protected]> * make translations Signed-off-by: William Woodruff <[email protected]> * avoid "active" projects label Signed-off-by: William Woodruff <[email protected]> * rename projects -> live_projects Signed-off-by: William Woodruff <[email protected]> * archive project profile tests Signed-off-by: William Woodruff <[email protected]> * Update tests/unit/accounts/test_views.py Co-authored-by: Mike Fiedler <[email protected]> * tests: add a basic HTML content test Signed-off-by: William Woodruff <[email protected]> --------- Signed-off-by: William Woodruff <[email protected]> Co-authored-by: Dustin Ingram <[email protected]> Co-authored-by: Mike Fiedler <[email protected]>
1 parent c6dd5af commit a8dd637

File tree

6 files changed

+500
-388
lines changed

6 files changed

+500
-388
lines changed

tests/functional/test_user_profile.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from http import HTTPStatus
1414

1515
from tests.common.db.accounts import UserFactory
16+
from tests.common.db.packaging import ProjectFactory, ReleaseFactory, RoleFactory
17+
from warehouse.packaging.models import LifecycleStatus
1618

1719

1820
def test_user_profile(webtest):
@@ -30,3 +32,23 @@ def test_user_profile(webtest):
3032
# ...and verify that the user's profile page exists
3133
resp = webtest.get(f"/user/{user.username}/")
3234
assert resp.status_code == HTTPStatus.OK
35+
36+
37+
def test_user_profile_project_states(webtest):
38+
user = UserFactory.create()
39+
40+
# Create some live projects
41+
projects = ProjectFactory.create_batch(3)
42+
for project in projects:
43+
RoleFactory.create(user=user, project=project)
44+
ReleaseFactory.create(project=project)
45+
46+
# Create an archived project
47+
archived_project = ProjectFactory.create(lifecycle_status=LifecycleStatus.Archived)
48+
RoleFactory.create(user=user, project=archived_project)
49+
ReleaseFactory.create(project=archived_project)
50+
51+
resp = webtest.get(f"/user/{user.username}/")
52+
53+
assert resp.status_code == HTTPStatus.OK
54+
assert "4 projects" in resp.html.h2.text

tests/unit/accounts/test_views.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ def test_user_redirects_username(self, db_request):
149149

150150
def test_returns_user(self, db_request):
151151
user = UserFactory.create()
152-
assert views.profile(user, db_request) == {"user": user, "projects": []}
152+
assert views.profile(user, db_request) == {
153+
"user": user,
154+
"live_projects": [],
155+
"archived_projects": [],
156+
}
153157

154158
def test_user_profile_queries_once_for_all_projects(
155159
self, db_request, query_recorder
@@ -179,10 +183,27 @@ def test_user_profile_queries_once_for_all_projects(
179183
response = views.profile(user, db_request)
180184

181185
assert response["user"] == user
182-
assert len(response["projects"]) == 3
186+
assert len(response["live_projects"]) == 3
183187
# Two queries, one for the user (via context), one for their projects
184188
assert len(query_recorder.queries) == 2
185189

190+
def test_returns_archived_projects(self, db_request):
191+
user = UserFactory.create()
192+
193+
projects = ProjectFactory.create_batch(3)
194+
for project in projects:
195+
RoleFactory.create(user=user, project=project)
196+
ReleaseFactory.create(project=project)
197+
198+
archived_project = ProjectFactory.create(lifecycle_status="archived")
199+
RoleFactory.create(user=user, project=archived_project)
200+
ReleaseFactory.create(project=archived_project)
201+
202+
resp = views.profile(user, db_request)
203+
204+
assert len(resp["live_projects"]) == 3
205+
assert len(resp["archived_projects"]) == 1
206+
186207

187208
class TestAccountsSearch:
188209
def test_unauthenticated_raises_401(self):
@@ -4039,10 +4060,7 @@ def test_add_pending_github_oidc_publisher_too_many_already(
40394060
]
40404061
assert db_request.session.flash.calls == [
40414062
pretend.call(
4042-
(
4043-
"You can't register more than 3 pending trusted "
4044-
"publishers at once."
4045-
),
4063+
"You can't register more than 3 pending trusted publishers at once.",
40464064
queue="error",
40474065
)
40484066
]

warehouse/accounts/views.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
from warehouse.packaging.interfaces import IProjectService
9999
from warehouse.packaging.models import (
100100
JournalEntry,
101+
LifecycleStatus,
101102
Project,
102103
Release,
103104
Role,
@@ -185,6 +186,7 @@ def profile(user, request):
185186
select(
186187
Project.name,
187188
Project.normalized_name,
189+
Project.lifecycle_status,
188190
Release.created,
189191
Release.summary,
190192
)
@@ -206,17 +208,28 @@ def profile(user, request):
206208
)
207209

208210
# Construct the list of projects with their latest releases from query results
209-
projects = [
210-
{
211+
archived_projects = []
212+
live_projects = []
213+
214+
for row in request.db.execute(stmt):
215+
project = {
211216
"name": row.name,
212217
"normalized_name": row.normalized_name,
218+
"lifecycle_status": row.lifecycle_status,
213219
"created": row.created,
214220
"summary": row.summary,
215221
}
216-
for row in request.db.execute(stmt)
217-
]
218222

219-
return {"user": user, "projects": projects}
223+
if row.lifecycle_status == LifecycleStatus.Archived:
224+
archived_projects.append(project)
225+
else:
226+
live_projects.append(project)
227+
228+
return {
229+
"user": user,
230+
"live_projects": live_projects,
231+
"archived_projects": archived_projects,
232+
}
220233

221234

222235
@view_config(
@@ -1640,8 +1653,7 @@ def _add_pending_oidc_publisher(
16401653
if len(self.request.user.pending_oidc_publishers) >= 3:
16411654
self.request.session.flash(
16421655
self.request._(
1643-
"You can't register more than 3 pending trusted "
1644-
"publishers at once."
1656+
"You can't register more than 3 pending trusted publishers at once."
16451657
),
16461658
queue="error",
16471659
)

0 commit comments

Comments
 (0)