hooks/test/unittest_hooks.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Dec 2009 18:04:57 +0100
changeset 4051 eec34250a645
parent 3536 f6c9a5df80fb
child 4055 03443dfb6fa4
permissions -rw-r--r--
move hook tests to hooks package tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
"""functional tests for core hooks
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
note: most schemahooks.py hooks are actually tested in unittest_migrations.py
1981
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
     5
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
from logilab.common.testlib import TestCase, unittest_main
2454
3648b718a0d3 add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2453
diff changeset
     9
3648b718a0d3 add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2453
diff changeset
    10
from datetime import datetime
3648b718a0d3 add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2453
diff changeset
    11
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
    12
from cubicweb import (ConnectionError, ValidationError, AuthenticationError,
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
    13
                      BadConnectionId)
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
    14
from cubicweb.devtools.testlib import CubicWebTC, get_versions
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
1251
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    16
from cubicweb.server.sqlutils import SQL_PREFIX
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    17
from cubicweb.server.repository import Repository
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
orig_get_versions = Repository.get_versions
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
def setup_module(*args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
    Repository.get_versions = get_versions
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
def teardown_module(*args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
    Repository.get_versions = orig_get_versions
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
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    28
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
    29
class CoreHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    30
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
    def test_delete_internal_entities(self):
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
    32
        self.assertRaises(ValidationError, self.execute,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
    33
                          'DELETE CWEType X WHERE X name "CWEType"')
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
    34
        self.assertRaises(ValidationError, self.execute,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
    35
                          'DELETE CWRType X WHERE X name "relation_type"')
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
    36
        self.assertRaises(ValidationError, self.execute,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
    37
                          'DELETE CWGroup X WHERE X name "owners"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    def test_delete_required_relations_subject(self):
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
    40
        self.execute('INSERT CWUser X: X login "toto", X upassword "hop", X in_group Y '
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
    41
                     'WHERE Y name "users"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
        self.execute('DELETE X in_group Y WHERE X login "toto", Y name "users"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
        self.assertRaises(ValidationError, self.commit)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        self.execute('DELETE X in_group Y WHERE X login "toto"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        self.execute('SET X in_group Y WHERE X login "toto", Y name "guests"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
        self.commit()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    48
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
    def test_delete_required_relations_object(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        self.skip('no sample in the schema ! YAGNI ? Kermaat ?')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    51
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    def test_static_vocabulary_check(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        self.assertRaises(ValidationError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
                          self.execute,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
    55
                          'SET X composite "whatever" WHERE X from_entity FE, FE name "CWUser", X relation_type RT, RT name "in_group"')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    56
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
    def test_missing_required_relations_subject_inline(self):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    58
        # missing in_group relation
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
    59
        self.execute('INSERT CWUser X: X login "toto", X upassword "hop"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        self.assertRaises(ValidationError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
                          self.commit)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
    def test_inlined(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
        self.assertEquals(self.repo.schema['sender'].inlined, True)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
                            'WHERE Y is EmailAddress, P is EmailPart')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        rset = self.execute('Any S WHERE X sender S, X eid %s' % eeid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        self.assertEquals(len(rset), 1)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    72
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
    def test_composite_1(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
                     'WHERE Y is EmailAddress, P is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
        self.failUnless(self.execute('Email X WHERE X sender Y'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
        self.execute('DELETE Email X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
        rset = self.execute('Any X WHERE X is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        self.assertEquals(len(rset), 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
        rset = self.execute('Any X WHERE X is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        self.assertEquals(len(rset), 0)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    86
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
    def test_composite_2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
                     'WHERE Y is EmailAddress, P is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        self.execute('DELETE Email X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self.execute('DELETE EmailPart X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
        rset = self.execute('Any X WHERE X is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
        self.assertEquals(len(rset), 0)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    98
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
    def test_composite_redirection(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
        self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
                     'WHERE Y is EmailAddress, P is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
        self.execute('INSERT Email X: X messageid "<2345>", X subject "test2", X sender Y, X recipients Y '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
                     'WHERE Y is EmailAddress')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        self.execute('DELETE X parts Y WHERE X messageid "<1234>"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        self.execute('SET X parts Y WHERE X messageid "<2345>"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        rset = self.execute('Any X WHERE X is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        self.assertEquals(len(rset), 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
        self.assertEquals(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
    def test_unsatisfied_constraints(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   115
        self.execute('INSERT CWRelation X: X from_entity FE, X relation_type RT, X to_entity TE '
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   116
                     'WHERE FE name "CWUser", RT name "in_group", TE name "String"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   117
        ex = self.assertRaises(ValidationError,
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   118
                               self.commit)
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   119
        self.assertEquals(str(ex), '612 (to_entity): constraint O final FALSE failed')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
    def test_html_tidy_hook(self):
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   122
        entity = self.add_entity('Workflow', name=u'wf1', description_format=u'text/html',
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   123
                                 description=u'yo')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   124
        self.assertEquals(entity.description, u'yo')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   125
        entity = self.add_entity('Workflow', name=u'wf2', description_format=u'text/html',
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   126
                                 description=u'<b>yo')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   127
        self.assertEquals(entity.description, u'<b>yo</b>')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   128
        entity = self.add_entity('Workflow', name=u'wf3', description_format=u'text/html',
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   129
                                 description=u'<b>yo</b>')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   130
        self.assertEquals(entity.description, u'<b>yo</b>')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   131
        entity = self.add_entity('Workflow', name=u'wf4', description_format=u'text/html',
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   132
                                 description=u'<b>R&D</b>')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   133
        self.assertEquals(entity.description, u'<b>R&amp;D</b>')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   134
        entity = self.add_entity('Workflow', name=u'wf5', description_format=u'text/html',
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   135
                                 description=u"<div>c&apos;est <b>l'ét&eacute;")
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   136
        self.assertEquals(entity.description, u"<div>c'est <b>l'été</b></div>")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
    def test_nonregr_html_tidy_hook_no_update(self):
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   139
        entity = self.add_entity('Workflow', name=u'wf1', description_format=u'text/html',
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   140
                                 description=u'yo')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   141
        entity.set_attributes(name=u'wf2')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   142
        self.assertEquals(entity.description, u'yo')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   143
        entity.set_attributes(description=u'R&D<p>yo')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   144
        entity.pop('description')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   145
        self.assertEquals(entity.description, u'R&amp;D<p>yo</p>')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   146
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   147
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   148
    def test_metadata_cwuri(self):
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   149
        entity = self.add_entity('Workflow', name=u'wf1')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   150
        self.assertEquals(entity.cwuri, self.repo.config['base-url'] + 'eid/%s' % entity.eid)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   151
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   152
    def test_metadata_creation_modification_date(self):
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   153
        _now = datetime.now()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   154
        entity = self.add_entity('Workflow', name=u'wf1')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   155
        self.assertEquals((entity.creation_date - _now).seconds, 0)
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   156
        self.assertEquals((entity.modification_date - _now).seconds, 0)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   157
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   158
    def test_metadata_created_by(self):
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   159
        entity = self.add_entity('Bookmark', title=u'wf1', path=u'/view')
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   160
        self.commit() # fire operations
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   161
        self.assertEquals(len(entity.created_by), 1) # make sure we have only one creator
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   162
        self.assertEquals(entity.created_by[0].eid, self.session.user.eid)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   163
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   164
    def test_metadata_owned_by(self):
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   165
        entity = self.add_entity('Bookmark', title=u'wf1', path=u'/view')
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   166
        self.commit() # fire operations
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   167
        self.assertEquals(len(entity.owned_by), 1) # make sure we have only one owner
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   168
        self.assertEquals(entity.owned_by[0].eid, self.session.user.eid)
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   169
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   170
    def test_user_login_stripped(self):
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   171
        u = self.create_user('  joe  ')
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   172
        tname = self.execute('Any L WHERE E login L, E eid %(e)s',
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   173
                             {'e': u.eid})[0][0]
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   174
        self.assertEquals(tname, 'joe')
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   175
        self.execute('SET X login " jijoe " WHERE X eid %(x)s', {'x': u.eid})
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   176
        tname = self.execute('Any L WHERE E login L, E eid %(e)s',
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   177
                             {'e': u.eid})[0][0]
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   178
        self.assertEquals(tname, 'jijoe')
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   179
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   182
class UserGroupHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   183
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
    def test_user_synchronization(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        self.create_user('toto', password='hop', commit=False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
        self.assertRaises(AuthenticationError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
                          self.repo.connect, u'toto', 'hop')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
        cnxid = self.repo.connect(u'toto', 'hop')
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   190
        self.failIfEqual(cnxid, self.session.id)
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   191
        self.execute('DELETE CWUser X WHERE X login "toto"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
        self.repo.execute(cnxid, 'State X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
        self.assertRaises(BadConnectionId,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
                          self.repo.execute, cnxid, 'State X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
    def test_user_group_synchronization(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
        user = self.session.user
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
        self.assertEquals(user.groups, set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
        self.assertEquals(user.groups, set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
        self.assertEquals(user.groups, set(('managers', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
        self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
        self.assertEquals(user.groups, set(('managers', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
        self.assertEquals(user.groups, set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
    def test_user_composite_owner(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   210
        ueid = self.create_user('toto').eid
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
        # composite of euser should be owned by the euser regardless of who created it
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
                     'WHERE U login "toto"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
        self.assertEquals(self.execute('Any A WHERE X owned_by U, U use_email X,'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
                                       'U login "toto", X address A')[0][0],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
                          'toto@logilab.fr')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   219
    def test_no_created_by_on_deleted_entity(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
        eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
        self.execute('DELETE EmailAddress X WHERE X eid %s' % eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
        self.failIf(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid}))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   224
2746
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   225
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   226
class CWPropertyHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   227
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
    def test_unexistant_eproperty(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
        ex = self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   230
                          self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
        self.assertEquals(ex.errors, {'pkey': 'unknown property key'})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   232
        ex = self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   233
                          self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
        self.assertEquals(ex.errors, {'pkey': 'unknown property key'})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   235
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
    def test_site_wide_eproperty(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
        ex = self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   238
                               self.execute, 'INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
        self.assertEquals(ex.errors, {'for_user': "site-wide property can't be set for user"})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   240
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   241
    def test_bad_type_eproperty(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   242
        ex = self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   243
                               self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   244
        self.assertEquals(ex.errors, {'value': u'unauthorized value'})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   245
        ex = self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   246
                          self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   247
        self.assertEquals(ex.errors, {'value': u'unauthorized value'})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   248
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   249
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   250
class SchemaHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   251
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
    def test_duplicate_etype_error(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   253
        # check we can't add a CWEType or CWRType entity if it already exists one
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
        # with the same name
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   255
        self.assertRaises(ValidationError,
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   256
                          self.execute, 'INSERT CWEType X: X name "CWUser"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   257
        self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   258
                          self.execute, 'INSERT CWRType X: X name "in_group"')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   259
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
    def test_validation_unique_constraint(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   261
        self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   262
                          self.execute, 'INSERT CWUser X: X login "admin"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
        try:
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   264
            self.execute('INSERT CWUser X: X login "admin"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   265
        except ValidationError, ex:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   266
            self.assertIsInstance(ex.entity, int)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
            self.assertEquals(ex.errors, {'login': 'the value "admin" is already used, use another one'})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   270
class SchemaModificationHooksTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   272
    @classmethod
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   273
    def init_config(cls, config):
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   274
        super(SchemaModificationHooksTC, cls).init_config(config)
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   275
        config._cubes = None
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   276
        cls.repo.fill_schema()
1251
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   277
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   278
    def index_exists(self, etype, attr, unique=False):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   279
        self.session.set_pool()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   280
        dbhelper = self.session.pool.source('system').dbhelper
1251
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   281
        sqlcursor = self.session.pool['system']
af40e615dc89 introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   282
        return dbhelper.index_exists(sqlcursor, SQL_PREFIX + etype, SQL_PREFIX + attr, unique=unique)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   283
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   284
    def test_base(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   285
        schema = self.repo.schema
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   286
        self.session.set_pool()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   287
        dbhelper = self.session.pool.source('system').dbhelper
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
        sqlcursor = self.session.pool['system']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   289
        self.failIf(schema.has_entity('Societe2'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   290
        self.failIf(schema.has_entity('concerne2'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   291
        # schema should be update on insertion (after commit)
2453
0faf7b5cdc71 [tests] remove some other 'meta' relation usage in tests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2251
diff changeset
   292
        self.execute('INSERT CWEType X: X name "Societe2", X description "", X final FALSE')
0faf7b5cdc71 [tests] remove some other 'meta' relation usage in tests
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2251
diff changeset
   293
        self.execute('INSERT CWRType X: X name "concerne2", X description "", X final FALSE, X symetric FALSE')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   294
        self.failIf(schema.has_entity('Societe2'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   295
        self.failIf(schema.has_entity('concerne2'))
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   296
        self.execute('SET X read_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   297
        self.execute('SET X read_permission G WHERE X is CWRType, X name "concerne2", G is CWGroup')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   298
        self.execute('SET X add_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup, G name "managers"')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   299
        self.execute('SET X add_permission G WHERE X is CWRType, X name "concerne2", G is CWGroup, G name "managers"')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   300
        self.execute('SET X delete_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup, G name "owners"')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   301
        self.execute('SET X delete_permission G WHERE X is CWRType, X name "concerne2", G is CWGroup, G name "owners"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
        # have to commit before adding definition relations
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
        self.failUnless(schema.has_entity('Societe2'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
        self.failUnless(schema.has_relation('concerne2'))
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   306
        self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval "noname", X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   307
                     'WHERE RT name "name", E name "Societe2", F name "String"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
        concerne2_rdef_eid = self.execute(
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   309
            'INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E '
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
            'WHERE RT name "concerne2", E name "Societe2"')[0][0]
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   311
        self.failIf('name' in schema['Societe2'].subject_relations())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
        self.failIf('concerne2' in schema['Societe2'].subject_relations())
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   313
        self.failIf(self.index_exists('Societe2', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
        self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   315
        self.failUnless('name' in schema['Societe2'].subject_relations())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
        self.failUnless('concerne2' in schema['Societe2'].subject_relations())
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   317
        self.failUnless(self.index_exists('Societe2', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   318
        # now we should be able to insert and query Societe2
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   319
        s2eid = self.execute('INSERT Societe2 X: X name "logilab"')[0][0]
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   320
        self.execute('Societe2 X WHERE X name "logilab"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   321
        self.execute('SET X concerne2 X WHERE X name "logilab"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
        rset = self.execute('Any X WHERE X concerne2 Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
        self.assertEquals(rset.rows, [[s2eid]])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
        # check that when a relation definition is deleted, existing relations are deleted
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   325
        self.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, X from_entity E, X to_entity E '
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   326
                     'WHERE RT name "concerne2", E name "CWUser"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
        self.commit()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   328
        self.execute('DELETE CWRelation X WHERE X eid %(x)s', {'x': concerne2_rdef_eid}, 'x')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
        self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   330
        self.failUnless('concerne2' in schema['CWUser'].subject_relations())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
        self.failIf('concerne2' in schema['Societe2'].subject_relations())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
        self.failIf(self.execute('Any X WHERE X concerne2 Y'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
        # schema should be cleaned on delete (after commit)
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   334
        self.execute('DELETE CWEType X WHERE X name "Societe2"')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   335
        self.execute('DELETE CWRType X WHERE X name "concerne2"')
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   336
        self.failUnless(self.index_exists('Societe2', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
        self.failUnless(schema.has_entity('Societe2'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   338
        self.failUnless(schema.has_relation('concerne2'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   339
        self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   340
        self.failIf(self.index_exists('Societe2', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   341
        self.failIf(schema.has_entity('Societe2'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
        self.failIf(schema.has_entity('concerne2'))
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   343
        self.failIf('concerne2' in schema['CWUser'].subject_relations())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   345
    def test_is_instance_of_insertions(self):
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   346
        seid = self.execute('INSERT Transition T: T name "subdiv"')[0][0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
        is_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is ET, ET name ETN' % seid)]
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   348
        self.assertEquals(is_etypes, ['Transition'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
        instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)]
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   350
        self.assertEquals(sorted(instanceof_etypes), ['BaseTransition', 'Transition'])
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   351
        snames = [name for name, in self.execute('Any N WHERE S is BaseTransition, S name N')]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
        self.failIf('subdiv' in snames)
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   353
        snames = [name for name, in self.execute('Any N WHERE S is_instance_of BaseTransition, S name N')]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
        self.failUnless('subdiv' in snames)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   355
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   356
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   357
    def test_perms_synchronization_1(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   358
        schema = self.repo.schema
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   359
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users')))
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   360
        self.failUnless(self.execute('Any X, Y WHERE X is CWEType, X name "CWUser", Y is CWGroup, Y name "users"')[0])
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   361
        self.execute('DELETE X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   362
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users', )))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
        self.commit()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   364
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', )))
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   365
        self.execute('SET X read_permission Y WHERE X is CWEType, X name "CWUser", Y name "users"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
        self.commit()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   367
        self.assertEquals(schema['CWUser'].get_groups('read'), set(('managers', 'users',)))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
    def test_perms_synchronization_2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
        schema = self.repo.schema['in_group']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests')))
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   372
        self.execute('DELETE X read_permission Y WHERE X is CWRType, X name "in_group", Y name "guests"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   373
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   374
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users')))
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   376
        self.execute('SET X read_permission Y WHERE X is CWRType, X name "in_group", Y name "guests"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
        self.assertEquals(schema.get_groups('read'), set(('managers', 'users', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
    def test_nonregr_user_edit_itself(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   382
        ueid = self.session.user.eid
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   383
        groupeids = [eid for eid, in self.execute('CWGroup G WHERE G name in ("managers", "users")')]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   384
        self.execute('DELETE X in_group Y WHERE X eid %s' % ueid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   385
        self.execute('SET X surname "toto" WHERE X eid %s' % ueid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   386
        self.execute('SET X in_group Y WHERE X eid %s, Y name "managers"' % ueid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   387
        self.commit()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   388
        eeid = self.execute('Any X WHERE X is CWEType, X name "CWEType"')[0][0]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   389
        self.execute('DELETE X read_permission Y WHERE X eid %s' % eeid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   390
        self.execute('SET X final FALSE WHERE X eid %s' % eeid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
        self.execute('SET X read_permission Y WHERE X eid %s, Y eid in (%s, %s)'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
                     % (eeid, groupeids[0], groupeids[1]))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   393
        self.commit()
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   394
        self.execute('Any X WHERE X is CWEType, X name "CWEType"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   395
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   396
    # schema modification hooks tests #########################################
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   397
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   398
    def test_uninline_relation(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   399
        self.session.set_pool()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   400
        dbhelper = self.session.pool.source('system').dbhelper
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   401
        sqlcursor = self.session.pool['system']
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   402
        self.failUnless(self.schema['state_of'].inlined)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   403
        try:
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   404
            self.execute('SET X inlined FALSE WHERE X name "state_of"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   405
            self.failUnless(self.schema['state_of'].inlined)
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   406
            self.commit()
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   407
            self.failIf(self.schema['state_of'].inlined)
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   408
            self.failIf(self.index_exists('State', 'state_of'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   409
            rset = self.execute('Any X, Y WHERE X state_of Y')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   410
            self.assertEquals(len(rset), 2) # user states
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   411
        finally:
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   412
            self.execute('SET X inlined TRUE WHERE X name "state_of"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   413
            self.failIf(self.schema['state_of'].inlined)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
            self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   415
            self.failUnless(self.schema['state_of'].inlined)
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   416
            self.failUnless(self.index_exists('State', 'state_of'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   417
            rset = self.execute('Any X, Y WHERE X state_of Y')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   418
            self.assertEquals(len(rset), 2)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   419
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   420
    def test_indexed_change(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   421
        self.session.set_pool()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   422
        dbhelper = self.session.pool.source('system').dbhelper
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   423
        sqlcursor = self.session.pool['system']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
        try:
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   425
            self.execute('SET X indexed FALSE WHERE X relation_type R, R name "name"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   426
            self.failUnless(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   427
            self.failUnless(self.index_exists('Workflow', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   428
            self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   429
            self.failIf(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   430
            self.failIf(self.index_exists('Workflow', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   431
        finally:
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   432
            self.execute('SET X indexed TRUE WHERE X relation_type R, R name "name"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   433
            self.failIf(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   434
            self.failIf(self.index_exists('Workflow', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   435
            self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   436
            self.failUnless(self.schema['name'].rproperty('Workflow', 'String', 'indexed'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   437
            self.failUnless(self.index_exists('Workflow', 'name'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   438
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   439
    def test_unique_change(self):
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   440
        self.session.set_pool()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   441
        dbhelper = self.session.pool.source('system').dbhelper
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   442
        sqlcursor = self.session.pool['system']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   443
        try:
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   444
            self.execute('INSERT CWConstraint X: X cstrtype CT, DEF constrained_by X '
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   445
                         'WHERE CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,'
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   446
                         'RT name "name", E name "Workflow"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   447
            self.failIf(self.schema['Workflow'].has_unique_values('name'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   448
            self.failIf(self.index_exists('Workflow', 'name', unique=True))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   449
            self.commit()
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   450
            self.failUnless(self.schema['Workflow'].has_unique_values('name'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   451
            self.failUnless(self.index_exists('Workflow', 'name', unique=True))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   452
        finally:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
            self.execute('DELETE DEF constrained_by X WHERE X cstrtype CT, '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
                         'CT name "UniqueConstraint", DEF relation_type RT, DEF from_entity E,'
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   455
                         'RT name "name", E name "Workflow"')
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   456
            self.failUnless(self.schema['Workflow'].has_unique_values('name'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   457
            self.failUnless(self.index_exists('Workflow', 'name', unique=True))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   458
            self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   459
            self.failIf(self.schema['Workflow'].has_unique_values('name'))
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   460
            self.failIf(self.index_exists('Workflow', 'name', unique=True))
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   461
1981
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   462
    def test_required_change_1(self):
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   463
        self.execute('SET DEF cardinality "?1" '
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   464
                     'WHERE DEF relation_type RT, DEF from_entity E,'
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   465
                     'RT name "title", E name "Bookmark"')
1981
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   466
        self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   467
        # should now be able to add bookmark without title
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   468
        self.execute('INSERT Bookmark X: X path "/view"')
1981
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   469
        self.commit()
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   470
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   471
    def test_required_change_2(self):
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   472
        self.execute('SET DEF cardinality "11" '
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   473
                     'WHERE DEF relation_type RT, DEF from_entity E,'
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   474
                     'RT name "surname", E name "CWUser"')
1981
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   475
        self.commit()
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   476
        # should not be able anymore to add cwuser without surname
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   477
        self.assertRaises(ValidationError, self.create_user, "toto")
2251
799ff50ddfe8 fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1990
diff changeset
   478
        self.execute('SET DEF cardinality "?1" '
799ff50ddfe8 fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1990
diff changeset
   479
                     'WHERE DEF relation_type RT, DEF from_entity E,'
3431
6944a92c16f2 move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   480
                     'RT name "surname", E name "CWUser"')
2251
799ff50ddfe8 fix tests to avoid schema copy, pytest unittest_migration.py OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1990
diff changeset
   481
        self.commit()
1981
e6eed4324357 fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1787
diff changeset
   482
3526
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   483
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   484
    def test_add_attribute_to_base_class(self):
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   485
        self.execute('INSERT CWAttribute X: X cardinality "11", X defaultval "noname", X indexed TRUE, X relation_type RT, X from_entity E, X to_entity F '
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   486
                     'WHERE RT name "nom", E name "BaseTransition", F name "String"')
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   487
        self.commit()
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   488
        self.schema.rebuild_infered_relations()
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   489
        self.failUnless('Transition' in self.schema['nom'].subjects())
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   490
        self.failUnless('WorkflowTransition' in self.schema['nom'].subjects())
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   491
        self.execute('Any X WHERE X is_instance_of BaseTransition, X nom "hop"')
dfb2ebb765e2 [migration] fix addition of attribute to a parent class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2923
diff changeset
   492
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   494
    unittest_main()