test/unittest_entity.py
changeset 10997 da712d3f0601
parent 10907 9ae707db5265
child 11047 bfd11ffa79f7
equal deleted inserted replaced
10996:dc572d116731 10997:da712d3f0601
   140 
   140 
   141     def test_related_cache_both(self):
   141     def test_related_cache_both(self):
   142         with self.admin_access.web_request() as req:
   142         with self.admin_access.web_request() as req:
   143             user = req.execute('Any X WHERE X eid %(x)s', {'x':req.user.eid}).get_entity(0, 0)
   143             user = req.execute('Any X WHERE X eid %(x)s', {'x':req.user.eid}).get_entity(0, 0)
   144             adeleid = req.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0]
   144             adeleid = req.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0]
   145             self.assertEqual({}, user._cw_related_cache)
       
   146             req.cnx.commit()
   145             req.cnx.commit()
   147             self.assertEqual(['primary_email_subject', 'use_email_subject', 'wf_info_for_object'],
   146             self.assertEqual(user._cw_related_cache, {})
   148                              sorted(user._cw_related_cache))
       
   149             email = user.primary_email[0]
   147             email = user.primary_email[0]
   150             self.assertEqual(u'toto@logilab.org', email.address)
   148             self.assertEqual(sorted(user._cw_related_cache), ['primary_email_subject'])
   151             self.assertEqual(['created_by_subject',
   149             self.assertEqual(list(email._cw_related_cache), ['primary_email_object'])
   152                               'cw_source_subject',
       
   153                               'is_instance_of_subject',
       
   154                               'is_subject',
       
   155                               'owned_by_subject',
       
   156                               'prefered_form_object',
       
   157                               'prefered_form_subject',
       
   158                               'primary_email_object',
       
   159                               'use_email_object'],
       
   160                              sorted(email._cw_related_cache))
       
   161             self.assertEqual('admin', email._cw_related_cache['primary_email_object'][1][0].login)
       
   162             groups = user.in_group
   150             groups = user.in_group
       
   151             self.assertEqual(sorted(user._cw_related_cache), ['in_group_subject', 'primary_email_subject'])
   163             for group in groups:
   152             for group in groups:
   164                 self.assertNotIn('in_group_subject', group._cw_related_cache)
   153                 self.assertNotIn('in_group_subject', group._cw_related_cache)
   165             user.cw_clear_all_caches()
   154             user.cw_clear_all_caches()
   166             user.related('in_group', entities=True)
   155             user.related('in_group', entities=True)
   167             self.assertIn('in_group_subject', user._cw_related_cache)
   156             self.assertIn('in_group_subject', user._cw_related_cache)