From d5f4a015f01f9572341111d69aba4051c0c0f381 Mon Sep 17 00:00:00 2001 From: Donald Stufft Date: Sun, 26 Jun 2022 13:45:32 -0400 Subject: [PATCH] The simple API is no longer considered a legacy api --- tests/functional/test_templates.py | 1 + tests/unit/api/__init__.py | 11 +++++++++++ tests/unit/{legacy => }/api/test_simple.py | 6 +++--- tests/unit/packaging/test_utils.py | 4 ++-- tests/unit/test_routes.py | 4 ++-- warehouse/api/__init__.py | 11 +++++++++++ warehouse/{legacy => }/api/simple.py | 8 ++++---- warehouse/packaging/utils.py | 2 +- warehouse/routes.py | 7 ++++--- .../templates/{legacy => }/api/simple/detail.html | 0 .../templates/{legacy => }/api/simple/index.html | 2 +- 11 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 tests/unit/api/__init__.py rename tests/unit/{legacy => }/api/test_simple.py (99%) create mode 100644 warehouse/api/__init__.py rename warehouse/{legacy => }/api/simple.py (95%) rename warehouse/templates/{legacy => }/api/simple/detail.html (100%) rename warehouse/templates/{legacy => }/api/simple/index.html (86%) diff --git a/tests/functional/test_templates.py b/tests/functional/test_templates.py index 4ac6dbc0a298..fdd0c7b21e9a 100644 --- a/tests/functional/test_templates.py +++ b/tests/functional/test_templates.py @@ -57,6 +57,7 @@ def test_templates_for_empty_titles(): for dir_, _, files in os.walk(dir_name): if ( dir_.find("/includes") > -1 + or dir_.find("/api") > -1 or dir_.find("/legacy") > -1 or dir_.find("/email/") > -1 ): diff --git a/tests/unit/api/__init__.py b/tests/unit/api/__init__.py new file mode 100644 index 000000000000..164f68b09175 --- /dev/null +++ b/tests/unit/api/__init__.py @@ -0,0 +1,11 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/tests/unit/legacy/api/test_simple.py b/tests/unit/api/test_simple.py similarity index 99% rename from tests/unit/legacy/api/test_simple.py rename to tests/unit/api/test_simple.py index 58b310042541..922f2cf82232 100644 --- a/tests/unit/legacy/api/test_simple.py +++ b/tests/unit/api/test_simple.py @@ -16,10 +16,10 @@ from pyramid.httpexceptions import HTTPMovedPermanently from pyramid.testing import DummyRequest -from warehouse.legacy.api import simple +from warehouse.api import simple -from ....common.db.accounts import UserFactory -from ....common.db.packaging import ( +from ...common.db.accounts import UserFactory +from ...common.db.packaging import ( FileFactory, JournalEntryFactory, ProjectFactory, diff --git a/tests/unit/packaging/test_utils.py b/tests/unit/packaging/test_utils.py index d3ea82bf63bd..2a55540c92d0 100644 --- a/tests/unit/packaging/test_utils.py +++ b/tests/unit/packaging/test_utils.py @@ -31,7 +31,7 @@ def test_render_simple_detail(db_request, monkeypatch, jinja): fakeblake2b = pretend.call_recorder(lambda *a, **kw: fake_hasher) monkeypatch.setattr(hashlib, "blake2b", fakeblake2b) - template = jinja.get_template("templates/legacy/api/simple/detail.html") + template = jinja.get_template("templates/api/simple/detail.html") expected_content = template.render( **_simple_detail(project, db_request), request=db_request ).encode("utf-8") @@ -88,7 +88,7 @@ def __exit__(self, type, value, traceback): monkeypatch.setattr(tempfile, "NamedTemporaryFile", FakeNamedTemporaryFile) - template = jinja.get_template("templates/legacy/api/simple/detail.html") + template = jinja.get_template("templates/api/simple/detail.html") expected_content = template.render( **_simple_detail(project, db_request), request=db_request ).encode("utf-8") diff --git a/tests/unit/test_routes.py b/tests/unit/test_routes.py index e0ede905e378..c3a34fa8ffab 100644 --- a/tests/unit/test_routes.py +++ b/tests/unit/test_routes.py @@ -432,9 +432,9 @@ def add_policy(name, filename): "/_/vulnerabilities/osv/report", domain=warehouse, ), - pretend.call("legacy.api.simple.index", "/simple/", domain=warehouse), + pretend.call("api.simple.index", "/simple/", domain=warehouse), pretend.call( - "legacy.api.simple.detail", + "api.simple.detail", "/simple/{name}/", factory="warehouse.packaging.models:ProjectFactory", traverse="/{name}/", diff --git a/warehouse/api/__init__.py b/warehouse/api/__init__.py new file mode 100644 index 000000000000..164f68b09175 --- /dev/null +++ b/warehouse/api/__init__.py @@ -0,0 +1,11 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/warehouse/legacy/api/simple.py b/warehouse/api/simple.py similarity index 95% rename from warehouse/legacy/api/simple.py rename to warehouse/api/simple.py index c3379d531104..674d1ee06905 100644 --- a/warehouse/legacy/api/simple.py +++ b/warehouse/api/simple.py @@ -52,8 +52,8 @@ def _select_content_type(request: Request) -> str: @view_config( - route_name="legacy.api.simple.index", - renderer="legacy/api/simple/index.html", + route_name="api.simple.index", + renderer="api/simple/index.html", decorator=[ add_vary("Accept"), cache_control(10 * 60), # 10 minutes @@ -79,9 +79,9 @@ def simple_index(request): @view_config( - route_name="legacy.api.simple.detail", + route_name="api.simple.detail", context=Project, - renderer="legacy/api/simple/detail.html", + renderer="api/simple/detail.html", decorator=[ add_vary("Accept"), cache_control(10 * 60), # 10 minutes diff --git a/warehouse/packaging/utils.py b/warehouse/packaging/utils.py index 38aa819b83a6..6c9b0588a059 100644 --- a/warehouse/packaging/utils.py +++ b/warehouse/packaging/utils.py @@ -73,7 +73,7 @@ def render_simple_detail(project, request, store=False): context = _simple_detail(project, request) env = request.registry.queryUtility(IJinja2Environment, name=".jinja2") - template = env.get_template("templates/legacy/api/simple/detail.html") + template = env.get_template("templates/api/simple/detail.html") content = template.render(**context, request=request) content_hasher = hashlib.blake2b(digest_size=256 // 8) diff --git a/warehouse/routes.py b/warehouse/routes.py index 1eaf5bd9edc4..07cbf3c4f043 100644 --- a/warehouse/routes.py +++ b/warehouse/routes.py @@ -427,10 +427,10 @@ def includeme(config): domain=warehouse, ) - # Legacy URLs - config.add_route("legacy.api.simple.index", "/simple/", domain=warehouse) + # API URLs + config.add_route("api.simple.index", "/simple/", domain=warehouse) config.add_route( - "legacy.api.simple.detail", + "api.simple.detail", "/simple/{name}/", factory="warehouse.packaging.models:ProjectFactory", traverse="/{name}/", @@ -438,6 +438,7 @@ def includeme(config): domain=warehouse, ) + # Legacy URLs config.add_route( "legacy.api.json.project", "/pypi/{name}/json", diff --git a/warehouse/templates/legacy/api/simple/detail.html b/warehouse/templates/api/simple/detail.html similarity index 100% rename from warehouse/templates/legacy/api/simple/detail.html rename to warehouse/templates/api/simple/detail.html diff --git a/warehouse/templates/legacy/api/simple/index.html b/warehouse/templates/api/simple/index.html similarity index 86% rename from warehouse/templates/legacy/api/simple/index.html rename to warehouse/templates/api/simple/index.html index 97b84c09d935..d5b9009fc305 100644 --- a/warehouse/templates/legacy/api/simple/index.html +++ b/warehouse/templates/api/simple/index.html @@ -19,7 +19,7 @@ {% for project in projects -%} - {{ project.name }} + {{ project.name }} {% endfor -%}