示例#1
0
 def testWebPage_updateWebDocument(self):
     """ Test if script load correctly the Web Page with data of one document
 """
     portal = self.portal
     portal_preferences = portal.portal_preferences
     web_page_module = portal.web_page_module
     portal_contributions = portal.portal_contributions
     system_preference = portal_preferences.newContent(
         portal_type='System Preference')
     conversion_dict = _getConversionServerDict()
     system_preference.setPreferredDocumentConversionServerUrl(
         conversion_dict["url"])
     system_preference.enable()
     self.tic()
     document_path, filename = self.getDocumentPath()
     file = FileUpload(document_path, filename)
     document = portal_contributions.newContent(file=file)
     web_page = web_page_module.newContent(portal_type="Web Page")
     self.tic()
     self.changeSkin("UNGDoc")
     web_page.WebPage_updateWebDocument(document.getPath())
     self.tic()
     self.assertTrue(
         re.search("\>tiolive\<", web_page.getTextContent()) is not None)
     self.assertEqual(web_page.getTitle(), document.getTitle())
示例#2
0
    def test_include_img(self):
        """
      Create an OOoTemplate from scratch, using pt_editAction to set the
      content, the content contains an include_img, when the OOo is rendered we
      have:
       - valid odf
       - an image included in the "ZIP"
       - the image properly listed in manifest
    """
        request = self.app.REQUEST
        filename = 'cmyk_sample.jpg'
        file_path = os.path.join(os.path.dirname(__file__), 'test_document',
                                 filename)
        upload_file = FileUpload(file_path)
        document = self.portal.portal_contributions.newContent(
            file=upload_file)
        addOOoTemplate = self.getPortal(
        ).manage_addProduct['ERP5OOo'].addOOoTemplate
        addOOoTemplate(id='Base_viewIncludeImageAsOdt', title='')
        custom_content = self.content.replace(
            "<office:text />",
            "<office:text><office:include_img path='%s'/></office:text>" %
            document.getRelativeUrl())
        Base_viewIncludeImageAsOdt = self.getPortal(
        ).Base_viewIncludeImageAsOdt
        Base_viewIncludeImageAsOdt.doSettings(
            request,
            title='',
            xml_file_id='content.xml',
            ooo_stylesheet='Base_getODTStyleSheet',
            script_name='')
        Base_viewIncludeImageAsOdt.pt_edit(
            custom_content,
            content_type='application/vnd.oasis.opendocument.text')
        self.tic()

        response = self.publish(
            '/' + self.getPortal().Base_viewIncludeImageAsOdt.absolute_url(1))
        body = response.getBody()
        self.assertEqual(200, response.getStatus(), body)
        self.assertEqual('application/vnd.oasis.opendocument.text',
                         response.getHeader('content-type').split(';')[0])
        self.assertEqual(
            'attachment; filename="Base_viewIncludeImageAsOdt.odt"',
            response.getHeader('content-disposition'))
        cs = StringIO()
        cs.write(body)
        zip_document = ZipFile(cs)
        picture_list = filter(lambda x: "Pictures" in x.filename,
                              zip_document.infolist())
        self.assertNotEquals([], picture_list)
        manifest = zip_document.read('META-INF/manifest.xml')
        content = zip_document.read('content.xml')
        for picture in picture_list:
            self.assertTrue(picture.filename in manifest)
            self.assertTrue(picture.filename in content)
示例#3
0
  def test_24_getImageDataWithAnonymousUser(self):
    """
      Anonymous user must be able to get product image.
    """
    product = self.getDefaultProduct()
    file_upload = FileUpload(os.path.join(os.path.dirname(__file__),
                          'test_data', 'images', 'erp5_logo_small.png'), 'rb')
    product.edit(default_image_file=file_upload)
    self.tic()

    self.logout()
    product = self.getDefaultProduct()
    self.assertTrue(product.getDefaultImageValue().getData()
                                                 not in ('', None))
示例#4
0
def makeFileUpload(name):
    path = os.path.join(test_files, name)
    return FileUpload(path, name)
示例#5
0
    def test_03_Image(self):
        """
    Mapping an ImageField to odg document.
    Check it's possible to use an odg document to map an image with a
    form.ImageField
    """
        # create a new person
        request = self.portal.REQUEST
        person_module = self.portal.getDefaultModule('Person')
        if person_module._getOb('person1', None) is None:
            person_module.newContent(id='person1', portal_type='Person')
        person1 = person_module.person1

        # add an image to this person
        current_dir = os.path.dirname(__file__)
        parent_dir = os.path.dirname(current_dir)
        image_path = os.path.join(parent_dir, 'www', 'form_printout_icon.png')
        file_data = FileUpload(image_path)
        image = person1.newContent(portal_type='Embedded File')
        image.edit(file=file_data)

        foo_printout = image.Foo_viewAsODGPrintout
        foo_form = image.Foo_view
        # add an image_field to Foo_view if there is not
        if foo_form._getOb("image_view", None) is None:
            foo_form.manage_addField('image_view', 'logo', 'ImageField')
        image_view_field = foo_form.image_view
        # set the image on the field
        image_view_field.values['default'] = image.absolute_url_path()

        # 01 - Normal image mapping
        odf_document = foo_printout(request)
        self.assertTrue(odf_document is not None)
        self._validate(odf_document)
        builder = OOoBuilder(odf_document)
        content_xml = builder.extract("content.xml")
        content = etree.XML(content_xml)
        image_element_list = content.xpath('//draw:image',
                                           namespaces=content.nsmap)
        self.assertTrue(len(image_element_list) > 0)

        # check the image is in the odg file
        try:
            image_path = image_element_list[0].get(
                '{http://www.w3.org/1999/xlink}href')
            image_data = builder.extract(image_path)
        except KeyError:
            self.fail('image %r not found in odg document' % image_path)
        self.assertEqual(image.getData(), image_data,
                         '%s != %s' % (len(image.getData()), len(image_data)))
        image_frame_xpath = '//draw:frame[@draw:name="image_view"]'
        image_frame_list = content.xpath(image_frame_xpath,
                                         namespaces=content.nsmap)
        self.assertTrue(len(image_frame_list) > 0)
        image_frame = image_frame_list[0]
        # Check the image size.
        # as the test image (form_printout_icon.png) is a square, proportions
        # should be keept, so heigh and width should be same and equal to the
        # height of the original image in the original odf test document.
        self.assertEqual(
            image_frame.attrib['{%s}height' % content.nsmap['svg']], '1.206cm')
        self.assertEqual(
            image_frame.attrib['{%s}width' % content.nsmap['svg']], '1.206cm')

        # 02: No image defined
        image_view_field.values['default'] = ''
        odf_document = foo_printout(request)
        self.assertTrue(odf_document is not None)
        builder = OOoBuilder(odf_document)
        content_xml = builder.extract("content.xml")
        # confirming the image was removed
        content = etree.XML(content_xml)
        image_element_list = content.xpath('//draw:image',
                                           namespaces=content.nsmap)
        self.assertFalse(len(image_element_list) > 0)
        self._validate(odf_document)
示例#6
0
def makeFileUpload(name, as_name=None):
    if as_name is None:
        as_name = name
    path = makeFilePath(name)
    return FileUpload(path, as_name)
示例#7
0
def makeFileUpload(name):
  path = makeFilePath(name)
  return FileUpload(path, name)
示例#8
0
 def makeFileUpload(self, filename):
     return FileUpload(
         os.path.join(os.path.dirname(__file__), 'data', filename), 'rb')