devtools/webtest.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 13 Mar 2015 14:47:35 +0100
changeset 10234 a12e4459eee5
parent 9930 d20c2b262f55
child 11016 d04703f54510
permissions -rw-r--r--
[web/views/rdf] Take the second element of XY equivalent for non final relation When given a Yams snippet of the form `<etype> <rtype>` ``xy.xeq()`` will return the XML snippet equivalent to this relation in the form of a tuple `(subject, rtype, object)` so ``item`` will always be a tuple here. In fact, the correct code appears just a few lines above (around line 88) for final relations so I guess this is a copy-paste mistake. Closes #4745929.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9930
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     1
from __future__ import absolute_import
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     2
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     3
import webtest
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     4
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     5
from cubicweb.wsgi import handler
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     6
from cubicweb.devtools.testlib import CubicWebTC
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     7
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     8
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     9
class CubicWebTestTC(CubicWebTC):
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    10
    @classmethod
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    11
    def init_config(cls, config):
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    12
        super(CubicWebTestTC, cls).init_config(config)
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    13
        config.global_set_option('base-url', 'http://localhost.local/')
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    14
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    15
    def setUp(self):
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    16
        super(CubicWebTestTC, self).setUp()
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    17
        webapp = handler.CubicWebWSGIApplication(self.config)
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    18
        self.webapp = webtest.TestApp(webapp)
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    19
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    20
    def tearDown(self):
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    21
        del self.webapp
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    22
        super(CubicWebTestTC, self).tearDown()
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    23
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    24
    def login(self, user=None, password=None, **args):
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    25
        if user is None:
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    26
            user = self.admlogin
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    27
        if password is None:
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    28
            password = self.admpassword if user == self.admlogin else user
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    29
        args.update({
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    30
            '__login': user,
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    31
            '__password': password
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    32
        })
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    33
        return self.webapp.get('/login', args)
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    34
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    35
    def logout(self):
d20c2b262f55 [tests] Add a webtest based TestCase class
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    36
        return self.webapp.get('/logout')