[entity] Reimplement and deprecate entity.cw_metainformation
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 06 Oct 2016 12:15:50 +0200
changeset 11764 6ab14a1afb65
parent 11763 39df042f4ab4
child 11765 9cb215e833b0
[entity] Reimplement and deprecate entity.cw_metainformation It shouldn't rely anymore on cnx.entity_metas which is itself deprecated, and the cw_metainformation API is similarly not needed anymore, access directly to cwuri / cw_source if needed. Related to #15538288
cubicweb/entity.py
cubicweb/server/test/unittest_datafeed.py
cubicweb/server/test/unittest_ldapsource.py
cubicweb/test/unittest_entity.py
--- a/cubicweb/entity.py	Fri Sep 30 17:39:17 2016 +0200
+++ b/cubicweb/entity.py	Thu Oct 06 12:15:50 2016 +0200
@@ -623,9 +623,13 @@
         """
         return self.has_eid() and self._cw_is_saved
 
+    @deprecated('[3.24] cw_metainformation is deprecated')
     @cached
     def cw_metainformation(self):
-        return self._cw.entity_metas(self.eid)
+        source = self.cw_source[0].name
+        return {'type': self.cw_etype,
+                'extid': self.cwuri if source != 'system' else None,
+                'source': {'uri': source}}
 
     def cw_check_perm(self, action):
         self.e_schema.check_perm(self._cw, action, eid=self.eid)
--- a/cubicweb/server/test/unittest_datafeed.py	Fri Sep 30 17:39:17 2016 +0200
+++ b/cubicweb/server/test/unittest_datafeed.py	Thu Oct 06 12:15:50 2016 +0200
@@ -84,10 +84,6 @@
                 self.assertEqual(entity.content, 'the cw web site')
                 self.assertEqual(entity.cwuri, 'http://www.cubicweb.org/')
                 self.assertEqual(entity.cw_source[0].name, u'รด myfeed')
-                self.assertEqual(entity.cw_metainformation(),
-                                 {'type': 'Card',
-                                  'extid': b'http://www.cubicweb.org/'}
-                                 )
                 # test repo cache keys
                 self.assertEqual(self.repo._type_extid_cache[entity.eid],
                                  ('Card', b'http://www.cubicweb.org/'))
@@ -104,12 +100,7 @@
             entity = cnx.execute('Card X').get_entity(0, 0)
             self.assertEqual(entity.cwuri, 'http://www.cubicweb.org/')
             self.assertEqual(entity.cw_source[0].name, 'myrenamedfeed')
-            self.assertEqual(entity.cw_metainformation(),
-                             {'type': 'Card',
-                              'extid': b'http://www.cubicweb.org/'}
-                             )
-            self.assertEqual(self.repo._type_extid_cache[entity.eid],
-                             ('Card', b'http://www.cubicweb.org/'))
+            self.assertEqual(self.repo._type_cache[entity.eid], 'Card')
 
             # test_delete_source
             cnx.execute('DELETE CWSource S WHERE S name "myrenamedfeed"')
--- a/cubicweb/server/test/unittest_ldapsource.py	Fri Sep 30 17:39:17 2016 +0200
+++ b/cubicweb/server/test/unittest_ldapsource.py	Thu Oct 06 12:15:50 2016 +0200
@@ -284,8 +284,6 @@
             self.assertEqual(len(rset), 1)
             e = rset.get_entity(0, 0)
             self.assertEqual(e.eid, eid)
-            self.assertEqual(e.cw_metainformation(), {'type': 'CWUser',
-                                                      'extid': None})
             self.assertEqual(e.cw_source[0].name, 'system')
             self.assertTrue(e.creation_date)
             self.assertTrue(e.modification_date)
@@ -294,11 +292,10 @@
             self.assertEqual(len(rset), 1)
             self.assertTrue(self.repo.system_source.authenticate(cnx, 'syt', password='syt'))
             # make sure the pull from ldap have not "reverted" user as a ldap-feed user
-            self.assertEqual(e.cw_metainformation(), {'type': 'CWUser',
-                                                      'extid': None})
             # and that the password stored in the system source is not empty or so
             user = cnx.execute('CWUser U WHERE U login "syt"').get_entity(0, 0)
             user.cw_clear_all_caches()
+            self.assertEqual(user.cw_source[0].name, 'system')
             cu = cnx.system_sql("SELECT cw_upassword FROM cw_cwuser WHERE cw_login='syt';")
             pwd = cu.fetchall()[0][0]
             self.assertIsNotNone(pwd)
--- a/cubicweb/test/unittest_entity.py	Fri Sep 30 17:39:17 2016 +0200
+++ b/cubicweb/test/unittest_entity.py	Thu Oct 06 12:15:50 2016 +0200
@@ -832,10 +832,14 @@
             self.assertEqual(len(person.reverse_ecrit_par), 2)
 
     def test_metainformation(self):
-        with self.admin_access.web_request() as req:
-            note = req.create_entity('Note', type=u'z')
+        with self.admin_access.client_cnx() as cnx:
+            note = cnx.create_entity('Note', type=u'z')
+            cnx.commit()
+            note.cw_clear_all_caches()
             metainf = note.cw_metainformation()
-            self.assertEqual(metainf, {'type': u'Note', 'extid': None})
+            self.assertEqual(metainf, {'type': u'Note',
+                                       'extid': None,
+                                       'source': {'uri': 'system'}})
 
     def test_absolute_url_empty_field(self):
         with self.admin_access.web_request() as req: