Skip to content

Commit

Permalink
remove self-reference from Simple HTML and JSON
Browse files Browse the repository at this point in the history
The PEP reads as though they can be implied "When using alternate locations, clients MUST implicitly assume that the url the response was fetched from was included in the list."
  • Loading branch information
ewdurbin committed Sep 19, 2024
1 parent 3fffca8 commit ebe29e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 51 deletions.
48 changes: 8 additions & 40 deletions tests/unit/api/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ def test_redirects(self, pyramid_request):
def test_no_files_no_serial(self, db_request, content_type, renderer_override):
db_request.accept = content_type
project = ProjectFactory.create()
db_request.route_url = lambda route_name, **kwargs: (
f"http://localhost/simple/{project.normalized_name}"
)
db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
JournalEntryFactory.create(submitted_by=user)
Expand All @@ -221,9 +218,7 @@ def test_no_files_no_serial(self, db_request, content_type, renderer_override):
"name": project.normalized_name,
"files": [],
"versions": [],
"alternate-locations": [
f"http://localhost/simple/{project.normalized_name}"
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand All @@ -242,9 +237,6 @@ def test_no_files_no_serial(self, db_request, content_type, renderer_override):
def test_no_files_with_serial(self, db_request, content_type, renderer_override):
db_request.accept = content_type
project = ProjectFactory.create()
db_request.route_url = lambda route_name, **kwargs: (
f"http://localhost/simple/{project.normalized_name}"
)
db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)
Expand All @@ -258,10 +250,7 @@ def test_no_files_with_serial(self, db_request, content_type, renderer_override)
"name": project.normalized_name,
"files": [],
"versions": [],
"alternate-locations": [
f"http://localhost/simple/{project.normalized_name}"
]
+ sorted(al.url for al in als),
"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 All @@ -280,9 +269,6 @@ def test_no_files_with_serial(self, db_request, content_type, renderer_override)
def test_with_files_no_serial(self, db_request, content_type, renderer_override):
db_request.accept = content_type
project = ProjectFactory.create()
db_request.route_url = lambda route_name, **kwargs: (
f"http://localhost/simple/{project.normalized_name}"
)
releases = ReleaseFactory.create_batch(3, project=project)
release_versions = sorted([r.version for r in releases], key=parse)
files = [
Expand All @@ -293,11 +279,7 @@ def test_with_files_no_serial(self, db_request, content_type, renderer_override)
files = sorted(files, key=lambda f: (parse(f.release.version), f.filename))
urls_iter = (f"/file/{f.filename}" for f in files)
db_request.matchdict["name"] = project.normalized_name
db_request.route_url = lambda route_name, **kw: (
next(urls_iter)
if route_name == "packaging.file"
else f"http://localhost/simple/{project.normalized_name}"
)
db_request.route_url = lambda *a, **kw: next(urls_iter)
user = UserFactory.create()
JournalEntryFactory.create(submitted_by=user)

Expand All @@ -319,9 +301,7 @@ def test_with_files_no_serial(self, db_request, content_type, renderer_override)
}
for f in files
],
"alternate-locations": [
f"http://localhost/simple/{project.normalized_name}"
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand Down Expand Up @@ -350,11 +330,7 @@ def test_with_files_with_serial(self, db_request, content_type, renderer_overrid
files = sorted(files, key=lambda f: (parse(f.release.version), f.filename))
urls_iter = (f"/file/{f.filename}" for f in files)
db_request.matchdict["name"] = project.normalized_name
db_request.route_url = lambda route_name, **kw: (
next(urls_iter)
if route_name == "packaging.file"
else f"http://localhost/simple/{project.normalized_name}"
)
db_request.route_url = lambda *a, **kw: next(urls_iter)
user = UserFactory.create()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

Expand All @@ -376,9 +352,7 @@ def test_with_files_with_serial(self, db_request, content_type, renderer_overrid
}
for f in files
],
"alternate-locations": [
f"http://localhost/simple/{project.normalized_name}"
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand Down Expand Up @@ -444,11 +418,7 @@ def test_with_files_with_version_multi_digit(

urls_iter = (f"/file/{f.filename}" for f in files)
db_request.matchdict["name"] = project.normalized_name
db_request.route_url = lambda route_name, **kw: (
next(urls_iter)
if route_name == "packaging.file"
else f"http://localhost/simple/{project.normalized_name}"
)
db_request.route_url = lambda *a, **kw: next(urls_iter)
user = UserFactory.create()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

Expand Down Expand Up @@ -478,9 +448,7 @@ def test_with_files_with_version_multi_digit(
}
for f in files
],
"alternate-locations": [
f"http://localhost/simple/{project.normalized_name}"
],
"alternate-locations": [],
}
context = _update_context(context, content_type, renderer_override)
assert simple.simple_detail(project, db_request) == context
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/packaging/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ def test_render_simple_detail_with_store(db_request, monkeypatch, jinja):
ISimpleStorage: storage_service,
}.get(svc)
)
db_request.route_url = pretend.call_recorder(
lambda path_name, name=None: f"http://localhost/simple/{name}"
)

fake_hasher = pretend.stub(
update=pretend.call_recorder(lambda x: None),
Expand Down Expand Up @@ -127,11 +124,6 @@ def __exit__(self, type, value, traceback):
assert fake_hasher.update.calls == [pretend.call(expected_content)]
assert fake_hasher.hexdigest.calls == [pretend.call()]

assert db_request.route_url.calls == [
pretend.call("api.simple.detail", name=project.normalized_name),
pretend.call("api.simple.detail", name=project.normalized_name),
]

assert storage_service.store.calls == [
pretend.call(
(
Expand Down
6 changes: 3 additions & 3 deletions warehouse/packaging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def _simple_detail(project, request):
versions = sorted(
{f.release.version for f in files}, key=packaging_legacy.version.parse
)
alternate_repositories = [
request.route_url("api.simple.detail", name=project.normalized_name)
] + sorted(alt_repo.url for alt_repo in project.alternate_repositories)
alternate_repositories = sorted(
alt_repo.url for alt_repo in project.alternate_repositories
)

return {
"meta": {"api-version": API_VERSION, "_last-serial": project.last_serial},
Expand Down

0 comments on commit ebe29e8

Please sign in to comment.