Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions tests/common/db/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from warehouse.observations.models import ObservationKind
from warehouse.packaging.models import (
AlternateRepository,
Dependency,
DependencyKind,
Description,
Expand Down Expand Up @@ -202,13 +201,3 @@ class Meta:
)
name = factory.Faker("pystr", max_chars=12)
prohibited_by = factory.SubFactory(UserFactory)


class AlternateRepositoryFactory(WarehouseFactory):
class Meta:
model = AlternateRepository

name = factory.Faker("word")
url = factory.Faker("uri")
description = factory.Faker("text")
project = factory.SubFactory(ProjectFactory)
14 changes: 0 additions & 14 deletions tests/unit/api/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from ...common.db.accounts import UserFactory
from ...common.db.packaging import (
AlternateRepositoryFactory,
FileFactory,
JournalEntryFactory,
ProjectFactory,
Expand Down Expand Up @@ -210,7 +209,6 @@ def test_no_files_no_serial(self, db_request, content_type, renderer_override):
"project-status": {"status": "active"},
"files": [],
"versions": [],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand All @@ -232,18 +230,13 @@ def test_no_files_with_serial(self, db_request, content_type, renderer_override)
db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)
als = [
AlternateRepositoryFactory.create(project=project),
AlternateRepositoryFactory.create(project=project),
]

context = {
"meta": {"_last-serial": je.id, "api-version": API_VERSION},
"name": project.normalized_name,
"project-status": {"status": "active"},
"files": [],
"versions": [],
"alternate-locations": sorted(al.url for al in als),
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand Down Expand Up @@ -296,7 +289,6 @@ def test_with_files_no_serial(self, db_request, content_type, renderer_override)
}
for f in files
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand Down Expand Up @@ -349,7 +341,6 @@ def test_with_files_with_serial(self, db_request, content_type, renderer_overrid
}
for f in files
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand Down Expand Up @@ -447,7 +438,6 @@ def test_with_files_with_version_multi_digit(
}
for f in files
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand Down Expand Up @@ -480,7 +470,6 @@ def test_with_files_quarantined_omitted_from_index(
"project-status": {"status": "quarantined"},
"files": [],
"versions": [],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)

Expand Down Expand Up @@ -513,7 +502,6 @@ def test_with_archived_project(
"project-status": {"status": "archived"},
"files": [],
"versions": [],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)

Expand All @@ -539,7 +527,6 @@ def test_with_quarantine_exit_project(
"project-status": {"status": "active"},
"files": [],
"versions": [],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)

Expand Down Expand Up @@ -660,7 +647,6 @@ def route_url(route, **kw):
}
for f in files
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)

Expand Down
255 changes: 0 additions & 255 deletions tests/unit/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
TeamRoleFactory,
)
from ...common.db.packaging import (
AlternateRepositoryFactory,
FileEventFactory,
FileFactory,
JournalEntryFactory,
Expand Down Expand Up @@ -2986,260 +2985,6 @@ def test_manage_project_settings_in_organization_owned(self, monkeypatch):
pretend.call(organization_choices={organization_managed})
]

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

db_request.POST = MultiDict(
{
"display_name": "foo alt repo",
"link_url": "https://example.org",
"description": "foo alt repo descr",
"alternate_repository_location": "add",
}
)
db_request.flags = pretend.stub(enabled=pretend.call_recorder(lambda *a: False))
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)
)
db_request.user = UserFactory.create()

RoleFactory.create(project=project, user=db_request.user, role_name="Owner")

add_alternate_repository_form_class = pretend.call_recorder(
views.AddAlternateRepositoryForm
)
monkeypatch.setattr(
views,
"AddAlternateRepositoryForm",
add_alternate_repository_form_class,
)

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

assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"
assert db_request.session.flash.calls == [
pretend.call("Added alternate repository 'foo alt repo'", queue="success")
]
assert db_request.route_path.calls == [
pretend.call("manage.project.settings", project_name="foo")
]
assert add_alternate_repository_form_class.calls == [
pretend.call(db_request.POST)
]

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

db_request.POST = MultiDict(
{
"display_name": "foo alt repo",
"link_url": "invalid link",
"description": "foo alt repo descr",
"alternate_repository_location": "add",
}
)
db_request.flags = pretend.stub(enabled=pretend.call_recorder(lambda *a: False))
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)
)
db_request.user = UserFactory.create()

RoleFactory.create(project=project, user=db_request.user, role_name="Owner")

