test/unittest_schema.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 19 Sep 2011 14:22:28 +0200
changeset 7808 d90338624ea0
parent 7795 b8027b317d1c
child 7962 38ce8b8a980f
permissions -rw-r--r--
[security view] slight changes to make things clearer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7152
39c1ffc7d93f [schema, refactoring] use RQLExpression as base class for RQL constraint classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7147
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5179
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6117
f3fdfcbda54b cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5563
diff changeset
    18
"""unit tests for module cubicweb.schema"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6768
diff changeset
    20
from __future__ import with_statement
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6768
diff changeset
    21
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
import sys
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from os.path import join, isabs, basename, dirname
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
from rql import RQLSyntaxError
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
7640
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
    29
from yams import ValidationError, BadSchemaDefinition
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
from yams.constraints import SizeConstraint, StaticVocabularyConstraint
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
from yams.buildobjs import RelationDefinition, EntityType, RelationType
7469
f8c983afbf8e [test] update cubicweb/test/unittest_schema.py (to follow yams#.....)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7460
diff changeset
    32
from yams.reader import fill_schema
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
3978
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
    34
from cubicweb.schema import (
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
    35
    CubicWebSchema, CubicWebEntitySchema, CubicWebSchemaLoader,
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
    36
    RQLConstraint, RQLUniqueConstraint, RQLVocabularyConstraint,
3998
94cc7cad3d2d backport stable into default
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3877 3978
diff changeset
    37
    RQLExpression, ERQLExpression, RRQLExpression,
4132
440d383367eb fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
    38
    normalize_expression, order_eschemas, guess_rrqlexpr_mainvars)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
from cubicweb.devtools import TestServerConfiguration as TestConfiguration
7640
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
    40
from cubicweb.devtools.testlib import CubicWebTC
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
DATADIR = join(dirname(__file__), 'data')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
# build a dummy schema ########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
PERSONNE_PERMISSIONS =  {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
    'read':   ('managers', 'users', 'guests'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
    'update': ('managers', 'owners'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
    'add':    ('managers', ERQLExpression('X travaille S, S owned_by U')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
    'delete': ('managers', 'owners',),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
CONCERNE_PERMISSIONS = {
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
    'read':   ('managers', 'users', 'guests'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    'add':    ('managers', RRQLExpression('U has_update_permission S')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
    'delete': ('managers', RRQLExpression('O owned_by U')),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
    }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
schema = CubicWebSchema('Test Schema')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
enote = schema.add_entity_type(EntityType('Note'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
eaffaire = schema.add_entity_type(EntityType('Affaire'))
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    63
eperson = schema.add_entity_type(EntityType('Personne', __permissions__=PERSONNE_PERMISSIONS))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
esociete = schema.add_entity_type(EntityType('Societe'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
RELS = (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
    # attribute relations
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
    ('Note date String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    ('Note type String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
    ('Affaire sujet String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
    ('Affaire ref String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
    ('Personne nom String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
    ('Personne prenom String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    ('Personne sexe String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    ('Personne tel Int'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
    ('Personne fax Int'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
    ('Personne datenaiss Date'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    ('Personne promo String'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    # real relations
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    ('Personne  travaille Societe'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
    ('Personne  evaluee   Note'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    ('Societe evaluee   Note'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    ('Personne  concerne  Affaire'),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    ('Personne  concerne  Societe'),
6861
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
    85
    ('Affaire concerne  Societe'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
done = {}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
for rel in RELS:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
    _from, _type, _to = rel.split()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
    if not _type.lower() in done:
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    91
        schema.add_relation_type(RelationType(_type))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        done[_type.lower()] = True
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    93
    if _type == 'concerne':
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    94
        schema.add_relation_def(RelationDefinition(_from, _type, _to,
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    95
                                                   __permissions__=CONCERNE_PERMISSIONS))
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    96
    else:
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
    97
        schema.add_relation_def(RelationDefinition(_from, _type, _to))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
class CubicWebSchemaTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
3978
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   101
    def test_rql_constraints_inheritance(self):
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   102
        # isinstance(cstr, RQLVocabularyConstraint)
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   103
        # -> expected to return RQLVocabularyConstraint and RQLConstraint
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   104
        #   instances but not RQLUniqueConstraint
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   105
        #
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   106
        # isinstance(cstr, RQLConstraint)
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   107
        # -> expected to return RQLConstraint instances but not
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   108
        #    RRQLVocabularyConstraint and QLUniqueConstraint
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   109
        self.assertFalse(issubclass(RQLUniqueConstraint, RQLVocabularyConstraint))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   110
        self.assertFalse(issubclass(RQLUniqueConstraint, RQLConstraint))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   111
        self.assertTrue(issubclass(RQLConstraint, RQLVocabularyConstraint))
3978
2c95e3033f64 finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3899
diff changeset
   112
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
    def test_entity_perms(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
        self.assertEqual(eperson.get_groups('read'), set(('managers', 'users', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
        self.assertEqual(eperson.get_groups('update'), set(('managers', 'owners',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        self.assertEqual(eperson.get_groups('delete'), set(('managers', 'owners')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
        self.assertEqual(eperson.get_groups('add'), set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
        self.assertEqual([str(e) for e in eperson.get_rqlexprs('add')],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
                         ['Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s'])
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   120
        eperson.set_action_permissions('read', ('managers',))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
        self.assertEqual(eperson.get_groups('read'), set(('managers',)))
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   122
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
    def test_relation_perms(self):
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   124
        rconcerne = schema.rschema('concerne').rdef('Personne', 'Societe')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
        self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        self.assertEqual(rconcerne.get_groups('delete'), set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        self.assertEqual(rconcerne.get_groups('add'), set(('managers', )))
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   128
        rconcerne.set_action_permissions('read', ('managers',))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
        self.assertEqual(rconcerne.get_groups('read'), set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        self.assertEqual([str(e) for e in rconcerne.get_rqlexprs('add')],
3899
78a2c8e7eef5 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   131
                         ['Any S,U WHERE U has_update_permission S, S eid %(s)s, U eid %(u)s'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
    def test_erqlexpression(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        self.assertRaises(RQLSyntaxError, ERQLExpression, '1')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        expr = ERQLExpression('X travaille S, S owned_by U')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   136
        self.assertEqual(str(expr), 'Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   137
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
    def test_rrqlexpression(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
        self.assertRaises(Exception, RRQLExpression, '1')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
        self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
        expr = RRQLExpression('U has_update_permission O')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   142
        self.assertEqual(str(expr), 'Any O,U WHERE U has_update_permission O, O eid %(o)s, U eid %(u)s')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   143
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
loader = CubicWebSchemaLoader()
6640
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6427
diff changeset
   145
config = TestConfiguration('data', apphome=DATADIR)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
config.bootstrap_cubes()
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   147
2926
4484387ed012 when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   148
class SchemaReaderClassTest(TestCase):
4484387ed012 when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   149
4484387ed012 when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   150
    def test_order_eschemas(self):
4484387ed012 when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   151
        schema = loader.load(config)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   152
        self.assertEqual(order_eschemas([schema['Note'], schema['SubNote']]),
2926
4484387ed012 when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   153
                                         [schema['Note'], schema['SubNote']])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   154
        self.assertEqual(order_eschemas([schema['SubNote'], schema['Note']]),
2926
4484387ed012 when adding/removing cubes, we should add/remove entity types in correct order if one inherits from another
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   155
                                         [schema['Note'], schema['SubNote']])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
    def test_knownValues_load_schema(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
        schema = loader.load(config)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
        self.assert_(isinstance(schema, CubicWebSchema))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   160
        self.assertEqual(schema.name, 'data')
6415
b0b0f097a72d cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   161
        entities = sorted([str(e) for e in schema.entities()])
7460
2455cdbeadca [schema] support for BigInt type. Closes #1720995
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7459
diff changeset
   162
        expected_entities = ['BaseTransition', 'BigInt', 'Bookmark', 'Boolean', 'Bytes', 'Card',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
                             'Date', 'Datetime', 'Decimal',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 985
diff changeset
   164
                             'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 985
diff changeset
   165
                             'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation',
6306
e6557be1127e [test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6117
diff changeset
   166
                             'CWPermission', 'CWProperty', 'CWRType',
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6910
diff changeset
   167
                             'CWSource', 'CWSourceHostConfig', 'CWSourceSchemaConfig',
6306
e6557be1127e [test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6117
diff changeset
   168
                             'CWUniqueTogetherConstraint', 'CWUser',
5563
26e242ba3da5 with cw 3.9, no more Image type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   169
                             'ExternalUri', 'File', 'Float', 'Int', 'Interval', 'Note',
7426
254bc099db1a [test] update test broken by previous commit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
   170
                             'Password', 'Personne', 'Produit',
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   171
                             'RQLExpression',
7426
254bc099db1a [test] update test broken by previous commit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
   172
                             'Service', 'Societe', 'State', 'StateFull', 'String', 'SubNote', 'SubWorkflowExitPoint',
7166
dde161937d3e [time zone] support for TZDatetime and TZTime data type
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7152
diff changeset
   173
                             'Tag', 'TZDatetime', 'TZTime', 'Time', 'Transition', 'TrInfo',
7426
254bc099db1a [test] update test broken by previous commit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
   174
                             'Usine',
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   175
                             'Workflow', 'WorkflowTransition']
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6910
diff changeset
   176
        self.assertListEqual(sorted(expected_entities), entities)
6415
b0b0f097a72d cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   177
        relations = sorted([str(r) for r in schema.relations()])
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   178
        expected_relations = ['add_permission', 'address', 'alias', 'allowed_transition',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2730
diff changeset
   179
                              'bookmarked_by', 'by_transition',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
3204
0b766b8a13e1 #370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2943
diff changeset
   181
                              'cardinality', 'comment', 'comment_format',
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   182
                              'composite', 'condition', 'config', 'connait',
6306
e6557be1127e [test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6117
diff changeset
   183
                              'constrained_by', 'constraint_of',
e6557be1127e [test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6117
diff changeset
   184
                              'content', 'content_format',
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   185
                              'created_by', 'creation_date', 'cstrtype', 'custom_workflow',
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6910
diff changeset
   186
                              'cwuri', 'cw_for_source', 'cw_host_config_of', 'cw_schema', 'cw_source',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3204
diff changeset
   188
                              'data', 'data_encoding', 'data_format', 'data_name', 'default_workflow', 'defaultval', 'delete_permission',
750
89e997bc2bf1 update test for new test schema
sylvain.thenault@logilab.fr
parents: 624
diff changeset
   189
                              'description', 'description_format', 'destination_state',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   190
750
89e997bc2bf1 update test for new test schema
sylvain.thenault@logilab.fr
parents: 624
diff changeset
   191
                              'ecrit_par', 'eid', 'evaluee', 'expression', 'exprtype',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
7426
254bc099db1a [test] update test broken by previous commit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
   193
                              'fabrique_par', 'final', 'firstname', 'for_user', 'fournit',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
                              'from_entity', 'from_state', 'fulltext_container', 'fulltextindexed',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
7795
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   196
                              'has_group_permission', 'has_text',
3204
0b766b8a13e1 #370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2943
diff changeset
   197
                              'identity', 'in_group', 'in_state', 'indexed',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
                              'initial_state', 'inlined', 'internationalizable', 'is', 'is_instance_of',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
7426
254bc099db1a [test] update test broken by previous commit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7166
diff changeset
   200
                              'label', 'last_login_time', 'latest_retrieval', 'lieu', 'login',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   202
                              'mainvars', 'match_host', 'modification_date',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
750
89e997bc2bf1 update test for new test schema
sylvain.thenault@logilab.fr
parents: 624
diff changeset
   204
                              'name', 'nom',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6910
diff changeset
   206
                              'options', 'ordernum', 'owned_by',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
6957
ffda12be2e9f [repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   208
                              'parser', 'path', 'pkey', 'prefered_form', 'prenom', 'primary_email',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
6306
e6557be1127e [test] fix test broken by introduction of CWUniqueTogetherConstraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6117
diff changeset
   210
                              'read_permission', 'relation_type', 'relations', 'require_group',
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   211
7459
e4399a37674e [test,i18n] update test and i18n catalog to follow addition of 'synchronizing' attribute on sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7440
diff changeset
   212
                              'specializes', 'state_of', 'subworkflow', 'subworkflow_exit', 'subworkflow_state', 'surname', 'symmetric', 'synchronizing', 'synopsis',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
750
89e997bc2bf1 update test for new test schema
sylvain.thenault@logilab.fr
parents: 624
diff changeset
   214
                              'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
6957
ffda12be2e9f [repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   216
                              'upassword', 'update_permission', 'url', 'uri', 'use_email',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   218
                              'value',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
6768
b75f688bded7 fix unittest broken by TrInfo schema change
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6640
diff changeset
   220
                              'wf_info_for', 'wikiid', 'workflow_of', 'tr_count']
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   221
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6910
diff changeset
   222
        self.assertListEqual(sorted(expected_relations), relations)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 985
diff changeset
   224
        eschema = schema.eschema('CWUser')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
        rels = sorted(str(r) for r in eschema.subject_relations())
6427
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   226
        self.assertListEqual(rels, ['created_by', 'creation_date', 'custom_workflow',
c8a5ac2d1eaa [schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6415
diff changeset
   227
                                    'cw_source', 'cwuri', 'eid',
7795
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   228
                                    'evaluee', 'firstname', 'has_group_permission',
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   229
                                    'has_text', 'identity',
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   230
                                    'in_group', 'in_state', 'is',
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   231
                                    'is_instance_of', 'last_login_time',
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   232
                                    'login', 'modification_date', 'owned_by',
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   233
                                    'primary_email', 'surname', 'upassword',
b8027b317d1c [test] fix some tests broken since localperms cube extraction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7791
diff changeset
   234
                                    'use_email'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
        rels = sorted(r.type for r in eschema.object_relations())
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   236
        self.assertListEqual(rels, ['bookmarked_by', 'created_by', 'for_user',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
                                     'identity', 'owned_by', 'wf_info_for'])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
        rschema = schema.rschema('relation_type')
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   239
        properties = rschema.rdef('CWAttribute', 'CWRType')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   240
        self.assertEqual(properties.cardinality, '1*')
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   241
        constraints = properties.constraints
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   242
        self.assertEqual(len(constraints), 1, constraints)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   243
        constraint = constraints[0]
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   244
        self.assertTrue(isinstance(constraint, RQLConstraint))
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   245
        self.assertEqual(constraint.expression, 'O final TRUE')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   246
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
    def test_fulltext_container(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   248
        schema = loader.load(config)
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   249
        self.assertTrue('has_text' in schema['CWUser'].subject_relations())
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7642
diff changeset
   250
        self.assertFalse('has_text' in schema['EmailAddress'].subject_relations())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   251
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   252
    def test_permission_settings(self):
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   253
        schema = loader.load(config)
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   254
        aschema = schema['TrInfo'].rdef('comment')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   255
        self.assertEqual(aschema.get_groups('read'),
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   256
                          set(('managers', 'users', 'guests')))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   257
        self.assertEqual(aschema.get_rqlexprs('read'),
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   258
                          ())
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   259
        self.assertEqual(aschema.get_groups('update'),
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   260
                          set(('managers',)))
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   261
        self.assertEqual([x.expression for x in aschema.get_rqlexprs('update')],
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   262
                          ['U has_update_permission X'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
7440
539de926ec9d [test] fix failure introduced by 1719eab69551: the regexp should be fixed, not the error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7426
diff changeset
   264
    def test_nonregr_allowed_type_names(self):
539de926ec9d [test] fix failure introduced by 1719eab69551: the regexp should be fixed, not the error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7426
diff changeset
   265
        schema = CubicWebSchema('Test Schema')
539de926ec9d [test] fix failure introduced by 1719eab69551: the regexp should be fixed, not the error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7426
diff changeset
   266
        schema.add_entity_type(EntityType('NaN'))
539de926ec9d [test] fix failure introduced by 1719eab69551: the regexp should be fixed, not the error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7426
diff changeset
   267
539de926ec9d [test] fix failure introduced by 1719eab69551: the regexp should be fixed, not the error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7426
diff changeset
   268
6861
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   269
class BadSchemaTC(TestCase):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
    def setUp(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
        self.loader = CubicWebSchemaLoader()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
        self.loader.defined = {}
951
d4bb69eac55a properly init yams loader
sylvain.thenault@logilab.fr
parents: 13
diff changeset
   273
        self.loader.loaded_files = []
4469
310b5f01c982 need post_build_callbacks attribute with earlier yams version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4467
diff changeset
   274
        self.loader.post_build_callbacks = []
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
    def _test(self, schemafile, msg):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   277
        self.loader.handle_file(join(DATADIR, schemafile))
7469
f8c983afbf8e [test] update cubicweb/test/unittest_schema.py (to follow yams#.....)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7460
diff changeset
   278
        sch = self.loader.schemacls('toto')
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6768
diff changeset
   279
        with self.assertRaises(BadSchemaDefinition) as cm:
7469
f8c983afbf8e [test] update cubicweb/test/unittest_schema.py (to follow yams#.....)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7460
diff changeset
   280
            fill_schema(sch, self.loader.defined, False)
6796
e70ca9abfc51 [unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6768
diff changeset
   281
        self.assertEqual(str(cm.exception), msg)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   282
6861
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   283
    def test_lowered_etype(self):
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   284
        self._test('lowered_etype.py',
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   285
                   "'my_etype' is not a valid name for an entity type. It should "
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   286
                   "start with an upper cased letter and be followed by at least "
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   287
                   "a lower cased letter")
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   288
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   289
    def test_uppered_rtype(self):
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   290
        self._test('uppered_rtype.py',
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   291
                   "'ARelation' is not a valid name for a relation type. It should be lower cased")
9d4e11d6e783 [schema] ease understanding of schema naming error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6796
diff changeset
   292
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
    def test_rrqlexpr_on_etype(self):
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   294
        self._test('rrqlexpr_on_eetype.py',
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   295
                   "can't use RRQLExpression on ToTo, use an ERQLExpression")
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   296
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   297
    def test_erqlexpr_on_rtype(self):
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   298
        self._test('erqlexpr_on_ertype.py',
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   299
                   "can't use ERQLExpression on relation ToTo toto TuTu, use a RRQLExpression")
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   300
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
    def test_rqlexpr_on_rtype_read(self):
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   302
        self._test('rqlexpr_on_ertype_read.py',
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   303
                   "can't use rql expression for read permission of relation ToTo toto TuTu")
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1398
diff changeset
   304
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
    def test_rrqlexpr_on_attr(self):
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   306
        self._test('rrqlexpr_on_attr.py',
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   307
                   "can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
class NormalizeExpressionTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
    def test(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   313
        self.assertEqual(normalize_expression('X  bla Y,Y blur Z  ,  Z zigoulou   X '),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
                                               'X bla Y, Y blur Z, Z zigoulou X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
3877
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   316
class RQLExpressionTC(TestCase):
7ca53fc72a0a reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   317
    def test_comparison(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6306
diff changeset
   318
        self.assertEqual(ERQLExpression('X is CWUser', 'X', 0),
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   319
                          ERQLExpression('X is CWUser', 'X', 0))
6415
b0b0f097a72d cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   320
        self.assertNotEqual(ERQLExpression('X is CWUser', 'X', 0),
5179
f08943f22334 [schema] #847739: test and fix bad permission on TrInfo.comment
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4611
diff changeset
   321
                             ERQLExpression('X is CWGroup', 'X', 0))
4181
c79135c217df backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3998 4132
diff changeset
   322
4132
440d383367eb fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
   323
class GuessRrqlExprMainVarsTC(TestCase):
440d383367eb fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
   324
    def test_exists(self):
7603
1302aa6ba4da [schema / rql] fix mainvars of RRQLExpression with parens
Florent Cayré <florent.cayre@gmail.com>
parents: 7426
diff changeset
   325
        mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3, C concerns S)'))
1302aa6ba4da [schema / rql] fix mainvars of RRQLExpression with parens
Florent Cayré <florent.cayre@gmail.com>
parents: 7426
diff changeset
   326
        self.assertEqual(mainvars, set(['S', 'O']))
4132
440d383367eb fix mainvars detection bug with EXISTS (paren, actually)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3978
diff changeset
   327
4181
c79135c217df backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3998 4132
diff changeset
   328
7640
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   329
class RQLConstraintTC(CubicWebTC):
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   330
    def test_user_constraint(self):
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   331
        cstr = RQLConstraint('U identity O')
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   332
        anoneid = self.execute('Any X WHERE X login "anon"')[0][0]
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   333
        self.assertRaises(ValidationError, cstr.repo_check, self.session, 1, 'rel', anoneid)
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   334
        self.assertEqual(cstr.repo_check(self.session, 1, self.session.user.eid),
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   335
        None) # no validation error, constraint checked
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   336
85ebdbbcb321 [schema] closes #1816439: RQLConstraint does not take variable U into account
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7603
diff changeset
   337
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
    unittest_main()