Skip to content

Update project name on new release if release name is equivalent #4783

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 8 commits into from
Dec 12, 2018
53 changes: 53 additions & 0 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,59 @@ def test_upload_fails_with_unsupported_wheel_plat(
"400 Binary wheel .* has an unsupported " "platform tag .*", resp.status
)

def test_upload_updates_existing_project_name(self, pyramid_config, db_request):
pyramid_config.testing_securitypolicy(userid=1)

user = UserFactory.create()
EmailFactory.create(user=user)
project = ProjectFactory.create(name="Package-Name")
RoleFactory.create(user=user, project=project)

new_project_name = "package-name"
filename = "{}-{}.tar.gz".format(new_project_name, "1.1")

db_request.user = user
db_request.remote_addr = "10.10.10.20"
db_request.user_agent = "warehouse-tests/6.6.6"
db_request.POST = MultiDict(
{
"metadata_version": "1.1",
"name": new_project_name,
"version": "1.1",
"summary": "This is my summary!",
"filetype": "sdist",
"md5_digest": "335c476dc930b959dda9ec82bd65ef19",
"content": pretend.stub(
filename=filename,
file=io.BytesIO(b"A fake file."),
type="application/tar",
),
}
)

storage_service = pretend.stub(store=lambda path, filepath, meta: None)
db_request.find_service = lambda svc, name=None: storage_service
db_request.remote_addr = "10.10.10.10"
db_request.user_agent = "warehouse-tests/6.6.6"

resp = legacy.file_upload(db_request)

assert resp.status_code == 200

# Ensure that a Project object name has been updated.
project = (
db_request.db.query(Project).filter(Project.name == new_project_name).one()
)

# Ensure that a Release object has been created.
release = (
db_request.db.query(Release)
.filter((Release.project == project) & (Release.version == "1.1"))
.one()
)

assert release.uploaded_via == "warehouse-tests/6.6.6"

def test_upload_succeeds_creates_release(self, pyramid_config, db_request):
pyramid_config.testing_securitypolicy(userid=1)

Expand Down
6 changes: 6 additions & 0 deletions warehouse/forklift/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,12 @@ def file_upload(request):
),
)

# Update name if it differs but is still equivalent. We don't need to check if
# they are equivalent when normalized because that's already been done when we
# queried for the project.
if project.name != form.name.data:
project.name = form.name.data

# Uploading should prevent broken rendered descriptions.
# Temporarily disabled, see
# https://github.com/pypa/warehouse/issues/4079
Expand Down