Skip to content

Commit 9ecffac

Browse files
authored
Disallow transferring projects to inactive Company Organizations (#18320)
1 parent 9808697 commit 9ecffac

File tree

7 files changed

+132
-98
lines changed

7 files changed

+132
-98
lines changed

tests/unit/manage/test_forms.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from warehouse.manage import forms
1414

1515
from ...common.constants import REMOTE_ADDR
16+
from ...common.db.organizations import OrganizationFactory
1617
from ...common.db.packaging import ProjectFactory
1718

1819

@@ -1008,25 +1009,30 @@ def test_validate(
10081009

10091010

10101011
class TestTransferOrganizationProjectForm:
1011-
@pytest.mark.parametrize(
1012-
("organization", "organization_choices", "errors"),
1013-
[
1014-
("", [], {"organization": ["Select organization"]}),
1015-
("", ["organization"], {"organization": ["Select organization"]}),
1016-
("organization", ["organization"], {}),
1017-
],
1018-
)
1019-
def test_validate(
1020-
self, pyramid_request, organization, organization_choices, errors
1021-
):
1022-
pyramid_request.POST = MultiDict({"organization": organization})
1012+
def test_validate(self, pyramid_request):
1013+
organization = OrganizationFactory()
1014+
pyramid_request.POST = MultiDict({"organization": organization.id})
10231015

10241016
form = forms.TransferOrganizationProjectForm(
1025-
pyramid_request.POST, organization_choices=organization_choices
1017+
pyramid_request.POST, organization_choices=[organization]
10261018
)
10271019

1028-
assert not form.validate() if errors else form.validate(), str(form.errors)
1029-
assert form.errors == errors
1020+
assert form.validate()
1021+
1022+
def test_rejects_inactive_company(self, pyramid_request):
1023+
organization = OrganizationFactory(orgtype="Company")
1024+
pyramid_request.POST = MultiDict({"organization": organization.id})
1025+
1026+
form = forms.TransferOrganizationProjectForm(
1027+
pyramid_request.POST, organization_choices=[organization]
1028+
)
1029+
1030+
assert not form.validate()
1031+
assert form.errors == {
1032+
"organization": [
1033+
"Cannot transfer to Company Organization with inactive billing"
1034+
]
1035+
}
10301036

10311037

10321038
class TestCreateOrganizationRoleForm:

tests/unit/manage/test_views.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,7 +2667,7 @@ def test_manage_project_settings_in_organization_managed(self, monkeypatch):
26672667
"add_alternate_repository_form_class": form,
26682668
}
26692669
assert view.transfer_organization_project_form_class.calls == [
2670-
pretend.call(organization_choices={"owned-org"})
2670+
pretend.call(organization_choices={organization_owned})
26712671
]
26722672

26732673
def test_manage_project_settings_in_organization_owned(self, monkeypatch):
@@ -2699,7 +2699,7 @@ def test_manage_project_settings_in_organization_owned(self, monkeypatch):
26992699
"add_alternate_repository_form_class": form,
27002700
}
27012701
assert view.transfer_organization_project_form_class.calls == [
2702-
pretend.call(organization_choices={"managed-org"})
2702+
pretend.call(organization_choices={organization_managed})
27032703
]
27042704

27052705
def test_add_alternate_repository(self, monkeypatch, db_request):
@@ -3278,7 +3278,7 @@ def test_transfer_organization_project_no_current_organization(
32783278

32793279
db_request.POST = MultiDict(
32803280
{
3281-
"organization": organization.normalized_name,
3281+
"organization": str(organization.id),
32823282
"confirm_transfer_organization_project_name": project.name,
32833283
}
32843284
)
@@ -3372,7 +3372,7 @@ def test_transfer_organization_project_no_individual_owner(
33723372

33733373
db_request.POST = MultiDict(
33743374
{
3375-
"organization": organization.normalized_name,
3375+
"organization": str(organization.id),
33763376
"confirm_transfer_organization_project_name": project.name,
33773377
}
33783378
)
@@ -3483,7 +3483,7 @@ def test_transfer_organization_project_from_organization_managed(
34833483

34843484
db_request.POST = MultiDict(
34853485
{
3486-
"organization": organization.normalized_name,
3486+
"organization": str(organization.id),
34873487
"confirm_transfer_organization_project_name": project.name,
34883488
}
34893489
)
@@ -3547,7 +3547,9 @@ def test_transfer_organization_project_from_organization_managed(
35473547
pretend.call("manage.project.settings", project_name="foo")
35483548
]
35493549
assert transfer_organization_project_form_class.calls == [
3550-
pretend.call(db_request.POST, organization_choices={"bar-owned", "baz"})
3550+
pretend.call(
3551+
db_request.POST, organization_choices={organization, organization_owned}
3552+
)
35513553
]
35523554
assert isinstance(result, HTTPSeeOther)
35533555
assert result.headers["Location"] == "/the-redirect"
@@ -3581,7 +3583,7 @@ def test_transfer_organization_project_from_organization_owned(
35813583

35823584
db_request.POST = MultiDict(
35833585
{
3584-
"organization": organization.normalized_name,
3586+
"organization": str(organization.id),
35853587
"confirm_transfer_organization_project_name": project.name,
35863588
}
35873589
)
@@ -3645,7 +3647,10 @@ def test_transfer_organization_project_from_organization_owned(
36453647
pretend.call("manage.project.settings", project_name="foo")
36463648
]
36473649
assert transfer_organization_project_form_class.calls == [
3648-
pretend.call(db_request.POST, organization_choices={"bar-managed", "baz"})
3650+
pretend.call(
3651+
db_request.POST,
3652+
organization_choices={organization_managed, organization},
3653+
)
36493654
]
36503655
assert isinstance(result, HTTPSeeOther)
36513656
assert result.headers["Location"] == "/the-redirect"

0 commit comments

Comments
 (0)