-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement Alternate Repository Location for PEP 708 #15716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
04e9ec1
837e464
401ed2b
6877707
81cdf21
cf94d59
6759b55
f21d788
8d53891
cc9111b
3517006
5323726
bfab8e3
ef9d6db
987d129
e6fdd04
52542f9
e52f44e
69c6362
95ee51a
60970a6
1849468
6d4a484
2316455
f7f9244
1df1394
415b85f
64fa33b
21ddc57
724fc0f
4e9e773
3fffca8
ebe29e8
03c15ce
68afe18
d1ac800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,11 @@ | |
from pyramid.testing import DummyRequest | ||
|
||
from warehouse.api import simple | ||
from warehouse.packaging.utils import API_VERSION | ||
from warehouse.packaging.utils import API_VERSION, _valid_simple_detail_context | ||
|
||
from ...common.db.accounts import UserFactory | ||
from ...common.db.packaging import ( | ||
AlternateRepositoryFactory, | ||
FileFactory, | ||
JournalEntryFactory, | ||
ProjectFactory, | ||
|
@@ -48,29 +49,30 @@ def test_defaults_text_html(self, header): | |
default to text/html. | ||
""" | ||
request = DummyRequest(accept=header) | ||
assert simple._select_content_type(request) == "text/html" | ||
assert simple._select_content_type(request) == simple.MIME_TEXT_HTML | ||
|
||
@pytest.mark.parametrize( | ||
("header", "expected"), | ||
[ | ||
("text/html", "text/html"), | ||
(simple.MIME_TEXT_HTML, simple.MIME_TEXT_HTML), | ||
( | ||
"application/vnd.pypi.simple.v1+html", | ||
"application/vnd.pypi.simple.v1+html", | ||
simple.MIME_PYPI_SIMPLE_V1_HTML, | ||
simple.MIME_PYPI_SIMPLE_V1_HTML, | ||
), | ||
( | ||
"application/vnd.pypi.simple.v1+json", | ||
"application/vnd.pypi.simple.v1+json", | ||
simple.MIME_PYPI_SIMPLE_V1_JSON, | ||
simple.MIME_PYPI_SIMPLE_V1_JSON, | ||
), | ||
( | ||
"text/html, application/vnd.pypi.simple.v1+html, " | ||
"application/vnd.pypi.simple.v1+json", | ||
"text/html", | ||
f"{simple.MIME_TEXT_HTML}, {simple.MIME_PYPI_SIMPLE_V1_HTML}, " | ||
f"{simple.MIME_PYPI_SIMPLE_V1_JSON}", | ||
simple.MIME_TEXT_HTML, | ||
), | ||
( | ||
"text/html;q=0.01, application/vnd.pypi.simple.v1+html;q=0.2, " | ||
"application/vnd.pypi.simple.v1+json", | ||
"application/vnd.pypi.simple.v1+json", | ||
f"{simple.MIME_TEXT_HTML};q=0.01, " | ||
f"{simple.MIME_PYPI_SIMPLE_V1_HTML};q=0.2, " | ||
f"{simple.MIME_PYPI_SIMPLE_V1_JSON}", | ||
simple.MIME_PYPI_SIMPLE_V1_JSON, | ||
), | ||
], | ||
) | ||
|
@@ -80,9 +82,9 @@ def test_selects(self, header, expected): | |
|
||
|
||
CONTENT_TYPE_PARAMS = [ | ||
("text/html", None), | ||
("application/vnd.pypi.simple.v1+html", None), | ||
("application/vnd.pypi.simple.v1+json", "json"), | ||
(simple.MIME_TEXT_HTML, None), | ||
(simple.MIME_PYPI_SIMPLE_V1_HTML, None), | ||
(simple.MIME_PYPI_SIMPLE_V1_JSON, "json"), | ||
] | ||
|
||
|
||
|
@@ -211,12 +213,15 @@ def test_no_files_no_serial(self, db_request, content_type, renderer_override): | |
user = UserFactory.create() | ||
JournalEntryFactory.create(submitted_by=user) | ||
|
||
assert simple.simple_detail(project, db_request) == { | ||
context = { | ||
"meta": {"_last-serial": 0, "api-version": API_VERSION}, | ||
"name": project.normalized_name, | ||
"files": [], | ||
"versions": [], | ||
"alternate-locations": [], | ||
} | ||
context = _update_context(context, content_type, renderer_override) | ||
assert simple.simple_detail(project, db_request) == context | ||
|
||
assert db_request.response.headers["X-PyPI-Last-Serial"] == "0" | ||
assert db_request.response.content_type == content_type | ||
|
@@ -235,13 +240,20 @@ 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), | ||
] | ||
|
||
assert simple.simple_detail(project, db_request) == { | ||
context = { | ||
"meta": {"_last-serial": je.id, "api-version": API_VERSION}, | ||
"name": project.normalized_name, | ||
"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 | ||
|
||
assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id) | ||
assert db_request.response.content_type == content_type | ||
|
@@ -271,7 +283,7 @@ def test_with_files_no_serial(self, db_request, content_type, renderer_override) | |
user = UserFactory.create() | ||
JournalEntryFactory.create(submitted_by=user) | ||
|
||
assert simple.simple_detail(project, db_request) == { | ||
context = { | ||
"meta": {"_last-serial": 0, "api-version": API_VERSION}, | ||
"name": project.normalized_name, | ||
"versions": release_versions, | ||
|
@@ -289,7 +301,10 @@ 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 | ||
|
||
assert db_request.response.headers["X-PyPI-Last-Serial"] == "0" | ||
assert db_request.response.content_type == content_type | ||
|
@@ -319,7 +334,7 @@ def test_with_files_with_serial(self, db_request, content_type, renderer_overrid | |
user = UserFactory.create() | ||
je = JournalEntryFactory.create(name=project.name, submitted_by=user) | ||
|
||
assert simple.simple_detail(project, db_request) == { | ||
context = { | ||
"meta": {"_last-serial": je.id, "api-version": API_VERSION}, | ||
"name": project.normalized_name, | ||
"versions": release_versions, | ||
|
@@ -337,7 +352,10 @@ 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 | ||
|
||
assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id) | ||
assert db_request.response.content_type == content_type | ||
|
@@ -404,7 +422,7 @@ def test_with_files_with_version_multi_digit( | |
user = UserFactory.create() | ||
je = JournalEntryFactory.create(name=project.name, submitted_by=user) | ||
|
||
assert simple.simple_detail(project, db_request) == { | ||
context = { | ||
"meta": {"_last-serial": je.id, "api-version": API_VERSION}, | ||
"name": project.normalized_name, | ||
"versions": release_versions, | ||
|
@@ -430,7 +448,10 @@ 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 | ||
|
||
assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id) | ||
assert db_request.response.content_type == content_type | ||
|
@@ -439,6 +460,15 @@ def test_with_files_with_version_multi_digit( | |
if renderer_override is not None: | ||
assert db_request.override_renderer == renderer_override | ||
|
||
|
||
def _update_context(context, content_type, renderer_override): | ||
if renderer_override != "json" or content_type in [ | ||
simple.MIME_TEXT_HTML, | ||
simple.MIME_PYPI_SIMPLE_V1_HTML, | ||
]: | ||
return _valid_simple_detail_context(context) | ||
return context | ||
Comment on lines
+464
to
+470
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be missing something, but I think this helper is currently causing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened #16777 with the fix. |
||
|
||
def test_with_files_quarantined_omitted_from_index(self, db_request): | ||
db_request.accept = "text/html" | ||
project = ProjectFactory.create(lifecycle_status="quarantine-enter") | ||
|
Uh oh!
There was an error while loading. Please reload this page.