Skip to content

Commit e8195e4

Browse files
dimiketheman
andauthored
Add some releases to the Simple API functional test (#16556)
* Restructure functional test directory * Add some releases to the Simple API functional test * Update tests/functional/api/test_simple.py Co-authored-by: Mike Fiedler <[email protected]> * Use HTTPStatus everywhere instead of integers --------- Co-authored-by: Mike Fiedler <[email protected]>
1 parent ca2781e commit e8195e4

File tree

11 files changed

+85
-41
lines changed

11 files changed

+85
-41
lines changed

tests/functional/legacy_api/test_simple.py renamed to tests/functional/api/test_simple.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from http import HTTPStatus
1414

15-
from ...common.db.packaging import ProjectFactory
15+
from ...common.db.packaging import ProjectFactory, ReleaseFactory
1616

1717

1818
def test_simple_api_html(webtest):
@@ -24,6 +24,7 @@ def test_simple_api_html(webtest):
2424

2525
def test_simple_api_detail(webtest):
2626
project = ProjectFactory.create()
27+
ReleaseFactory.create_batch(2, project=project)
2728

2829
resp = webtest.get(f"/simple/{project.normalized_name}/", status=HTTPStatus.OK)
2930

tests/functional/forklift/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.

tests/functional/legacy_api/test_basic.py renamed to tests/functional/forklift/test_legacy.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13+
from http import HTTPStatus
14+
15+
import pytest
16+
1317

1418
def test_incorrect_post_redirect(webtest):
1519
"""
@@ -19,11 +23,28 @@ def test_incorrect_post_redirect(webtest):
1923
2024
See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308
2125
"""
22-
resp = webtest.post("/legacy", status=308)
26+
resp = webtest.post("/legacy", status=HTTPStatus.PERMANENT_REDIRECT)
2327
assert resp.status == (
2428
"308 An upload was attempted to /legacy but the expected upload URL is "
2529
"/legacy/ (with a trailing slash)"
2630
)
2731

2832
assert "location" in resp.headers
2933
assert resp.headers["location"] == "http://localhost/legacy/"
34+
35+
36+
@pytest.mark.parametrize("action", ["submit", "submit_pkg_info"])
37+
def test_removed_upload_apis(webtest, action):
38+
resp = webtest.post(f"/legacy/?:action={action}", status=HTTPStatus.GONE)
39+
assert resp.status == (
40+
"410 Project pre-registration is no longer required or supported, "
41+
"upload your files instead."
42+
)
43+
44+
45+
def test_remove_doc_upload(webtest):
46+
resp = webtest.post("/legacy/?:action=doc_upload", status=HTTPStatus.GONE)
47+
assert resp.status == (
48+
"410 Uploading documentation is no longer supported, we recommend "
49+
"using https://readthedocs.org/."
50+
)

tests/functional/legacy/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
from http import HTTPStatus
14+
15+
16+
def test_doap(webtest):
17+
resp = webtest.get(
18+
"/pypi?:action=doap&name=foo&version=1.0", status=HTTPStatus.GONE
19+
)
20+
assert resp.status == "410 DOAP is no longer supported."

tests/functional/legacy_api/test_removed.py

-35
This file was deleted.

tests/functional/test_basic.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13+
from http import HTTPStatus
14+
1315
import pytest
1416
import webtest
1517

@@ -21,7 +23,7 @@ def test_robots_txt(app_config, domain, indexable):
2123
app_config.add_settings({"warehouse.domain": domain, "enforce_https": False})
2224
testapp = webtest.TestApp(app_config.make_wsgi_app())
2325
resp = testapp.get("/robots.txt")
24-
assert resp.status_code == 200
26+
assert resp.status_code == HTTPStatus.OK
2527
assert resp.content_type == "text/plain"
2628
body = resp.body.decode(resp.charset)
2729
if indexable:
@@ -45,5 +47,5 @@ def test_robots_txt(app_config, domain, indexable):
4547

4648

4749
def test_non_existent_route_404(webtest):
48-
resp = webtest.get("/asdadadasdasd/", status=404)
49-
assert resp.status_code == 404
50+
resp = webtest.get("/asdadadasdasd/", status=HTTPStatus.NOT_FOUND)
51+
assert resp.status_code == HTTPStatus.NOT_FOUND

tests/functional/test_user_profile.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13+
from http import HTTPStatus
14+
1315
from tests.common.db.accounts import UserFactory
1416

1517

@@ -27,4 +29,4 @@ def test_user_profile(webtest):
2729
assert user.username
2830
# ...and verify that the user's profile page exists
2931
resp = webtest.get(f"/user/{user.username}/")
30-
assert resp.status_code == 200
32+
assert resp.status_code == HTTPStatus.OK

0 commit comments

Comments
 (0)