web/test/unittest_facet.py
author Christophe de Vienne <christophe@unlish.com>
Sat, 03 Jan 2015 04:06:06 +0100
changeset 10141 62e1f9749d3a
parent 9645 0b809c852266
child 10307 4b8253fb3125
permissions -rw-r--r--
[entities] Optimize CWUser.properties. This property gets called each time a user connects to a repository, which means a lot. This optimisation cuts its execution time by 5 according to my tests
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:
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    73
            rset = req.cnx.execute('Any X,GROUP_CONCAT(GN) GROUPBY X '
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    74
                                   'WHERE X in_group G?, G name GN, NOT G name "users"')
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
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    90
            self.assertEqual(rqlst.as_string(), "DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name 'users'")
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
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
    95
            self.assertEqual(rqlst.as_string(), "DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name 'users'")
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(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
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
63d5dbaef999 [facets] support for `no_relation` on RelationFacet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   132
6338
b520b86113e3 add test case demonstrating #1251910
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6119
diff changeset
   133
6119
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
    def test_relationattribute(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   135
        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
   136
            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
   137
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   138
                              [(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
   139
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   140
            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
   141
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   142
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   143
                              ['guests', 'managers'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   144
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   145
            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
   146
            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
   147
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   148
            # 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
   149
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   150
            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
   151
                              "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
   152
7615
e5ad51352eb3 [facet] fix argument inversion in date range facet
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7612
diff changeset
   153
    def test_daterange(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   154
        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
   155
            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
   156
            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
   157
                                     select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   158
                                     filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   159
            f.rtype = 'creation_date'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   160
            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
   161
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   162
                              [(str(mind), mind),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   163
                               (str(maxd), maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   164
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   165
            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
   166
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   167
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   168
                             [str(mind), str(maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   169
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   170
            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
   171
            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
   172
            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
   173
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   174
            # 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
   175
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   176
            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
   177
                              '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
   178
                             'X creation_date <= "%s"'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   179
                             % (mind.strftime('%Y/%m/%d'),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   180
                                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
   181
b217635d3b28 new RelationAttributeFacet + other fixes and cleanup + facets test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   182
    def test_attribute(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   183
        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
   184
            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
   185
            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
   186
                                     select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   187
                                     filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   188
            f.rtype = 'login'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   189
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   190
                              [(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
   191
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   192
            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
   193
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   194
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   195
                              ['admin', 'anon'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   196
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   197
            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
   198
            req.form[f.__regid__] = 'admin'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   199
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   200
            # 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
   201
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   202
            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
   203
                              "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
   204
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
   205
    def test_bitfield(self):
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   206
        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
   207
            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
   208
                '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
   209
                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
   210
                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
   211
            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
   212
                                    select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   213
                                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   214
            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
   215
            f.rtype = 'ordernum'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   216
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   217
                              [(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
   218
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   219
            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
   220
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   221
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   222
                              ['2', '1'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   223
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   224
            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
   225
            req.form[f.__regid__] = '3'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   226
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   227
            # 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
   228
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   229
            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
   230
                              "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
   231
8598
95b3792a8947 [facet] make BitFieldFacet allow special 0 value. Closes #2522697
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8029
diff changeset
   232
    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
   233
        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
   234
            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
   235
                '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
   236
                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
   237
                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
   238
            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
   239
                                    select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   240
                                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   241
            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
   242
            f.rtype = 'ordernum'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   243
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   244
                              [(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
   245
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   246
                              ['2', '1', '0'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   247
            req.form[f.__regid__] = '0'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   248
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   249
            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
   250
                              "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
   251
7618
5395007c415c [facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7615
diff changeset
   252
    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
   253
        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
   254
            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
   255
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   256
                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
   257
                filter_variable = 'O'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   258
                label_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   259
            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
   260
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   261
            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
   262
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   263
            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
   264
            #rqlst = rset.syntax_tree()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   265
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   266
                             [str(req.user.eid),])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   267
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   268
            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
   269
            req.form[f.__regid__] = '1'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   270
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   271
            # 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
   272
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   273
            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
   274
                             "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
   275
7874
be04706eacc9 [facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7768
diff changeset
   276
    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
   277
        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
   278
            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
   279
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   280
                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
   281
                filter_variable = 'O'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   282
            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
   283
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   284
            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
   285
7618
5395007c415c [facet] closes #1806931: new facet type, based on arbitrary rql path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7615
diff changeset
   286
    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
   287
        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
   288
            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
   289
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   290
                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
   291
                filter_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   292
            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
   293
                    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
   294
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   295
            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
   296
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   297
            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
   298
            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
   299
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   300
            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
   301
            req.form[f.__regid__] = 'admin'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   302
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   303
            # 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
   304
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   305
            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
   306
                             "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
   307
7874
be04706eacc9 [facet] add safety belt to rql path facet init (closes #1965481)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7768
diff changeset
   308
    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
   309
        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
   310
            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
   311
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   312
                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
   313
                filter_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   314
                label_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   315
            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
   316
                              select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   317
                              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
   318
9562
0509880fec01 [facet] create a RangeRQLPathFacet (closes #2852512)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8598
diff changeset
   319
0509880fec01 [facet] create a RangeRQLPathFacet (closes #2852512)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8598
diff changeset
   320
    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
   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.prepare_rqlst(req)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   323
            class RRF(facet.DateRangeRQLPathFacet):
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 creation_date 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
            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
   327
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   328
            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
   329
            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
   330
                                              (str(maxd), maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   331
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   332
            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
   333
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   334
                             [str(mind), str(maxd)])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   335
            # ensure rqlst is left unmodified
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   336
            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
   337
            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
   338
            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
   339
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   340
            # 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
   341
            # is not in real life)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   342
            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
   343
                             '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
   344
                             'H creation_date <= "%s"'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   345
                             % (mind.strftime('%Y/%m/%d'),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   346
                                mind.strftime('%Y/%m/%d')))
9562
0509880fec01 [facet] create a RangeRQLPathFacet (closes #2852512)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 8598
diff changeset
   347
9645
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   348
    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
   349
        return self.prepare_rqlst(req,
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
   350
            'Any 1, COUNT(X) WHERE X is CWUser, X creation_date XD, '
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
   351
            'X modification_date XM, Y creation_date YD, Y is CWGroup '
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
   352
            'HAVING DAY(XD)>=DAY(YD) AND DAY(XM)<=DAY(YD)', 'X',
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
   353
            expected_baserql='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
   354
            '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
   355
            'HAVING DAY(XD) >= DAY(YD), DAY(XM) <= DAY(YD)',
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
   356
            expected_preparedrql='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
   357
            '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
   358
            '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
   359
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
   360
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
   361
    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
   362
        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
   363
            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
   364
            select = rqlst.children[0]
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   365
            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
   366
            self.assertEqual(select.as_string(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   367
                             '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
   368
                             '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
   369
                             '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
   370
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
    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
   372
        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
   373
            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
   374
            class RPF(facet.RQLPathFacet):
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   375
                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
   376
                filter_variable = 'OL'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   377
            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
   378
                    filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   379
            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
   380
            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
   381
            req.form[f.__regid__] = 'admin'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   382
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   383
            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
   384
                             "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
   385
                             "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
   386
                             "X created_by G, G owned_by H, H login 'admin' "
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   387
                             "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
   388
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
   389
    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
   390
        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
   391
            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
   392
            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
   393
                                     select=rqlst.children[0],
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   394
                                     filtered_variable=filtered_variable)
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   395
            f.rtype = 'login'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   396
            self.assertEqual(f.vocabulary(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   397
                              [(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
   398
            self.assertEqual(f.possible_values(),
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   399
                              ['admin', 'anon'])
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   400
            req.form[f.__regid__] = 'admin'
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   401
            f.add_rql_restrictions()
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   402
            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
   403
                              "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
   404
                              "X modification_date XM, Y creation_date YD, Y is CWGroup, X login 'admin' "
0b809c852266 [web/test] port unittest_facet to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 9562
diff changeset
   405
                              "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
   406
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   407
if __name__ == '__main__':
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   408
    from logilab.common.testlib import unittest_main
95c40961df21 [test] missing main
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
   409
    unittest_main()