Skip to content
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

PEP 694 (resolved merge conflicts from PR #8941) #16277

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0a362e2
Draft Releases working
alanbato Sep 25, 2020
6d65127
Draft Releases now uploadable by twine
alanbato Sep 29, 2020
15e79b8
Fix security history tag display
alanbato Sep 29, 2020
56a8236
Remove old migrations
alanbato Sep 29, 2020
db1369d
Pre-review ready
alanbato Oct 1, 2020
9dc0a13
Fix tests :)
alanbato Oct 2, 2020
9294a52
Fix tests, again :)
alanbato Oct 2, 2020
abc3e66
Update translations file, remove backup migration
alanbato Dec 19, 2020
80058fe
Update translations
di May 2, 2022
9b2ae55
Bring migration back to head
di May 2, 2022
d3c11f8
Remove deprecated factory.fuzzy usage
alanbato May 2, 2022
283fc03
Remove duplicate version entry
alanbato May 2, 2022
e3d6951
Add successful draft upload test
alanbato May 2, 2022
a231b22
Fix successful draft upload test
alanbato May 2, 2022
9eb26c2
Fix lint
alanbato May 2, 2022
f5dfa44
Fix lint x2
alanbato May 2, 2022
83a6f14
Merge branch 'draft-releases' into warsaw/pep-694
warsaw Jul 13, 2024
b0dedff
Merge branch 'main' into warsaw/pep-694
warsaw Jul 13, 2024
38ea032
Lint repair
warsaw Jul 13, 2024
bc2630b
Merge branch 'main' into warsaw/pep-694
warsaw Jul 16, 2024
6207e3c
Merge branch 'main' into warsaw/pep-694
warsaw Aug 13, 2024
620c016
make translations after merge conflict resolution
warsaw Aug 14, 2024
def17fb
make lint fixes
warsaw Aug 14, 2024
b2adb0f
Fix linting error
warsaw Aug 14, 2024
b8b5229
Update translations
warsaw Aug 14, 2024
fd727da
Merge branch 'main' into warsaw/pep-694
warsaw Sep 17, 2024
ed50304
read_only=True seems invalid now
warsaw Sep 17, 2024
fb9e158
alembic migration merge
warsaw Sep 17, 2024
05360c5
Update `None` comparison operations
warsaw Sep 18, 2024
32006b5
Another `isnot(None)` -> `is not None` conversion
warsaw Sep 18, 2024
da990be
Fix linting
warsaw Sep 18, 2024
92c7a25
Merge branch 'main' into warsaw/pep-694
warsaw Sep 19, 2024
6ecacf3
Checkpointing migrations fix
warsaw Sep 21, 2024
a77e0ab
Seemingly fix migrations by running autogenerate again
warsaw Sep 21, 2024
14d597f
Fix `make lint`
warsaw Sep 21, 2024
3bff8ae
Merge branch 'main' into warsaw/pep-694
warsaw Sep 21, 2024
24cbde6
Make `make checkdb` happy
warsaw Sep 21, 2024
5f9c39c
Merge branch 'main' into warsaw/pep-694
warsaw Sep 23, 2024
33739ec
Some form items are optional
warsaw Sep 24, 2024
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
3 changes: 3 additions & 0 deletions tests/common/db/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class Meta:

uploader = factory.SubFactory(UserFactory)
description = factory.SubFactory(DescriptionFactory)
published = factory.Faker(
"date_time_between_dates", datetime_start=datetime.datetime(2008, 1, 1)
)


class FileFactory(WarehouseFactory):
Expand Down
84 changes: 76 additions & 8 deletions tests/unit/forklift/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,7 @@ def test_fails_with_invalid_names(self, pyramid_config, db_request, name):

@pytest.mark.parametrize(
"conflicting_name",
[
"toast1ng",
"toastlng",
"t0asting",
"toast-ing",
"toast.ing",
"toast_ing",
],
["toast1ng", "toastlng", "t0asting", "toast-ing", "toast.ing", "toast_ing"],
)
def test_fails_with_ultranormalized_names(
self, pyramid_config, db_request, conflicting_name
Expand Down Expand Up @@ -3439,6 +3432,81 @@ def test_upload_succeeds_creates_release(
),
]

@pytest.mark.parametrize("is_draft", [(True,), (False,)])
def test_upload_succeeds_creates_draft_release(
self,
pyramid_config,
db_request,
metrics,
is_draft,
):
pyramid_config.testing_securitypolicy(userid=1)

user = UserFactory.create()
EmailFactory.create(user=user)
project = ProjectFactory.create()
RoleFactory.create(user=user, project=project)

db_request.db.add(Classifier(classifier="Environment :: Other Environment"))
db_request.db.add(Classifier(classifier="Programming Language :: Python"))

filename = "{}-{}.tar.gz".format(project.name, "1.0")

