def test_uploader_identity_ensure_user_can_disband( uploader_identity: UploaderIdentity, user_type: str, role: str) -> None: user = TestUserTypes.get_user_by_type(user_type) if not user or not user.is_authenticated: assert uploader_identity.can_user_disband(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_disband(user) assert "Must be authenticated" in str(e.value) elif user_type == TestUserTypes.deactivated_user: assert uploader_identity.can_user_disband(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_disband(user) assert "User has been deactivated" in str(e.value) elif user_type == TestUserTypes.service_account: assert uploader_identity.can_user_disband(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_disband(user) assert "Service accounts are unable to disband teams" in str(e.value) else: if role is not None: UploaderIdentityMember.objects.create( user=user, identity=uploader_identity, role=role, ) if role != UploaderIdentityMemberRole.owner: assert uploader_identity.can_user_disband(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_disband(user) assert "Must be an owner to disband team" in str(e.value) else: assert uploader_identity.can_user_disband(user) is True uploader_identity.ensure_user_can_disband(user)
def test_uploader_identity_ensure_user_can_disband_has_packages( uploader_identity: UploaderIdentity, package: Package) -> None: member = UploaderIdentityMemberFactory( identity=uploader_identity, role=UploaderIdentityMemberRole.owner) assert uploader_identity.can_user_disband(member.user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_disband(member.user) assert "Unable to disband teams with packages" in str(e.value)