web/test/unittest_facet.py
author Rémi Cardona <remi.cardona@logilab.fr>
Fri, 18 Sep 2015 11:58:29 +0200
changeset 10707 3f4f190f8e35
parent 10656 0b1d03f07b87
permissions -rw-r--r--
[py3k] unicode → six.text_type
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7615
e5ad51352eb3 [facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7612
diff changeset
     1
from logilab.common.date import datetime2ticks
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
from cubicweb.devtools.testlib import CubicWebTC
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
from cubicweb.web import facet
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
class BaseFacetTC(CubicWebTC):
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
     7
    def prepare_rqlst(self, req, rql='CWUser X', mainvar='X',
8023
047e62cddee0 [test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7874
diff changeset
     8
                      expected_baserql='Any X WHERE X is CWUser',
047e62cddee0 [test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7874
diff changeset
     9
                      expected_preparedrql='DISTINCT Any  WHERE X is CWUser'):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    10
        rset = req.cnx.execute(rql)
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
        rqlst = rset.syntax_tree().copy()
7624
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
    12
        filtered_variable, baserql = facet.init_facets(rset, rqlst.children[0],
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
    13
                                                       mainvar=mainvar)
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
    14
        self.assertEqual(filtered_variable.name, mainvar)
8023
047e62cddee0 [test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7874
diff changeset
    15
        self.assertEqual(baserql, expected_baserql)
047e62cddee0 [test, facets] fix prepare_rqlst arguments, it wasn't actually testing baserql due to name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7874
diff changeset
    16
        self.assertEqual(rqlst.as_string(), expected_preparedrql)
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    17
        return rset, rqlst, filtered_variable
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    19
    def _in_group_facet(self, req, cls=facet.RelationFacet, no_relation=False):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    20
        rset, rqlst, filtered_variable = self.prepare_rqlst(req)
6380
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    21
        cls.no_relation = no_relation
7605
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7601
diff changeset
    22
        f = cls(req, rset=rset, select=rqlst.children[0],
48abeac162fd [facets] refactor / cleanup facet api: more consistent variable naming and easier to reuse function. Closes #1796804
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7601
diff changeset
    23
                filtered_variable=filtered_variable)
6380
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    24
        f.__regid__ = 'in_group'
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
        f.rtype = 'in_group'
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
        f.role = 'subject'
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
        f.target_attr = 'name'
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    28
        guests, managers = [eid for eid, in req.cnx.execute('CWGroup G ORDERBY GN '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    29
                                                            'WHERE G name GN, G name IN ("guests", "managers")')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    30
        groups = [eid for eid, in req.cnx.execute('CWGroup G ORDERBY GN '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    31
                                                  'WHERE G name GN, G name IN ("guests", "managers")')]
6380
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    32
        return f, groups
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    33
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    34
    def test_relation_simple(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    35
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    36
            f, (guests, managers) = self._in_group_facet(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    37
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    38
                          [(u'guests', guests), (u'managers', managers)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    39
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    40
            self.assertEqual(f.select.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    41
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    42
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    43
                              [str(guests), str(managers)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    44
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    45
            self.assertEqual(f.select.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    46
            f._cw.form[f.__regid__] = str(guests)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    47
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    48
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    49
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    50
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    51
                             'DISTINCT Any  WHERE X is CWUser, X in_group D, D eid %s' % guests)
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
7768
bd44f506ca86 closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7629
diff changeset
    53
    def test_relation_multiple_and(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    54
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    55
            f, (guests, managers) = self._in_group_facet(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    56
            f._cw.form[f.__regid__] = [str(guests), str(managers)]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    57
            f._cw.form[f.__regid__ + '_andor'] = 'AND'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    58
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    59
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    60
                             'DISTINCT Any  WHERE X is CWUser, X in_group A, B eid %s, X in_group B, A eid %s' % (guests, managers))
7768
bd44f506ca86 closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7629
diff changeset
    61
bd44f506ca86 closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7629
diff changeset
    62
    def test_relation_multiple_or(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    63
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    64
            f, (guests, managers) = self._in_group_facet(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    65
            f._cw.form[f.__regid__] = [str(guests), str(managers)]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    66
            f._cw.form[f.__regid__ + '_andor'] = 'OR'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    67
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    68
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    69
                             'DISTINCT Any  WHERE X is CWUser, X in_group A, A eid IN(%s, %s)' % (guests, managers))
7768
bd44f506ca86 closes #1914824: fix retrieval of _andor input, test and fix generated rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7629
diff changeset
    70
6338
b520b86113e3 add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6119
diff changeset
    71
    def test_relation_optional_rel(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    72
        with self.admin_access.web_request() as req:
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
    73
            rset = req.cnx.execute(u'Any X,GROUP_CONCAT(GN) GROUPBY X '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
    74
                                    'WHERE X in_group G?, G name GN, NOT G name "users"')
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    75
            rqlst = rset.syntax_tree().copy()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    76
            select = rqlst.children[0]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    77
            filtered_variable, baserql = facet.init_facets(rset, select)
6338
b520b86113e3 add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6119
diff changeset
    78
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    79
            f = facet.RelationFacet(req, rset=rset,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    80
                                    select=select,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    81
                                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    82
            f.rtype = 'in_group'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    83
            f.role = 'subject'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    84
            f.target_attr = 'name'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    85
            guests, managers = [eid for eid, in req.cnx.execute('CWGroup G ORDERBY GN '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    86
                                                                'WHERE G name GN, G name IN ("guests", "managers")')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    87
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    88
                             [(u'guests', guests), (u'managers', managers)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    89
            # ensure rqlst is left unmodified
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
    90
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users"')
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    91
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    92
            self.assertEqual(sorted(f.possible_values()),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    93
                             [str(guests), str(managers)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    94
            # ensure rqlst is left unmodified
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
    95
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users"')
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    96
            req.form[f.__regid__] = str(guests)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    97
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    98
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    99
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   100
            self.assertEqual(f.select.as_string(),
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   101
                             'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users", X in_group D, D eid %s' % guests)
6338
b520b86113e3 add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6119
diff changeset
   102
6380
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   103
    def test_relation_no_relation_1(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   104
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   105
            f, (guests, managers) = self._in_group_facet(req, no_relation=True)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   106
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   107
                              [(u'guests', guests), (u'managers', managers)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   108
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   109
                              [str(guests), str(managers)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   110
            f._cw.create_entity('CWUser', login=u'hop', upassword='toto')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   111
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   112
                              [(u'<no relation>', ''), (u'guests', guests), (u'managers', managers)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   113
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   114
                              [str(guests), str(managers), ''])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   115
            f._cw.form[f.__regid__] = ''
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   116
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   117
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   118
                              'DISTINCT Any  WHERE X is CWUser, NOT X in_group G')
6380
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   119
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   120
    def test_relation_no_relation_2(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   121
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   122
            f, (guests, managers) = self._in_group_facet(req, no_relation=True)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   123
            f._cw.form[f.__regid__] = ['', guests]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   124
            f.select.save_state()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   125
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   126
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   127
                              'DISTINCT Any  WHERE X is CWUser, (NOT X in_group B) OR (X in_group A, A eid %s)' % guests)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   128
            f.select.recover()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   129
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   130
                              'DISTINCT Any  WHERE X is CWUser')
6380
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   131
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
    def test_relationattribute(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   133
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   134
            f, (guests, managers) = self._in_group_facet(req, cls=facet.RelationAttributeFacet)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   135
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   136
                              [(u'guests', u'guests'), (u'managers', u'managers')])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   137
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   138
            self.assertEqual(f.select.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   139
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   140
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   141
                              ['guests', 'managers'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   142
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   143
            self.assertEqual(f.select.as_string(), 'DISTINCT Any  WHERE X is CWUser')
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   144
            f._cw.form[f.__regid__] = u'guests'
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   145
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   146
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   147
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   148
            self.assertEqual(f.select.as_string(),
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   149
                             'DISTINCT Any  WHERE X is CWUser, X in_group E, E name "guests"')
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
10307
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   151
    def test_hasrelation(self):
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   152
        with self.admin_access.web_request() as req:
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   153
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   154
            f = facet.HasRelationFacet(req, rset=rset,
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   155
                                       select=rqlst.children[0],
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   156
                                       filtered_variable=filtered_variable)
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   157
            f.__regid__ = 'has_group'
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   158
            f.rtype = 'in_group'
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   159
            f.role = 'subject'
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   160
            f._cw.form[f.__regid__] = 'feed me'
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   161
            f.add_rql_restrictions()
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   162
            self.assertEqual(f.select.as_string(),
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   163
                             'DISTINCT Any  WHERE X is CWUser, EXISTS(X in_group A)')
4b8253fb3125 [web/facet] Use an Exists node in HasRelationFacet
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9645
diff changeset
   164
7615
e5ad51352eb3 [facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7612
diff changeset
   165
    def test_daterange(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   166
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   167
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   168
            f = facet.DateRangeFacet(req, rset=rset,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   169
                                     select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   170
                                     filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   171
            f.rtype = 'creation_date'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   172
            mind, maxd = req.cnx.execute('Any MIN(CD), MAX(CD) WHERE X is CWUser, X creation_date CD')[0]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   173
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   174
                              [(str(mind), mind),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   175
                               (str(maxd), maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   176
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   177
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   178
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   179
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   180
                             [str(mind), str(maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   181
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   182
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   183
            req.form['%s_inf' % f.__regid__] = str(datetime2ticks(mind))
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   184
            req.form['%s_sup' % f.__regid__] = str(datetime2ticks(mind))
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   185
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   186
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   187
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   188
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   189
                              'DISTINCT Any  WHERE X is CWUser, X creation_date >= "%s", '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   190
                             'X creation_date <= "%s"'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   191
                             % (mind.strftime('%Y/%m/%d'),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   192
                                mind.strftime('%Y/%m/%d')))
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   193
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   194
    def test_attribute(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   195
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   196
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   197
            f = facet.AttributeFacet(req, rset=rset,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   198
                                     select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   199
                                     filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   200
            f.rtype = 'login'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   201
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   202
                              [(u'admin', u'admin'), (u'anon', u'anon')])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   203
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   204
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   205
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   206
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   207
                              ['admin', 'anon'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   208
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   209
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   210
            req.form[f.__regid__] = u'admin'
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   211
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   212
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   213
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   214
            self.assertEqual(f.select.as_string(),
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   215
                             'DISTINCT Any  WHERE X is CWUser, X login "admin"')
6433
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   216
8029
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8023
diff changeset
   217
    def test_bitfield(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   218
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   219
            rset, rqlst, filtered_variable = self.prepare_rqlst(req,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   220
                'CWAttribute X WHERE X ordernum XO',
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   221
                expected_baserql='Any X WHERE X ordernum XO, X is CWAttribute',
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   222
                expected_preparedrql='DISTINCT Any  WHERE X ordernum XO, X is CWAttribute')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   223
            f = facet.BitFieldFacet(req, rset=rset,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   224
                                    select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   225
                                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   226
            f.choices = [('un', 1,), ('deux', 2,)]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   227
            f.rtype = 'ordernum'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   228
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   229
                              [(u'deux', 2), (u'un', 1)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   230
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   231
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X ordernum XO, X is CWAttribute')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   232
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   233
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   234
                              ['2', '1'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   235
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   236
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X ordernum XO, X is CWAttribute')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   237
            req.form[f.__regid__] = '3'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   238
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   239
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   240
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   241
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   242
                              "DISTINCT Any  WHERE X ordernum XO, X is CWAttribute, X ordernum C HAVING 3 = (C & 3)")
8029
805d4e121b65 [ui lib] facet and form widget for Integer used to store binary mask. Closes #2054771
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8023
diff changeset
   243
8598
95b3792a8947 [facet] make BitFieldFacet allow special 0 value. Closes #2522697
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8029
diff changeset
   244
    def test_bitfield_0_value(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   245
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   246
            rset, rqlst, filtered_variable = self.prepare_rqlst(req,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   247
                'CWAttribute X WHERE X ordernum XO',
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   248
                expected_baserql='Any X WHERE X ordernum XO, X is CWAttribute',
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   249
                expected_preparedrql='DISTINCT Any  WHERE X ordernum XO, X is CWAttribute')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   250
            f = facet.BitFieldFacet(req, rset=rset,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   251
                                    select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   252
                                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   253
            f.choices = [('zero', 0,), ('un', 1,), ('deux', 2,)]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   254
            f.rtype = 'ordernum'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   255
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   256
                              [(u'deux', 2), (u'un', 1), (u'zero', 0)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   257
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   258
                              ['2', '1', '0'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   259
            req.form[f.__regid__] = '0'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   260
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   261
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   262
                              "DISTINCT Any  WHERE X ordernum XO, X is CWAttribute, X ordernum C HAVING 0 = C")
8598
95b3792a8947 [facet] make BitFieldFacet allow special 0 value. Closes #2522697
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8029
diff changeset
   263
7618
5395007c415c [facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7615
diff changeset
   264
    def test_rql_path_eid(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   265
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   266
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   267
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   268
                path = [('X created_by U'), ('U owned_by O'), ('O login OL')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   269
                filter_variable = 'O'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   270
                label_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   271
            f = RPF(req, rset=rset, select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   272
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   273
            self.assertEqual(f.vocabulary(), [(u'admin', req.user.eid),])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   274
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   275
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   276
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   277
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   278
                             [str(req.user.eid),])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   279
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   280
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   281
            req.form[f.__regid__] = '1'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   282
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   283
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   284
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   285
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   286
                             "DISTINCT Any  WHERE X is CWUser, X created_by F, F owned_by G, G eid 1")
7618
5395007c415c [facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7615
diff changeset
   287
7874
be04706eacc9 [facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7768
diff changeset
   288
    def test_rql_path_eid_no_label(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   289
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   290
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   291
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   292
                path = [('X created_by U'), ('U owned_by O'), ('O login OL')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   293
                filter_variable = 'O'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   294
            f = RPF(req, rset=rset, select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   295
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   296
            self.assertEqual(f.vocabulary(), [(str(req.user.eid), req.user.eid),])
7874
be04706eacc9 [facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7768
diff changeset
   297
7618
5395007c415c [facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7615
diff changeset
   298
    def test_rql_path_attr(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   299
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   300
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   301
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   302
                path = [('X created_by U'), ('U owned_by O'), ('O login OL')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   303
                filter_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   304
            f = RPF(req, rset=rset, select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   305
                    filtered_variable=filtered_variable)
7618
5395007c415c [facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7615
diff changeset
   306
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   307
            self.assertEqual(f.vocabulary(), [(u'admin', 'admin'),])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   308
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   309
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   310
            self.assertEqual(f.possible_values(), ['admin',])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   311
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   312
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   313
            req.form[f.__regid__] = u'admin'
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   314
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   315
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   316
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   317
            self.assertEqual(f.select.as_string(),
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   318
                             'DISTINCT Any  WHERE X is CWUser, X created_by G, G owned_by H, H login "admin"')
7618
5395007c415c [facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7615
diff changeset
   319
7874
be04706eacc9 [facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7768
diff changeset
   320
    def test_rql_path_check_filter_label_variable(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   321
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   322
            rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   323
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   324
                path = [('X created_by U'), ('U owned_by O'), ('O login OL')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   325
                filter_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   326
                label_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   327
            self.assertRaises(AssertionError, RPF, req, rset=rset,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   328
                              select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   329
                              filtered_variable=filtered_variable)
7874
be04706eacc9 [facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7768
diff changeset
   330
9562
0509880fec01 [facet] create a RangeRQLPathFacet (closes #2852512)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8598
diff changeset
   331
0509880fec01 [facet] create a RangeRQLPathFacet (closes #2852512)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8598
diff changeset
   332
    def test_rqlpath_range(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   333
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   334
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   335
            class RRF(facet.DateRangeRQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   336
                path = [('X created_by U'), ('U owned_by O'), ('O creation_date OL')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   337
                filter_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   338
            f = RRF(req, rset=rset, select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   339
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   340
            mind, maxd = req.cnx.execute('Any MIN(CD), MAX(CD) WHERE X is CWUser, X created_by U, U owned_by O, O creation_date CD')[0]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   341
            self.assertEqual(f.vocabulary(), [(str(mind), mind),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   342
                                              (str(maxd), maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   343
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   344
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   345
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   346
                             [str(mind), str(maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   347
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   348
            self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X is CWUser')
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   349
            req.form['%s_inf' % f.__regid__] = str(datetime2ticks(mind))
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   350
            req.form['%s_sup' % f.__regid__] = str(datetime2ticks(mind))
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   351
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   352
            # selection is cluttered because rqlst has been prepared for facet (it
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   353
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   354
            self.assertEqual(f.select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   355
                             'DISTINCT Any  WHERE X is CWUser, X created_by G, G owned_by H, H creation_date >= "%s", '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   356
                             'H creation_date <= "%s"'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   357
                             % (mind.strftime('%Y/%m/%d'),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   358
                                mind.strftime('%Y/%m/%d')))
9562
0509880fec01 [facet] create a RangeRQLPathFacet (closes #2852512)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8598
diff changeset
   359
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   360
    def prepareg_aggregat_rqlst(self, req):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   361
        return self.prepare_rqlst(req,
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   362
            u'Any 1, COUNT(X) WHERE X is CWUser, X creation_date XD, '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   363
             'X modification_date XM, Y creation_date YD, Y is CWGroup '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   364
             'HAVING DAY(XD)>=DAY(YD) AND DAY(XM)<=DAY(YD)', 'X',
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   365
            expected_baserql=u'Any 1,COUNT(X) WHERE X is CWUser, X creation_date XD, '
7624
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   366
            'X modification_date XM, Y creation_date YD, Y is CWGroup '
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   367
            'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)',
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   368
            expected_preparedrql=u'DISTINCT Any  WHERE X is CWUser, X creation_date XD, '
7624
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   369
            'X modification_date XM, Y creation_date YD, Y is CWGroup '
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   370
            'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)')
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   371
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   372
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   373
    def test_aggregat_query_cleanup_select(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   374
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   375
            rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   376
            select = rqlst.children[0]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   377
            facet.cleanup_select(select, filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   378
            self.assertEqual(select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   379
                             'DISTINCT Any  WHERE X is CWUser, X creation_date XD, '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   380
                             'X modification_date XM, Y creation_date YD, Y is CWGroup '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   381
                             'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)')
7624
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   382
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   383
    def test_aggregat_query_rql_path(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   384
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   385
            rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   386
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   387
                path = [('X created_by U'), ('U owned_by O'), ('O login OL')]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   388
                filter_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   389
            f = RPF(req, rset=rset, select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   390
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   391
            self.assertEqual(f.vocabulary(), [(u'admin', u'admin')])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   392
            self.assertEqual(f.possible_values(), ['admin'])
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   393
            req.form[f.__regid__] = u'admin'
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   394
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   395
            self.assertEqual(f.select.as_string(),
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   396
                             'DISTINCT Any  WHERE X is CWUser, X creation_date XD, '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   397
                             'X modification_date XM, Y creation_date YD, Y is CWGroup, '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   398
                             'X created_by G, G owned_by H, H login "admin" '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   399
                             'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)')
7624
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   400
ce020f90fb8e [facet] closes #1806932: test and fix facet bug w/ having query (need rql update)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7618
diff changeset
   401
    def test_aggregat_query_attribute(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   402
        with self.admin_access.web_request() as req:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   403
            rset, rqlst, filtered_variable = self.prepareg_aggregat_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   404
            f = facet.AttributeFacet(req, rset=rset,
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   405
                                     select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   406
                                     filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   407
            f.rtype = 'login'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   408
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   409
                              [(u'admin', u'admin'), (u'anon', u'anon')])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   410
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   411
                              ['admin', 'anon'])
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   412
            req.form[f.__regid__] = u'admin'
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   413
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   414
            self.assertEqual(f.select.as_string(),
10656
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   415
                             'DISTINCT Any  WHERE X is CWUser, X creation_date XD, '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   416
                             'X modification_date XM, Y creation_date YD, Y is CWGroup, X login "admin" '
0b1d03f07b87 [test] use unicode for rql queries (3/7)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10307
diff changeset
   417
                             'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)')
6433
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   418
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   419
if __name__ == '__main__':
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   420
    from logilab.common.testlib import unittest_main
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   421
    unittest_main()