Skip to content

Commit

Permalink
Add missing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
twm committed Aug 6, 2024
1 parent 7087a75 commit e667984
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/unit/packaging/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
IFileStorage,
IProjectService,
ISimpleStorage,
ProjectNameUnavailableReason,
)
from warehouse.packaging.services import (
B2FileStorage,
Expand All @@ -46,6 +47,8 @@
project_service_factory,
)

from ...common.db.packaging import ProhibitedProjectFactory, ProjectFactory


class TestLocalFileStorage:
def test_verify_service(self):
Expand Down Expand Up @@ -989,6 +992,70 @@ class TestProjectService:
def test_verify_service(self):
assert verifyClass(IProjectService, ProjectService)

@pytest.mark.parametrize("name", ["", ".,;", "_z"])
def test_check_project_name_invalid(self, name):
service = ProjectService(session=pretend.stub())
request = pretend.stub()

assert (
service.check_project_name(name, request)
is ProjectNameUnavailableReason.Invalid
)

@pytest.mark.parametrize("name", ["uu", "cgi", "nis", "mailcap"])
def test_check_project_name_stdlib(self, name):
service = ProjectService(session=pretend.stub())
request = pretend.stub()

assert (
service.check_project_name(name, request)
is ProjectNameUnavailableReason.Stdlib
)

def test_check_project_name_already_exists(self, db_session):
service = ProjectService(session=db_session)
request = pretend.stub(db=db_session)
ProjectFactory.create(name="foo")

assert (
service.check_project_name("foo", request)
is ProjectNameUnavailableReason.AlreadyExists
)
assert (
service.check_project_name("Foo", request)
is ProjectNameUnavailableReason.AlreadyExists
)

def test_check_project_name_prohibited(self, db_session):
service = ProjectService(session=db_session)
request = pretend.stub(db=db_session)
ProhibitedProjectFactory.create(name="foo")

assert (
service.check_project_name("foo", request)
is ProjectNameUnavailableReason.Prohibited
)
assert (
service.check_project_name("Foo", request)
is ProjectNameUnavailableReason.Prohibited
)

def test_check_project_name_too_similar(self, db_session):
service = ProjectService(session=db_session)
request = pretend.stub(db=db_session)
ProjectFactory.create(name="f00")

assert (
service.check_project_name("foo", request)
is ProjectNameUnavailableReason.TooSimilar
)

def test_check_project_name_ok(self, db_session):
service = ProjectService(session=db_session)
request = pretend.stub(db=db_session)

assert service.check_project_name("foo", request) is None


def test_project_service_factory():
db = pretend.stub()
Expand Down

0 comments on commit e667984

Please sign in to comment.