doc/tutorials/advanced/part02_security.rst
changeset 12209 3a3551fff787
parent 10491 c67bcee93248
child 12381 a383091bdea8
equal deleted inserted replaced
12208:159dce89a145 12209:3a3551fff787
   192 
   192 
   193     class SetVisibilityOp(hook.DataOperationMixIn, hook.Operation):
   193     class SetVisibilityOp(hook.DataOperationMixIn, hook.Operation):
   194 
   194 
   195 	def precommit_event(self):
   195 	def precommit_event(self):
   196 	    for eid in self.get_data():
   196 	    for eid in self.get_data():
   197 		entity = self.session.entity_from_eid(eid)
   197 		entity = self.cnx.entity_from_eid(eid)
   198 		if entity.visibility == 'parent':
   198 		if entity.visibility == 'parent':
   199 		    entity.cw_set(visibility=u'authenticated')
   199 		    entity.cw_set(visibility=u'authenticated')
   200 
   200 
   201     class SetVisibilityHook(hook.Hook):
   201     class SetVisibilityHook(hook.Hook):
   202 	__regid__ = 'sytweb.setvisibility'
   202 	__regid__ = 'sytweb.setvisibility'
   362 
   362 
   363 To run it type:
   363 To run it type:
   364 
   364 
   365 .. sourcecode:: bash
   365 .. sourcecode:: bash
   366 
   366 
   367     $ pytest unittest_sytweb.py
   367     $ python test/unittest_sytweb.py
   368     ========================  unittest_sytweb.py  ========================
   368     ========================  unittest_sytweb.py  ========================
   369     -> creating tables [....................]
   369     -> creating tables [....................]
   370     -> inserting default user and default groups.
   370     -> inserting default user and default groups.
   371     -> storing the schema in the database [....................]
   371     -> storing the schema in the database [....................]
   372     -> database for instance data initialized.
   372     -> database for instance data initialized.
   380 The first execution is taking time, since it creates a sqlite database for the
   380 The first execution is taking time, since it creates a sqlite database for the
   381 test instance. The second one will be much quicker:
   381 test instance. The second one will be much quicker:
   382 
   382 
   383 .. sourcecode:: bash
   383 .. sourcecode:: bash
   384 
   384 
   385     $ pytest unittest_sytweb.py
   385     $ python test/unittest_sytweb.py
   386     ========================  unittest_sytweb.py  ========================
   386     ========================  unittest_sytweb.py  ========================
   387     .
   387     .
   388     ----------------------------------------------------------------------
   388     ----------------------------------------------------------------------
   389     Ran 1 test in 2.662s
   389     Ran 1 test in 2.662s
   390 
   390 
   394 database. You do that by removing the tmpdb files before running the test: ::
   394 database. You do that by removing the tmpdb files before running the test: ::
   395 
   395 
   396     $ rm data/database/tmpdb*
   396     $ rm data/database/tmpdb*
   397 
   397 
   398 
   398 
   399 .. Note::
       
   400   pytest is a very convenient utility used to control test execution. It is available from the `logilab-common`_ package.
       
   401 
       
   402 .. _`logilab-common`: http://www.logilab.org/project/logilab-common
       
   403 
       
   404 .. _adv_tuto_migration_script:
   399 .. _adv_tuto_migration_script:
   405 
   400 
   406 Step 4: writing the migration script and migrating the instance
   401 Step 4: writing the migration script and migrating the instance
   407 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   402 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   408 
   403