Skip to content

Make two upload tests URL-independent #3183

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

Merged
merged 2 commits into from
Mar 8, 2018
Merged
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
30 changes: 27 additions & 3 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,16 +926,24 @@ def test_fails_with_stdlib_names(self, pyramid_config, db_request, name):
),
})

db_request.route_url = pretend.call_recorder(
lambda route, **kw: "/the/help/url/"
)

with pytest.raises(HTTPBadRequest) as excinfo:
legacy.file_upload(db_request)

resp = excinfo.value

assert db_request.route_url.calls == [
pretend.call('help', _anchor='project-name')
]

assert resp.status_code == 400
assert resp.status == (("400 The name {!r} is not allowed (conflict "
"with Python Standard Library module name). "
"See https://pypi.org/help/#project-name "
"for more information.").format(name))
"See /the/help/url/ "
"for more information.")).format(name)

def test_fails_with_admin_flag_set(self, pyramid_config, db_request):
admin_flag = (db_request.db.query(AdminFlag)
Expand Down Expand Up @@ -1885,9 +1893,25 @@ def test_upload_fails_without_permission(self, pyramid_config, db_request):
),
})

with pytest.raises(HTTPForbidden):
db_request.route_url = pretend.call_recorder(
lambda route, **kw: "/the/help/url/"
)

with pytest.raises(HTTPForbidden) as excinfo:
legacy.file_upload(db_request)

resp = excinfo.value

assert db_request.route_url.calls == [
pretend.call('help', _anchor='project-name')
]
assert resp.status_code == 403
assert resp.status == (
"403 The user '{0}' is not allowed to upload to project '{1}'. "
"See /the/help/url/ for more information.").format(
user2.username,
project.name)

@pytest.mark.parametrize(
"plat",
["any", "win32", "win_amd64", "win_ia64",
Expand Down
14 changes: 9 additions & 5 deletions warehouse/forklift/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,12 @@ def file_upload(request):
STDLIB_PROHIBITTED):
raise _exc_with_message(
HTTPBadRequest,
("The name {!r} is not allowed (conflict with Python "
("The name {name!r} is not allowed (conflict with Python "
"Standard Library module name). See "
"https://pypi.org/help/#project-name for more information.")
.format(form.name.data),
"{projecthelp} for more information.").format(
name=form.name.data,
projecthelp=request.route_url(
'help', _anchor='project-name')),
) from None

# The project doesn't exist in our database, so we'll add it along with
Expand Down Expand Up @@ -830,8 +832,10 @@ def file_upload(request):
raise _exc_with_message(
HTTPForbidden,
("The user '{0}' is not allowed to upload to project '{1}'. "
"See https://pypi.org/help#project-name for more information.")
.format(request.user.username, project.name)
"See {2} for more information.")
.format(request.user.username, project.name, request.route_url(
'help', _anchor='project-name')
)
)

try:
Expand Down