Skip to content

Commit

Permalink
archive project profile tests
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodruff <william@trailofbits.com>
  • Loading branch information
woodruffw committed Feb 10, 2025
1 parent c6abc45 commit fa1e22f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
20 changes: 20 additions & 0 deletions tests/functional/test_user_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from http import HTTPStatus

from tests.common.db.accounts import UserFactory
from tests.common.db.packaging import ProjectFactory, ReleaseFactory, RoleFactory
from warehouse.packaging.models import LifecycleStatus


def test_user_profile(webtest):
Expand All @@ -30,3 +32,21 @@ def test_user_profile(webtest):
# ...and verify that the user's profile page exists
resp = webtest.get(f"/user/{user.username}/")
assert resp.status_code == HTTPStatus.OK


def test_user_profile_project_states(webtest):
user = UserFactory.create()

# Create some live projects
projects = ProjectFactory.create_batch(3)
for project in projects:
RoleFactory.create(user=user, project=project)
ReleaseFactory.create(project=project)

# Create an archived project
archived_project = ProjectFactory.create(lifecycle_status=LifecycleStatus.Archived)
RoleFactory.create(user=user, project=archived_project)
ReleaseFactory.create(project=archived_project)

resp = webtest.get(f"/user/{user.username}/")
assert resp.status_code == HTTPStatus.OK
21 changes: 19 additions & 2 deletions tests/unit/accounts/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_returns_user(self, db_request):
user = UserFactory.create()
assert views.profile(user, db_request) == {
"user": user,
"projects": [],
"live_projects": [],
"archived_projects": [],
}

Expand Down Expand Up @@ -183,10 +183,27 @@ def test_user_profile_queries_once_for_all_projects(
response = views.profile(user, db_request)

assert response["user"] == user
assert len(response["projects"]) == 3
assert len(response["live_projects"]) == 3
# Two queries, one for the user (via context), one for their projects
assert len(query_recorder.queries) == 2

def test_returns_archived_projects(self, db_request):
user = UserFactory.create()

projects = ProjectFactory.create_batch(3)
for project in projects:
RoleFactory.create(user=user, project=project)
ReleaseFactory.create(project=project)

archived_project = ProjectFactory.create(lifecycle_status="archived")
RoleFactory.create(user=user, project=archived_project)
ReleaseFactory.create(project=archived_project)

resp = views.profile(user, db_request)

assert len(resp["live_projects"]) == 3
assert len(resp["archived_projects"]) == 1


class TestAccountsSearch:
def test_unauthenticated_raises_401(self):
Expand Down
1 change: 1 addition & 0 deletions warehouse/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import humanize
import pytz

from more_itertools import first_true
from pyramid.httpexceptions import (
HTTPBadRequest,
Expand Down

0 comments on commit fa1e22f

Please sign in to comment.