test/unittest_entity.py
changeset 9821 2077c8da1893
parent 9774 b7b71be569cf
child 9877 4a604b6e3067
equal deleted inserted replaced
9819:95902c0b991b 9821:2077c8da1893
    41 
    41 
    42     def tearDown(self):
    42     def tearDown(self):
    43         super(EntityTC, self).tearDown()
    43         super(EntityTC, self).tearDown()
    44         for cls in self.vreg['etypes'].iter_classes():
    44         for cls in self.vreg['etypes'].iter_classes():
    45             cls.fetch_attrs, cls.cw_fetch_order = self.backup_dict[cls]
    45             cls.fetch_attrs, cls.cw_fetch_order = self.backup_dict[cls]
       
    46 
       
    47     def test_no_prefill_related_cache_bug(self):
       
    48         session = self.session
       
    49         usine = session.create_entity('Usine', lieu=u'Montbeliard')
       
    50         produit = session.create_entity('Produit')
       
    51         # usine was prefilled in glob_add_entity
       
    52         # let's simulate produit creation without prefill
       
    53         produit._cw_related_cache.clear()
       
    54         # use add_relations
       
    55         session.add_relations([('fabrique_par', [(produit.eid, usine.eid)])])
       
    56         self.assertEqual(1, len(usine.reverse_fabrique_par))
       
    57         self.assertEqual(1, len(produit.fabrique_par))
    46 
    58 
    47     def test_boolean_value(self):
    59     def test_boolean_value(self):
    48         with self.admin_access.web_request() as req:
    60         with self.admin_access.web_request() as req:
    49             e = self.vreg['etypes'].etype_class('CWUser')(req)
    61             e = self.vreg['etypes'].etype_class('CWUser')(req)
    50             self.assertTrue(e)
    62             self.assertTrue(e)
   352             email = req.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0)
   364             email = req.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0)
   353             rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0]
   365             rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0]
   354             self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA '
   366             self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA '
   355                              'WHERE NOT S use_email O, O eid %(x)s, S is_instance_of CWUser, '
   367                              'WHERE NOT S use_email O, O eid %(x)s, S is_instance_of CWUser, '
   356                              'S login AA, S firstname AB, S surname AC, S modification_date AD')
   368                              'S login AA, S firstname AB, S surname AC, S modification_date AD')
       
   369             req.cnx.commit()
   357         rperms = self.schema['EmailAddress'].permissions['read']
   370         rperms = self.schema['EmailAddress'].permissions['read']
   358         clear_cache(self.schema['EmailAddress'], 'get_groups')
   371         clear_cache(self.schema['EmailAddress'], 'get_groups')
   359         clear_cache(self.schema['EmailAddress'], 'get_rqlexprs')
   372         clear_cache(self.schema['EmailAddress'], 'get_rqlexprs')
   360         self.schema['EmailAddress'].permissions['read'] = ('managers', 'users', 'guests',)
   373         self.schema['EmailAddress'].permissions['read'] = ('managers', 'users', 'guests',)
   361         try:
   374         try:
   686             e.cw_attr_cache['description_format'] = 'text/html'
   699             e.cw_attr_cache['description_format'] = 'text/html'
   687             e.cw_attr_cache['data'] = Binary('some <em>data</em>')
   700             e.cw_attr_cache['data'] = Binary('some <em>data</em>')
   688             e.cw_attr_cache['data_name'] = 'an html file'
   701             e.cw_attr_cache['data_name'] = 'an html file'
   689             e.cw_attr_cache['data_format'] = 'text/html'
   702             e.cw_attr_cache['data_format'] = 'text/html'
   690             e.cw_attr_cache['data_encoding'] = 'ascii'
   703             e.cw_attr_cache['data_encoding'] = 'ascii'
   691             e._cw.transaction_data = {} # XXX req should be a session
   704             e._cw.transaction_data.clear()
   692             words = e.cw_adapt_to('IFTIndexable').get_words()
   705             words = e.cw_adapt_to('IFTIndexable').get_words()
   693             words['C'].sort()
   706             words['C'].sort()
   694             self.assertEqual({'C': sorted(['an', 'html', 'file', 'du', 'html', 'some', 'data'])},
   707             self.assertEqual({'C': sorted(['an', 'html', 'file', 'du', 'html', 'some', 'data'])},
   695                              words)
   708                              words)
   696 
   709