Ejemplo n.º 1
0
    def test_ValidUserGroup(self):
        validator = v.ValidUserGroup()
        with pytest.raises(formencode.Invalid):
            validator.to_python('default')
        with pytest.raises(formencode.Invalid):
            validator.to_python('.,')

        gr = fixture.create_user_group('test')
        gr2 = fixture.create_user_group('tes2')
        Session().commit()
        with pytest.raises(formencode.Invalid):
            validator.to_python('test')
        assert gr.users_group_id is not None
        validator = v.ValidUserGroup(
            edit=True, old_data={'users_group_id': gr2.users_group_id})

        with pytest.raises(formencode.Invalid):
            validator.to_python('test')
        with pytest.raises(formencode.Invalid):
            validator.to_python('TesT')
        with pytest.raises(formencode.Invalid):
            validator.to_python('TEST')
        UserGroupModel().delete(gr)
        UserGroupModel().delete(gr2)
        Session().commit()
Ejemplo n.º 2
0
    class _UserGroupForm(formencode.Schema):
        allow_extra_fields = True
        filter_extra_fields = True

        users_group_name = All(
            v.UnicodeString(strip=True, min=1, not_empty=True),
            v.ValidUserGroup(edit, old_data))
        user_group_description = v.UnicodeString(strip=True,
                                                 min=1,
                                                 not_empty=False)

        users_group_active = v.StringBoolean(if_missing=False)

        if edit:
            users_group_members = v.OneOf(available_members,
                                          hideList=False,
                                          testValueList=True,
                                          if_missing=None,
                                          not_empty=False)