[test] extend a bit add_type_restriction tests

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset91c4cbe2eeb3
branchstable
phasepublic
hiddenno
parent revision#a3ddccf19ded properly undoable stmt.add_type_restriction. Closes #176469
child revision#ef50aa5ed8ce add_type_restriction properly behave vs is_instance_of relation. Closes #176472
files modified by this revision
test/unittest_nodes.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1378896979 -7200
# Wed Sep 11 12:56:19 2013 +0200
# Branch stable
# Node ID 91c4cbe2eeb39e1075fefd7266d94f08c83d8527
# Parent a3ddccf19ded09c1614124c94536c55d612143f8
[test] extend a bit add_type_restriction tests

diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py
@@ -60,31 +60,38 @@
1      def setUp(self):
2          self.parse = helper.parse
3          self.simplify = helper.simplify
4 
5      def test_add_is_type_restriction(self):
6 -        tree = self.parse('Any X WHERE X is Person')
7 +        tree = self.parse("Any X WHERE X is Person, X name ILIKE 'A%'")
8          select = tree.children[0]
9          x = select.get_selected_variables().next()
10          self.assertRaises(RQLException, select.add_type_restriction, x.variable, 'Babar')
11          select.add_type_restriction(x.variable, 'Person')
12 -        self.assertEqual(tree.as_string(), 'Any X WHERE X is Person')
13 +        self.assertEqual(tree.as_string(), "Any X WHERE X is Person, X name ILIKE 'A%'")
14 
15      def test_add_new_is_type_restriction_in(self):
16 +        tree = self.parse("Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
17 +        select = tree.children[0]
18 +        x = select.get_selected_variables().next()
19 +        select.add_type_restriction(x.variable, 'Company')
20 +        # implementation is KISS (the IN remains)
21 +        self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Company), X name ILIKE 'A%'")
22 +
23 +    def test_add_new_is_type_restriction_in_nonregr(self):
24          tree = self.parse('Any X WHERE X is IN(Person, Company, Student)')
25          select = tree.children[0]
26          x = select.get_selected_variables().next()
27          select.add_type_restriction(x.variable, 'Person')
28 -        # implementation is KISS (the IN remains)
29          self.assertEqual(tree.as_string(), 'Any X WHERE X is IN(Person)')
30 
31      def test_add_is_in_type_restriction(self):
32 -        tree = self.parse('Any X WHERE X is IN(Person, Company)')
33 +        tree = self.parse("Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
34          select = tree.children[0]
35          x = select.get_selected_variables().next()
36          self.assertRaises(RQLException, select.add_type_restriction, x.variable, 'Babar')
37 -        self.assertEqual(tree.as_string(), 'Any X WHERE X is IN(Person, Company)')
38 +        self.assertEqual(tree.as_string(), "Any X WHERE X is IN(Person, Company), X name ILIKE 'A%'")
39 
40      # XXX a full schema is needed, see test in cw/server/test/unittest_security
41      # def test_add_is_against_isintance_type_restriction(self):
42      #     tree = self.parse('Any X WHERE X is_instance_of Person')
43      #     select = tree.children[0]