add_alternate_repository_form_class = pretend.call_recorder(
views.AddAlternateRepositoryForm
)
monkeypatch.setattr(
views,
"AddAlternateRepositoryForm",
add_alternate_repository_form_class,
)

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

assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"
assert db_request.session.flash.calls == [
pretend.call("Invalid alternate repository location details", queue="error")
]
assert db_request.route_path.calls == [
pretend.call("manage.project.settings", project_name="foo")
]
assert add_alternate_repository_form_class.calls == [
pretend.call(db_request.POST)
]

def test_delete_alternate_repository(self, db_request):
project = ProjectFactory.create(name="foo")
alt_repo = AlternateRepositoryFactory.create(project=project)

db_request.POST = MultiDict(
{
"alternate_repository_id": str(alt_repo.id),
"confirm_alternate_repository_name": alt_repo.name,
"alternate_repository_location": "delete",
}
)
db_request.flags = pretend.stub(enabled=pretend.call_recorder(lambda *a: False))
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)
)
db_request.user = UserFactory.create()

RoleFactory.create(project=project, user=db_request.user, role_name="Owner")

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

assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"
assert db_request.session.flash.calls == [
pretend.call(
f"Deleted alternate repository '{alt_repo.name}'", queue="success"
)
]
assert db_request.route_path.calls == [
pretend.call("manage.project.settings", project_name="foo")
]

@pytest.mark.parametrize("alt_repo_id", [None, "", "blah"])
def test_delete_alternate_repository_invalid_id(self, db_request, alt_repo_id):
project = ProjectFactory.create(name="foo")
alt_repo = AlternateRepositoryFactory.create(project=project)

db_request.POST = MultiDict(
{
"alternate_repository_id": alt_repo_id,
"confirm_alternate_repository_name": alt_repo.name,
"alternate_repository_location": "delete",
}
)
db_request.flags = pretend.stub(enabled=pretend.call_recorder(lambda *a: False))
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)
)
db_request.user = UserFactory.create()

RoleFactory.create(project=project, user=db_request.user, role_name="Owner")

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

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

def test_delete_alternate_repository_wrong_id(self, db_request):
project = ProjectFactory.create(name="foo")
alt_repo = AlternateRepositoryFactory.create(project=project)

db_request.POST = MultiDict(
{
"alternate_repository_id": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"confirm_alternate_repository_name": alt_repo.name,
"alternate_repository_location": "delete",
}
)
db_request.flags = pretend.stub(enabled=pretend.call_recorder(lambda *a: False))
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)
)
db_request.user = UserFactory.create()

RoleFactory.create(project=project, user=db_request.user, role_name="Owner")

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

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

def test_delete_alternate_repository_no_confirm(self, db_request):
project = ProjectFactory.create(name="foo")
alt_repo = AlternateRepositoryFactory.create(project=project)

db_request.POST = MultiDict(
{
"alternate_repository_id": str(alt_repo.id),
"alternate_repository_location": "delete",
}
)
db_request.flags = pretend.stub(enabled=pretend.call_recorder(lambda *a: False))
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)
)
db_request.user = UserFactory.create()

RoleFactory.create(project=project, user=db_request.user, role_name="Owner")

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

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

def test_delete_alternate_repository_wrong_confirm(self, db_request):
project = ProjectFactory.create(name="foo")
alt_repo = AlternateRepositoryFactory.create(project=project)

db_request.POST = MultiDict(
{
"alternate_repository_id": str(alt_repo.id),
"confirm_alternate_repository_name": f"invalid-confirm-{alt_repo.name}",
"alternate_repository_location": "delete",
}
)
db_request.flags = pretend.stub(enabled=pretend.call_recorder(lambda *a: False))
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)
)
db_request.user = UserFactory.create()

RoleFactory.create(project=project, user=db_request.user, role_name="Owner")

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

assert isinstance(result, HTTPSeeOther)
assert result.headers["Location"] == "/the-redirect"
assert db_request.session.flash.calls == [
pretend.call(
f"Could not delete alternate repository - "
f"invalid-confirm-{alt_repo.name} is not the same as {alt_repo.name}",
queue="error",
)
]
assert db_request.route_path.calls == [
pretend.call("manage.project.settings", project_name="foo")
]

def test_remove_organization_project_no_confirm(self):
user = pretend.stub()
project = pretend.stub(
Expand Down
Loading
Loading