db_request.user = user
db_request.user_agent = "warehouse-tests/6.6.6"
draft_header = {"Is-Draft": "True" if is_draft else "False"}
db_request.headers.update(draft_header)
db_request.POST = MultiDict(
{
"metadata_version": "1.2",
"name": project.name,
"version": "1.0",
"summary": "This is my summary!",
"filetype": "sdist",
"md5_digest": _TAR_GZ_PKG_MD5,
"content": pretend.stub(
filename=filename,
file=io.BytesIO(_TAR_GZ_PKG_TESTDATA),
type="application/tar",
),
}
)
db_request.POST.extend(
[
("classifiers", "Environment :: Other Environment"),
("classifiers", "Programming Language :: Python"),
("requires_dist", "foo"),
("requires_dist", "bar (>1.0)"),
("project_urls", "Test, https://example.com/"),
("requires_external", "Cheese (>1.0)"),
("provides", "testing"),
]
)

storage_service = pretend.stub(store=lambda path, filepath, meta: None)
db_request.find_service = lambda svc, name=None, context=None: {
IFileStorage: storage_service,
IMetricsService: metrics,
}.get(svc)

resp = legacy.file_upload(db_request)

assert resp.status_code == 200

# Ensure that a Release object has been created.
release = (
db_request.db.query(Release)
.filter((Release.project == project) & (Release.version == "1.0"))
.one()
)
if is_draft:
assert release.published is None
else:
assert release.published is not None
assert release.is_draft is is_draft
assert release.version == "1.0"
assert release.canonical_version == "1"

def test_upload_with_valid_attestation_succeeds(
self,
monkeypatch,
Expand Down
167 changes: 167 additions & 0 deletions tests/unit/legacy/api/test_draft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# 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.

from warehouse.legacy.api import draft

from ....common.db.accounts import UserFactory
from ....common.db.packaging import (
FileFactory,
JournalEntryFactory,
ProjectFactory,
ReleaseFactory,
)


class TestDraftIndex:
def test_with_results_no_serial(self, db_request):
project = ProjectFactory.create()
release = ReleaseFactory.create(project=project, version="1.0", published=None)
draft_project_dict = {project.name: release}
assert draft.draft_index(draft_project_dict, db_request) == {
"draft_project_dict": draft_project_dict
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == "0"

def test_with_results_with_serial(self, db_request):
project = ProjectFactory.create()
release = ReleaseFactory.create(project=project, version="1.0", published=None)
draft_project_dict = {project.name: release}
user = UserFactory.create()
je = JournalEntryFactory.create(submitted_by=user)

assert draft.draft_index(draft_project_dict, db_request) == {
"draft_project_dict": draft_project_dict
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id)


class TestDraftDetail:
def test_no_files_no_serial(self, db_request):
project = ProjectFactory.create()
release = ReleaseFactory.create(project=project, version="1.0", published=None)
db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
JournalEntryFactory.create(submitted_by=user)

assert draft.draft_detail(release, db_request) == {
"project": project,
"files": [],
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == "0"

def test_no_files_with_serial(self, db_request):
project = ProjectFactory.create()
release = ReleaseFactory.create(project=project, version="1.0", published=None)
db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

assert draft.draft_detail(release, db_request) == {
"project": project,
"files": [],
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id)

def test_with_files_no_serial(self, db_request):
project = ProjectFactory.create()
release = ReleaseFactory.create(project=project, version="1.0", published=None)
files = [
FileFactory.create(
release=release,
filename=f"{project.name}-{release.version}.tar.gz",
)
]
db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
JournalEntryFactory.create(submitted_by=user)

assert draft.draft_detail(release, db_request) == {
"project": project,
"files": files,
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == "0"

def test_with_files_with_serial(self, db_request):
project = ProjectFactory.create()
release = ReleaseFactory.create(project=project, version="1.0", published=None)
files = [
FileFactory.create(
release=release,
filename=f"{project.name}-{release.version}.tar.gz",
)
]
db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

assert draft.draft_detail(release, db_request) == {
"project": project,
"files": files,
}
assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id)

def test_with_files_with_version_multi_digit(self, db_request):
project = ProjectFactory.create()
release_versions = [
"0.3.0rc1",
"0.3.0",
"0.3.0-post0",
"0.14.0",
"4.2.0",
"24.2.0",
]
releases = [
ReleaseFactory.create(project=project, version=version, published=None)
for version in release_versions
]

tar_files = [
FileFactory.create(
release=r,
filename=f"{project.name}-{r.version}.tar.gz",
packagetype="sdist",
)
for r in releases
]
wheel_files = [
FileFactory.create(
release=r,
filename=f"{project.name}-{r.version}.whl",
packagetype="bdist_wheel",
)
for r in releases
]
egg_files = [
FileFactory.create(
release=r,
filename=f"{project.name}-{r.version}.egg",
packagetype="bdist_egg",
)
for r in releases
]

files = [
list(files_release)
for files_release in zip(egg_files, tar_files, wheel_files)
]

db_request.matchdict["name"] = project.normalized_name
user = UserFactory.create()
je = JournalEntryFactory.create(name=project.name, submitted_by=user)

for release, files_release in zip(releases, files):
assert draft.draft_detail(release, db_request) == {
"project": project,
"files": files_release,
}

assert db_request.response.headers["X-PyPI-Last-Serial"] == str(je.id)
Loading
Loading