[schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 08 Mar 2010 09:03:43 +0100
branchstable
changeset 4826 7eba168407c3
parent 4825 cdd979ae1b57
child 4827 8a505bf12193
[schema hook] fulltext_container is a relation *type* property. Test and fix (+ more fti properties change testing)
hooks/syncschema.py
hooks/test/unittest_syncschema.py
--- a/hooks/syncschema.py	Mon Mar 08 09:00:23 2010 +0100
+++ b/hooks/syncschema.py	Mon Mar 08 09:03:43 2010 +0100
@@ -231,7 +231,15 @@
     def precommit_event(self):
         session = self.session
         rschema = self.rschema
-        if rschema.final or not 'inlined' in self.values:
+        entity = self.entity
+        if 'fulltext_container' in entity.edited_attributes:
+            ftiupdates = session.transaction_data.setdefault(
+                'fti_update_etypes', set())
+            for subjtype, objtype in rschema.rdefs:
+                ftiupdates.add(subjtype)
+                ftiupdates.add(objtype)
+            UpdateFTIndexOp(session)
+        if rschema.final or not 'inlined' in entity.edited_attributes:
             return # nothing to do
         inlined = self.values['inlined']
         entity = self.entity
@@ -491,12 +499,6 @@
             UpdateFTIndexOp(session)
             session.transaction_data.setdefault(
                 'fti_update_etypes', set()).add(etype)
-        elif 'fulltext_container' in self.values:
-            ftiupdates = session.transaction_data.setdefault(
-                'fti_update_etypes', set())
-            ftiupdates.add(etype)
-            ftiupdates.add(self.kobj[1])
-            UpdateFTIndexOp(session)
 
 
 class SourceDbCWConstraintAdd(hook.Operation):
--- a/hooks/test/unittest_syncschema.py	Mon Mar 08 09:00:23 2010 +0100
+++ b/hooks/test/unittest_syncschema.py	Mon Mar 08 09:03:43 2010 +0100
@@ -271,20 +271,40 @@
         self.execute('Any X WHERE X is_instance_of BaseTransition, X messageid "hop"')
 
     def test_change_fulltextindexed(self):
-        target = self.request().create_entity(u'EmailAddress', address=u'rick.roll@dance.com')
+        req = self.request()
+        target = req.create_entity(u'Email', messageid=u'1234',
+                                   subject=u'rick.roll@dance.com')
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(target.eid, [item[0] for item in rset])
+        assert req.execute('SET A fulltextindexed FALSE '
+                            'WHERE E is CWEType, E name "Email", A is CWAttribute,'
+                            'A from_entity E, A relation_type R, R name "subject"')
+        self.commit()
+        rset = req.execute('Any X Where X has_text "rick.roll"')
+        self.failIf(rset)
+        assert req.execute('SET A fulltextindexed TRUE '
+                           'WHERE A from_entity E, A relation_type R, '
+                           'E name "Email", R name "subject"')
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(target.eid, [item[0] for item in rset])
+
+    def test_change_fulltext_container(self):
+        req = self.request()
+        target = req.create_entity(u'EmailAddress', address=u'rick.roll@dance.com')
+        target.set_relations(reverse_use_email=req.user)
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(req.user.eid, [item[0] for item in rset])
+        assert self.execute('SET R fulltext_container NULL '
+                            'WHERE R name "use_email"')
         self.commit()
         rset = self.execute('Any X Where X has_text "rick.roll"')
         self.assertIn(target.eid, [item[0] for item in rset])
+        assert self.execute('SET R fulltext_container "subject" '
+                            'WHERE R name "use_email"')
+        self.commit()
+        rset = req.execute('Any X WHERE X has_text "rick.roll"')
+        self.assertIn(req.user.eid, [item[0] for item in rset])
 
-        assert self.execute('''SET A fulltextindexed False
-                        WHERE E is CWEType,
-                              E name "EmailAddress",
-                              A is CWAttribute,
-                              A from_entity E,
-                              A relation_type R,
-                              R name "address"
-                    ''')
-        self.commit()
-        rset = self.execute('Any X Where X has_text "rick.roll"')
-        self.assertNotIn(target.eid, [item[0] for item in rset])
-