def override_templates_step(context): if not context.readDataFile("imiodmsmail_singles_marker.txt"): return templates_list = [(tup[1], tup[2]) for tup in list_templates()] ret = update_templates(templates_list, force=True) ret = '\n'.join(["%s: %s" % (tup[0], tup[2]) for tup in ret]).encode('utf8') logger.info('\n{}'.format(ret)) return ret
def test_update_templates(self): # we use a ConfigurablePODTemplate to test style modification test_template = self.portal.podtemplates.get('test_template_multiple') tpath = '%s/profiles/demo/templates' % cdg.__path__[0] def path(tmpl): return '%s/%s' % (tpath, tmpl) with open(path('modele_general.odt'), 'rb') as f: mgodt = f.read() mgodt_md5 = compute_md5(mgodt) with open(path('modèle_collection.odt'), 'rb') as f: mcodt_md5 = compute_md5(f.read()) # check loaded current template is same as os one self.assertEqual(test_template.initial_md5, mgodt_md5) # check current md5 is no more initial_md5 after style update self.assertNotEqual(test_template.initial_md5, test_template.current_md5) # check style_modification_md5 is equal to current md5 after style update only self.assertEqual(test_template.style_modification_md5, test_template.current_md5) self.assertFalse(test_template.has_been_modified()) modif_date = test_template.modification_date # bad plone obj path => no change ret = update_templates([('/podtemplates/test_template_bad', path('modele_general.odt'))]) self.assertEquals(ret[0][2], 'plone path error') # bad file path => no change ret = update_templates([('/podtemplates/test_template_multiple', path('modele_general.bad'))]) self.assertEqual(modif_date, test_template.modification_date) self.assertEquals(ret[0][2], 'os path error') # same os file => unchanged status ret = update_templates([('/podtemplates/test_template_multiple', path('modele_general.odt'))]) self.assertEqual(modif_date, test_template.modification_date) self.assertEquals(ret[0][2], 'unchanged') # replace file when not same os file and template not modified ret = update_templates([('/podtemplates/test_template_multiple', path('modèle_collection.odt'))]) self.assertEqual(test_template.initial_md5, mcodt_md5) self.assertNotEqual(test_template.initial_md5, test_template.current_md5) self.assertEqual(test_template.style_modification_md5, test_template.current_md5) self.assertFalse(test_template.has_been_modified()) self.assertEquals(ret[0][2], 'replaced') self.assertNotEquals(modif_date, test_template.modification_date) modif_date = test_template.modification_date # don't replace file when not same os file but template is modified # We change template file test_template.odt_file.data = mgodt modified(test_template) self.assertEqual(test_template.initial_md5, mcodt_md5) self.assertNotEqual(test_template.style_modification_md5, test_template.current_md5) self.assertTrue(test_template.has_been_modified()) modif_date = test_template.modification_date ret = update_templates([('/podtemplates/test_template_multiple', path('modele_general.odt'))]) self.assertEquals(ret[0][2], 'kept') self.assertEquals(modif_date, test_template.modification_date) # we force replacement ret = update_templates([('/podtemplates/test_template_multiple', path('modele_general.odt'))], force=True) self.assertEquals(ret[0][2], 'replaced') self.assertNotEquals(modif_date, test_template.modification_date)