diff --git a/tests/common/db/packaging.py b/tests/common/db/packaging.py index f0ed676d1e78..462f6bb9e0a9 100644 --- a/tests/common/db/packaging.py +++ b/tests/common/db/packaging.py @@ -178,7 +178,6 @@ class JournalEntryFactory(WarehouseFactory): class Meta: model = JournalEntry - id = factory.Sequence(lambda n: n) name = factory.Faker("word") version = factory.Sequence(lambda n: str(n) + ".0") submitted_date = factory.Faker( diff --git a/tests/unit/admin/views/test_projects.py b/tests/unit/admin/views/test_projects.py index 111ada63e3d8..39057c7e35dc 100644 --- a/tests/unit/admin/views/test_projects.py +++ b/tests/unit/admin/views/test_projects.py @@ -17,7 +17,9 @@ import pretend import pytest +from paginate_sqlalchemy import SqlalchemyOrmPage from pyramid.httpexceptions import HTTPBadRequest, HTTPMovedPermanently, HTTPSeeOther +from sqlalchemy.orm import joinedload from tests.common.db.oidc import GitHubPublisherFactory from warehouse.admin.views import projects as views @@ -25,6 +27,7 @@ from warehouse.packaging.models import Project, Role from warehouse.packaging.tasks import update_release_description from warehouse.search.tasks import reindex_project +from warehouse.utils.paginate import paginate_url_factory from ....common.db.accounts import UserFactory from ....common.db.observations import ObserverFactory @@ -433,18 +436,32 @@ def test_with_page(self, db_request): observer = ObserverFactory.create() UserFactory.create(observer=observer) project = ProjectFactory.create() - observations = ProjectObservationFactory.create_batch( + ProjectObservationFactory.create_batch( size=30, related=project, observer=observer ) + observations_query = ( + db_request.db.query(project.Observation) + .options(joinedload(project.Observation.observer)) + .filter(project.Observation.related == project) + .order_by(project.Observation.created.desc()) + ) + observations_page = SqlalchemyOrmPage( + observations_query, + page=2, + items_per_page=25, + url_maker=paginate_url_factory(db_request), + ) + db_request.matchdict["project_name"] = project.normalized_name db_request.GET["page"] = "2" result = views.project_observations_list(project, db_request) assert result == { - "observations": observations[25:], + "observations": observations_page, "project": project, } + assert len(observations_page.items) == 5 def test_with_invalid_page(self, db_request): project = ProjectFactory.create() diff --git a/tests/unit/api/test_simple.py b/tests/unit/api/test_simple.py index 76855a773c3f..9503ccb1b613 100644 --- a/tests/unit/api/test_simple.py +++ b/tests/unit/api/test_simple.py @@ -102,7 +102,7 @@ def test_no_results_no_serial(self, db_request, content_type, renderer_override) _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override @pytest.mark.parametrize( "content_type,renderer_override", @@ -121,7 +121,7 @@ def test_no_results_with_serial(self, db_request, content_type, renderer_overrid _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override @pytest.mark.parametrize( "content_type,renderer_override", @@ -142,7 +142,7 @@ def test_with_results_no_serial(self, db_request, content_type, renderer_overrid _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override @pytest.mark.parametrize( "content_type,renderer_override", @@ -168,7 +168,7 @@ def test_with_results_with_serial( _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override class TestSimpleDetail: @@ -210,7 +210,7 @@ def test_no_files_no_serial(self, db_request, content_type, renderer_override): _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override @pytest.mark.parametrize( "content_type,renderer_override", @@ -235,7 +235,7 @@ def test_no_files_with_serial(self, db_request, content_type, renderer_override) _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override @pytest.mark.parametrize( "content_type,renderer_override", @@ -250,8 +250,8 @@ def test_with_files_no_serial(self, db_request, content_type, renderer_override) FileFactory.create(release=r, filename=f"{project.name}-{r.version}.tar.gz") for r in releases ] - # let's assert the result is ordered by string comparison of filename - files = sorted(files, key=lambda key: key.filename) + # let's assert the result is ordered by string comparison of version, filename + files = sorted(files, key=lambda f: (parse(f.release.version), f.filename)) urls_iter = (f"/file/{f.filename}" for f in files) db_request.matchdict["name"] = project.normalized_name db_request.route_url = lambda *a, **kw: next(urls_iter) @@ -283,7 +283,7 @@ def test_with_files_no_serial(self, db_request, content_type, renderer_override) _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override @pytest.mark.parametrize( "content_type,renderer_override", @@ -331,7 +331,7 @@ def test_with_files_with_serial(self, db_request, content_type, renderer_overrid _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override @pytest.mark.parametrize( "content_type,renderer_override", @@ -424,4 +424,4 @@ def test_with_files_with_version_multi_digit( _assert_has_cors_headers(db_request.response.headers) if renderer_override is not None: - db_request.override_renderer == renderer_override + assert db_request.override_renderer == renderer_override