def test_search_dont_alter_podtemplate(self):
        template1_md5 = compute_md5(self.template1.odt_file.data)
        template2_md5 = compute_md5(self.template2.odt_file.data)

        with SearchAndReplacePODTemplates(
            (self.template1, self.template2)) as search_replace:
            search_replace.search("view")

        self.assertEqual(compute_md5(self.template1.odt_file.data),
                         template1_md5)
        self.assertEqual(compute_md5(self.template2.odt_file.data),
                         template2_md5)
    def test_replace_change_podtemplate_file(self):
        template1_md5 = compute_md5(self.template1.odt_file.data)
        template2_md5 = compute_md5(self.template2.odt_file.data)

        with SearchAndReplacePODTemplates(
            (self.template1, self.template2)) as search_replace:
            search_replace.replace("view", "View")

        self.assertNotEquals(compute_md5(self.template1.odt_file.data),
                             template1_md5)
        self.assertNotEquals(compute_md5(self.template2.odt_file.data),
                             template2_md5)
 def current_md5(self):
     md5 = u''
     if self.odt_file:
         md5 = safe_unicode(compute_md5(self.odt_file.data))
     return md5
 def current_md5(self):
     md5 = ''
     if self.odt_file:
         md5 = compute_md5(self.odt_file.data)
     return md5
 def current_md5(self):
     md5 = u''
     if self.odt_file:
         md5 = safe_unicode(compute_md5(self.odt_file.data))
     return md5
    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)
    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)
Exemplo n.º 8
0
 def current_md5(self):
     md5 = ''
     if self.odt_file:
         md5 = compute_md5(self.odt_file.data)
     return md5