Repository: pypi/warehouse

Issue:
Make error message (for invalid project name) work with Test PyPI
Right now, when someone tries to upload a package to PyPI but the project name they want to use is not a project name we allow, the error message we send them includes -- hardcoded -- the URL https://pypi.org. Instead, we should use Pyramid's URL routing to refer to the URL of the PyPI in question, thus ensuring that we send error messages that, as appropriate, refer to pypi.org, test.pypi.org, or any other future PyPI.

To fix this, look at `warehouse/forklift/legacy.py` and `tests/unit/forklift/test_legacy.py` ([the test is `test_fails_with_invalid_names`](https://github.com/pypa/warehouse/blob/master/tests/unit/forklift/test_legacy.py#L872)), and make changes similar to the changes I made in #3183. If you're used to string substitution/string formatting in Python, this should be a relatively approachable first Warehouse issue.

---

**Good First Issue**: This issue is good for first time contributors. If you've already contributed to Warehouse, please work on [another issue without this label](https://github.com/pypa/warehouse/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+-label%3A%22good+first+issue%22) instead. If there is not a corresponding pull request for this issue, it is up for grabs. For directions for getting set up, see our [Getting Started Guide](https://warehouse.pypa.io/development/getting-started/). If you are working on this issue and have questions, please feel free to ask them here, [`#pypa-dev` on Freenode](https://webchat.freenode.net/?channels=%23pypa-dev), or the [pypa-dev mailing list](https://groups.google.com/forum/#!forum/pypa-dev).



Discussion:
I'm working on this issue.
Hi @pgadige! Saw your question in IRC about logging in within your local developer environment. As Dustin said, check https://warehouse.readthedocs.io/development/getting-started/#logging-in-to-warehouse . Glad to have you joining us!

You mentioned you're interested in the larger process of building something like Warehouse. I recommend you take a look at:

* [the PyPA's list of presentations and articles](https://www.pypa.io/en/latest/presentations/)
* [PyPA's history of Python packaging](https://www.pypa.io/en/latest/history/)
* [the Warehouse roadmap](https://wiki.python.org/psf/WarehouseRoadmap)
* [blog posts, mailing list messages, and notes from our core developer meetings](https://wiki.python.org/psf/PackagingWG)
* [Warehouse application overview](https://warehouse.readthedocs.io/application/)

Resolving patch:
diff --git a/warehouse/forklift/legacy.py b/warehouse/forklift/legacy.py
--- a/warehouse/forklift/legacy.py
+++ b/warehouse/forklift/legacy.py
@@ -813,10 +813,12 @@ def file_upload(request):
                 func.normalize_pep426_name(form.name.data))).scalar():
             raise _exc_with_message(
                 HTTPBadRequest,
-                ("The name {!r} is not allowed. "
-                 "See https://pypi.org/help/#project-name "
-                 "for more information.")
-                .format(form.name.data),
+                ("The name {name!r} is not allowed. "
+                 "See {projecthelp} "
+                 "for more information.").format(
+                    name=form.name.data,
+                    projecthelp=request.route_url(
+                        'help', _anchor='project-name')),
             ) from None
 
         # Also check for collisions with Python Standard Library modules.


Test patch:
diff --git a/tests/unit/forklift/test_legacy.py b/tests/unit/forklift/test_legacy.py
--- a/tests/unit/forklift/test_legacy.py
+++ b/tests/unit/forklift/test_legacy.py
@@ -915,14 +915,22 @@ def test_fails_with_invalid_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. "
-                               "See https://pypi.org/help/#project-name "
+                               "See /the/help/url/ "
                                "for more information.").format(name)
 
     @pytest.mark.parametrize("name", ["xml", "XML", "pickle", "PiCKle",