[PATCH saem] [hooks] Don't update concept's mdate on code_keyword_type insertion

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Oct 31 17:55:55 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1509447995 -3600
#      Tue Oct 31 12:06:35 2017 +0100
# Node ID dfd42c0fe159fcba5df4152907cfb54f31028998
# Parent  340a8515c5d5de6b57ef366d4d080eb25fb2560b
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r dfd42c0fe159
[hooks] Don't update concept's mdate on code_keyword_type insertion

only the subject's vocabulary should be marked as modified.

Closes extranet #37975627

diff --git a/cubicweb_saem_ref/hooks.py b/cubicweb_saem_ref/hooks.py
--- a/cubicweb_saem_ref/hooks.py
+++ b/cubicweb_saem_ref/hooks.py
@@ -109,10 +109,14 @@ def _log_relation(rtype, entity, target)
 
     This is called when relation's ends are in different containers, with
     `entity` as the potentiel activity holder and `target` the other relation's
     end.
     """
+    # code_keyword_type is qualifying the subject scheme, don't log the
+    # modification on the target concept
+    if rtype == 'code_keyword_type':
+        return entity.cw_etype == 'ConceptScheme'
     # if entity is a scheme or concept, only log if the other ends is also a
     # concept or scheme
     if entity.cw_etype in ('Concept', 'ConceptScheme'):
         return target.cw_etype in ('Concept', 'ConceptScheme')
     return True
diff --git a/test/unittest_hooks.py b/test/unittest_hooks.py
--- a/test/unittest_hooks.py
+++ b/test/unittest_hooks.py
@@ -54,10 +54,11 @@ class SAEMRefHooksTC(CubicWebTC):
 
     def test_sync_scheme_md(self):
         with self.admin_access.repo_cnx() as cnx:
             scheme = cnx.create_entity('ConceptScheme', title=u'my thesaurus',
                                        ark_naa=testutils.naa(cnx))
+            kt_scheme = testutils.scheme_for_type(cnx, 'seda_keyword_type_to', None, u'theme')
             cnx.commit()
             self.resetMD(cnx, scheme)
             c1 = scheme.add_concept(u'concept 1', language_code=u'fr')
             cnx.commit()
             self.assertMDNow(scheme)
@@ -86,10 +87,19 @@ class SAEMRefHooksTC(CubicWebTC):
             cnx.commit()
             self.assertMDNow(c2)
             self.assertMDNow(c1)
             self.assertMDNow(scheme)
 
+            self.resetMD(cnx, scheme)
+            self.resetMD(cnx, kt_scheme)
+            cnx.commit()
+            scheme.cw_set(code_keyword_type=kt_scheme.reverse_in_scheme[0])
+            cnx.commit()
+            kt_scheme.cw_clear_all_caches()
+            self.assertEqual(kt_scheme.modification_date, YESTERDAY)
+            self.assertMDNow(scheme)
+
     def test_sync_profile_md(self):
         with self.admin_access.repo_cnx() as cnx:
             scheme = testutils.scheme_for_type(cnx, 'seda_rule', 'SEDASeqAccessRuleRule', u'AR038')
             transfer = testutils.setup_profile(cnx)
             unit, unit_alt, unit_alt_seq = testutils.create_archive_unit(transfer)


More information about the saem-devel mailing list