hooks/test/unittest_hooks.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Mar 2010 20:32:10 +0100
changeset 5028 261add0b946c
parent 4689 4eb1f4490538
child 5030 5238d9a8dfee
permissions -rw-r--r--
...
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
4689
4eb1f4490538 [test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4667
diff changeset
    12
from cubicweb import ValidationError, AuthenticationError, BadConnectionId
4eb1f4490538 [test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4667
diff changeset
    13
from cubicweb.devtools.testlib import CubicWebTC
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    14
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
    15
class CoreHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    16
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
    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
    18
        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
    19
                          '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
    20
        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
    21
                          '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
    22
        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
    23
                          'DELETE CWGroup X WHERE X name "owners"')
0
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
    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
    26
        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
    27
                     'WHERE Y name "users"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
        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
    30
        self.assertRaises(ValidationError, self.commit)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        self.execute('DELETE X in_group Y WHERE X login "toto"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
        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
    33
        self.commit()
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    34
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    def test_delete_required_relations_object(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
        self.skip('no sample in the schema ! YAGNI ? Kermaat ?')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    37
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    def test_static_vocabulary_check(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        self.assertRaises(ValidationError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
                          self.execute,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
    41
                          '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
    42
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    def test_missing_required_relations_subject_inline(self):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    44
        # 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
    45
        self.execute('INSERT CWUser X: X login "toto", X upassword "hop"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        self.assertRaises(ValidationError,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
                          self.commit)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
    def test_inlined(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        self.assertEquals(self.repo.schema['sender'].inlined, True)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
        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
    52
        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
    53
        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
    54
                            'WHERE Y is EmailAddress, P is EmailPart')[0][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
        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
    56
        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
    57
        self.assertEquals(len(rset), 1)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    58
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    def test_composite_1(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        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
    61
        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
    62
        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
    63
                     'WHERE Y is EmailAddress, P is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
        self.failUnless(self.execute('Email X WHERE X sender Y'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        self.execute('DELETE Email X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        rset = self.execute('Any X WHERE X is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        self.assertEquals(len(rset), 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        rset = self.execute('Any X WHERE X is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        self.assertEquals(len(rset), 0)
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_2(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.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        self.execute('DELETE Email X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
        self.execute('DELETE EmailPart X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        rset = self.execute('Any X WHERE X is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
        self.assertEquals(len(rset), 0)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    84
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
    def test_composite_redirection(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
        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
    87
        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
    88
        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
    89
                     'WHERE Y is EmailAddress, P is EmailPart')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        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
    91
                     'WHERE Y is EmailAddress')
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 X parts Y WHERE X messageid "<1234>"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self.execute('SET X parts Y WHERE X messageid "<2345>"')
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), 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
        self.assertEquals(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
    def test_unsatisfied_constraints(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   101
        releid = self.execute('INSERT CWRelation X: X from_entity FE, X relation_type RT, X to_entity TE '
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   102
                              'WHERE FE name "CWUser", RT name "in_group", TE name "String"')[0][0]
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   103
        self.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"',
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   104
                     {'x': releid}, 'x')
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
   105
        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
   106
                               self.commit)
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   107
        self.assertEquals(ex.errors, {'to_entity': 'RQLConstraint O final FALSE failed'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
    def test_html_tidy_hook(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   110
        req = self.request()
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   111
        entity = req.create_entity('Workflow', name=u'wf1', description_format=u'text/html',
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
   112
                                 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
   113
        self.assertEquals(entity.description, u'yo')
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   114
        entity = req.create_entity('Workflow', name=u'wf2', description_format=u'text/html',
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
   115
                                 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
   116
        self.assertEquals(entity.description, u'<b>yo</b>')
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   117
        entity = req.create_entity('Workflow', name=u'wf3', description_format=u'text/html',
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
   118
                                 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
   119
        self.assertEquals(entity.description, u'<b>yo</b>')
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   120
        entity = req.create_entity('Workflow', name=u'wf4', description_format=u'text/html',
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
   121
                                 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
   122
        self.assertEquals(entity.description, u'<b>R&amp;D</b>')
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   123
        entity = req.create_entity('Workflow', name=u'wf5', description_format=u'text/html',
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
   124
                                 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
   125
        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
   126
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
    def test_nonregr_html_tidy_hook_no_update(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   128
        entity = self.request().create_entity('Workflow', name=u'wf1', description_format=u'text/html',
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
   129
                                 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
   130
        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
   131
        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
   132
        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
   133
        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
   134
        self.assertEquals(entity.description, u'R&amp;D<p>yo</p>')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   135
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   136
2921
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   137
    def test_metadata_cwuri(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   138
        entity = self.request().create_entity('Workflow', name=u'wf1')
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
        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
   140
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   141
    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
   142
        _now = datetime.now()
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   143
        entity = self.request().create_entity('Workflow', name=u'wf1')
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
   144
        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
   145
        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
   146
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   147
    def test_metadata_created_by(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   148
        entity = self.request().create_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
   149
        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
   150
        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
   151
        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
   152
8e2544e78a5e test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   153
    def test_metadata_owned_by(self):
4055
03443dfb6fa4 test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4051
diff changeset
   154
        entity = self.request().create_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
   155
        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
   156
        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
   157
        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
   158
4051
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   159
    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
   160
        u = self.create_user('  joe  ')
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   161
        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
   162
                             {'e': u.eid})[0][0]
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   163
        self.assertEquals(tname, 'joe')
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   164
        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
   165
        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
   166
                             {'e': u.eid})[0][0]
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   167
        self.assertEquals(tname, 'jijoe')
eec34250a645 move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3536
diff changeset
   168
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   171
class UserGroupHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   172
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    def test_user_synchronization(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
        self.create_user('toto', password='hop', commit=False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
        self.assertRaises(AuthenticationError,
4067
c49fba955a9c password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4055
diff changeset
   176
                          self.repo.connect, u'toto', password='hop')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
        self.commit()
4067
c49fba955a9c password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4055
diff changeset
   178
        cnxid = self.repo.connect(u'toto', password='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
   179
        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
   180
        self.execute('DELETE CWUser X WHERE X login "toto"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
        self.repo.execute(cnxid, 'State X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
        self.assertRaises(BadConnectionId,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
                          self.repo.execute, cnxid, 'State X')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
    def test_user_group_synchronization(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        user = self.session.user
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
        self.assertEquals(user.groups, set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   189
        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
   190
        self.assertEquals(user.groups, set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
        self.assertEquals(user.groups, set(('managers', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
        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
   194
        self.assertEquals(user.groups, set(('managers', 'guests')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   195
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
        self.assertEquals(user.groups, set(('managers',)))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   198
    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
   199
        ueid = self.create_user('toto').eid
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        # 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
   201
        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
   202
                     'WHERE U login "toto"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   203
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
        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
   205
                                       'U login "toto", X address A')[0][0],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
                          'toto@logilab.fr')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
    def test_no_created_by_on_deleted_entity(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
        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
   210
        self.execute('DELETE EmailAddress X WHERE X eid %s' % eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
        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
   213
2746
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   214
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   215
class CWPropertyHooksTC(CubicWebTC):
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   216
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
    def test_unexistant_eproperty(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
        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
   219
                          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
   220
        self.assertEquals(ex.errors, {'pkey': 'unknown property key'})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
        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
   222
                          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
   223
        self.assertEquals(ex.errors, {'pkey': 'unknown property key'})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   224
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   225
    def test_site_wide_eproperty(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
        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
   227
                               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
   228
        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
   229
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   230
    def test_bad_type_eproperty(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
        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
   232
                               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
   233
        self.assertEquals(ex.errors, {'value': u'unauthorized value'})
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   234
        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
   235
                          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
   236
        self.assertEquals(ex.errors, {'value': u'unauthorized value'})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   237
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   238
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2746
diff changeset
   239
class SchemaHooksTC(CubicWebTC):
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_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
   242
        # 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
   243
        # 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
   244
        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
   245
                          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
   246
        self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   247
                          self.execute, 'INSERT CWRType X: X name "in_group"')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   248
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   249
    def test_validation_unique_constraint(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   250
        self.assertRaises(ValidationError,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   251
                          self.execute, 'INSERT CWUser X: X login "admin"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   252
        try:
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1251
diff changeset
   253
            self.execute('INSERT CWUser X: X login "admin"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
        except ValidationError, ex:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
            self.assertIsInstance(ex.entity, int)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
            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
   257
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   259
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   260
    unittest_main()