pyramid_cubicweb/tests/test_entities.py
author Christophe de Vienne <christophe@unlish.com>
Tue, 09 Jun 2015 11:34:17 +0200
changeset 11596 1f2570f1d72a
permissions -rw-r--r--
[routes] Add a 'cwentities' route with traversal The route uses a factory that produces ETypeResource and EntityResource as a context. A 'delete' view serve as a test and demonstration. The module being experimental, it has to be explicitely included.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11596
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     1
from __future__ import absolute_import
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     2
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     3
from . import PyramidCWTest
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     4
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     5
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     6
class EntitiesTest(PyramidCWTest):
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     7
    def includeme(self, config):
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     8
        config.include('pyramid_cubicweb.entities')
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     9
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    10
    def test_delete(self):
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    11
        with self.admin_access.repo_cnx() as cnx:
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    12
            cnx.create_entity('CWGroup', name=u'tmp')
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    13
            cnx.commit()
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    14
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    15
        self.login()
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    16
        res = self.webapp.delete('/cwgroup/tmp')
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    17
        self.assertEqual(res.status_int, 204)
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    18
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    19
        with self.admin_access.repo_cnx() as cnx:
1f2570f1d72a [routes] Add a 'cwentities' route with traversal
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    20
            self.assertEqual(cnx.find('CWGroup', name=u'tmp').rowcount, 0)