Skip to content

Commit

Permalink
feat: allow marking projects as archived
Browse files Browse the repository at this point in the history
Signed-off-by: Facundo Tuesca <[email protected]>
  • Loading branch information
facutuesca committed Nov 19, 2024
1 parent 1de7977 commit f22daf0
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 166 deletions.
82 changes: 78 additions & 4 deletions tests/unit/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from warehouse.packaging.models import (
File,
JournalEntry,
LifecycleStatus,
Project,
Release,
Role,
Expand Down Expand Up @@ -96,7 +97,6 @@


class TestManageUnverifiedAccount:

def test_manage_account(self, monkeypatch):
user_service = pretend.stub()
name = pretend.stub()
Expand Down Expand Up @@ -2603,11 +2603,12 @@ class TestManageProjectSettings:
@pytest.mark.parametrize("enabled", [False, True])
def test_manage_project_settings(self, enabled, monkeypatch):
request = pretend.stub(organization_access=enabled)
project = pretend.stub(organization=None)
project = pretend.stub(organization=None, lifecycle_status=None)
view = views.ManageProjectSettingsViews(project, request)
form = pretend.stub()
view.transfer_organization_project_form_class = lambda *a, **kw: form
view.add_alternate_repository_form_class = lambda *a, **kw: form
view.set_project_status_form_class = lambda *a, **kw: form

user_organizations = pretend.call_recorder(
lambda *a, **kw: {
Expand All @@ -2622,21 +2623,91 @@ def test_manage_project_settings(self, enabled, monkeypatch):
"project": project,
"MAX_FILESIZE": MAX_FILESIZE,
"MAX_PROJECT_SIZE": MAX_PROJECT_SIZE,
"set_project_status_form": form,
"transfer_organization_project_form": form,
"add_alternate_repository_form_class": form,
}

def test_archive_project(self, db_request):
project = ProjectFactory.create(name="foo")

db_request.POST = MultiDict({"project_status": "archived"})
db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect")
db_request.session = pretend.stub(
flash=pretend.call_recorder(lambda *a, **kw: None)
)

settings_views = views.ManageProjectSettingsViews(project, db_request)
result = settings_views.set_project_status()

assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"
assert db_request.session.flash.calls == [
pretend.call("Set project status to 'archived'", queue="success")
]
assert db_request.route_path.calls == [
pretend.call("manage.project.settings", project_name="foo")
]
assert project.lifecycle_status == LifecycleStatus.Archived

def test_unarchive_project(self, db_request):
project = ProjectFactory.create(
name="foo", lifecycle_status=LifecycleStatus.Archived
)

db_request.POST = MultiDict({"project_status": ""})
db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect")
db_request.session = pretend.stub(
flash=pretend.call_recorder(lambda *a, **kw: None)
)

settings_views = views.ManageProjectSettingsViews(project, db_request)
result = settings_views.set_project_status()

assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"
assert db_request.session.flash.calls == [
pretend.call("Set project status to 'None'", queue="success")
]
assert db_request.route_path.calls == [
pretend.call("manage.project.settings", project_name="foo")
]
assert project.lifecycle_status is None

def test_disallowed_lifecycle_status_change(self, db_request):
project = ProjectFactory.create(name="foo", lifecycle_status="quarantine-enter")

db_request.POST = MultiDict({"project_status": "quarantine-exit"})
db_request.route_path = pretend.call_recorder(lambda *a, **kw: "/the-redirect")
db_request.session = pretend.stub(
flash=pretend.call_recorder(lambda *a, **kw: None)
)

settings_views = views.ManageProjectSettingsViews(project, db_request)
result = settings_views.set_project_status()

assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"
assert db_request.session.flash.calls == [
pretend.call("Invalid project status", queue="error")
]
assert db_request.route_path.calls == [
pretend.call("manage.project.settings", project_name="foo")
]
assert project.lifecycle_status == "quarantine-enter"

def test_manage_project_settings_in_organization_managed(self, monkeypatch):
request = pretend.stub(organization_access=True)
organization_managed = pretend.stub(name="managed-org", is_active=True)
organization_owned = pretend.stub(name="owned-org", is_active=True)
project = pretend.stub(organization=organization_managed)
project = pretend.stub(organization=organization_managed, lifecycle_status=None)
view = views.ManageProjectSettingsViews(project, request)
form = pretend.stub()
view.transfer_organization_project_form_class = pretend.call_recorder(
lambda *a, **kw: form
)
view.add_alternate_repository_form_class = lambda *a, **kw: form
view.set_project_status_form_class = lambda *a, **kw: form

user_organizations = pretend.call_recorder(
lambda *a, **kw: {
Expand All @@ -2651,6 +2722,7 @@ def test_manage_project_settings_in_organization_managed(self, monkeypatch):
"project": project,
"MAX_FILESIZE": MAX_FILESIZE,
"MAX_PROJECT_SIZE": MAX_PROJECT_SIZE,
"set_project_status_form": form,
"transfer_organization_project_form": form,
"add_alternate_repository_form_class": form,
}
Expand All @@ -2662,13 +2734,14 @@ def test_manage_project_settings_in_organization_owned(self, monkeypatch):
request = pretend.stub(organization_access=True)
organization_managed = pretend.stub(name="managed-org", is_active=True)
organization_owned = pretend.stub(name="owned-org", is_active=True)
project = pretend.stub(organization=organization_owned)
project = pretend.stub(organization=organization_owned, lifecycle_status=None)
view = views.ManageProjectSettingsViews(project, request)
form = pretend.stub()
view.transfer_organization_project_form_class = pretend.call_recorder(
lambda *a, **kw: form
)
view.add_alternate_repository_form_class = lambda *a, **kw: form
view.set_project_status_form_class = lambda *a, **kw: form

user_organizations = pretend.call_recorder(
lambda *a, **kw: {
Expand All @@ -2683,6 +2756,7 @@ def test_manage_project_settings_in_organization_owned(self, monkeypatch):
"project": project,
"MAX_FILESIZE": MAX_FILESIZE,
"MAX_PROJECT_SIZE": MAX_PROJECT_SIZE,
"set_project_status_form": form,
"transfer_organization_project_form": form,
"add_alternate_repository_form_class": form,
}
Expand Down
Loading

0 comments on commit f22daf0

Please sign in to comment.