def test_uploader_identity_ensure_user_can_access( uploader_identity: UploaderIdentity, user_type: str, role: str) -> None: user = TestUserTypes.get_user_by_type(user_type) if user_type in TestUserTypes.fake_users(): assert uploader_identity.can_user_access(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_access(user) assert "Must be authenticated" in str(e.value) elif user_type == TestUserTypes.deactivated_user: assert uploader_identity.can_user_access(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_access(user) assert "User has been deactivated" in str(e.value) else: if role is not None: UploaderIdentityMember.objects.create( user=user, identity=uploader_identity, role=role, ) if role is not None: assert uploader_identity.can_user_access(user) is True assert uploader_identity.ensure_user_can_access(user) is None else: assert uploader_identity.can_user_access(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_user_can_access(user) assert "Must be a member to access team" in str(e.value)
def test_uploader_identity_ensure_can_upload_package( uploader_identity: UploaderIdentity, uploader_active: bool, user_type: str, role: str, ) -> None: uploader_identity.is_active = uploader_active uploader_identity.save(update_fields=("is_active", )) user = TestUserTypes.get_user_by_type(user_type) if user_type in TestUserTypes.fake_users(): assert uploader_identity.can_user_upload(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_can_upload_package(user) assert "Must be authenticated" in str(e.value) else: if role is not None: UploaderIdentityMember.objects.create( user=user, identity=uploader_identity, role=role, ) if role is not None: if user_type == TestUserTypes.deactivated_user: assert uploader_identity.can_user_upload(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_can_upload_package(user) assert "User has been deactivated" in str(e.value) else: if uploader_active: assert uploader_identity.can_user_upload(user) is True assert uploader_identity.ensure_user_can_access( user) is None else: assert uploader_identity.can_user_upload(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_can_upload_package(user) assert ( "The team has been deactivated and as such cannot receive new packages" in str(e.value)) else: assert uploader_identity.can_user_upload(user) is False with pytest.raises(ValidationError) as e: uploader_identity.ensure_can_upload_package(user) if user_type == TestUserTypes.deactivated_user: assert "User has been deactivated" in str(e.value) else: assert "Must be a member of identity to upload package" in str( e.value)