Exemplo n.º 1
0
    def test_simple_file(self):
        path = '{}/hello_world.docx'.format(self.TESTFILE_BASE)
        with open(path, 'rb') as f:
            content = f.read()

        handler = DocxHandler()
        template, stringset = handler.parse(content)

        self.assertEqual(len(stringset), 1)

        openstring = stringset[0]
        self.assertEqual(openstring.order, 0)
        self.assertEqual(
            openstring.string,
            u'<tx>Hello world </tx><tx href="https://www.transifex.com/">this is a link</tx>'  # noqa
        )
        self.assertEqual(openstring.string, openstring.key)

        translation = u'<tx>Καλημέρα κόσμε </tx><tx href="https://el.transifex.com/">αυτός είναι ένας κρίκος</tx>'  # noqa
        stringset = [
            OpenString(openstring.key, translation, order=1)
        ]

        content = handler.compile(template, stringset)
        template, stringset = handler.parse(content)

        self.assertEqual(len(stringset), 1)

        docx = DocxFile(content)

        for text in [u'Hello world ', u'this is a link']:
            self.assertFalse(text in docx.get_document())

        for url in [u'https://www.transifex.com/']:
            self.assertFalse(url in docx.get_document_rels())

        for text in [u'Καλημέρα κόσμε ', u'αυτός είναι ένας κρίκος']:
            self.assertTrue(text in docx.get_document())

        for url in [u'https://el.transifex.com/']:
            self.assertTrue(url in docx.get_document_rels())

        docx.set_document(u'Modified Document')
        docx.set_document_rels(u'Modified Document Rels')

        openstring = stringset[0]
        self.assertEqual(openstring.order, 0)
        self.assertEqual(openstring.string, translation)
        self.assertEqual(openstring.string, openstring.key)
Exemplo n.º 2
0
    def test_docx_file(self):
        content = self.get_content('hello_world.docx')

        docx = DocxFile(content)

        for text in [u'Hello world ', u'this is a link']:
            self.assertTrue(text in docx.get_document())

        for url in [u'https://www.transifex.com/']:
            self.assertTrue(url in docx.get_document_rels())

        docx.set_document(u'Modified Document')
        docx.set_document_rels(u'Modified Document Rels')

        content = docx.compress()
        docx.delete()

        docx = DocxFile(content)
        self.assertEqual(docx.get_document(), u'Modified Document')
        self.assertEqual(docx.get_document_rels(), u'Modified Document Rels')
Exemplo n.º 3
0
    def test_docx_file(self):
        path = '{}/hello_world.docx'.format(self.TESTFILE_BASE)
        with open(path, 'rb') as f:
            content = f.read()

        docx = DocxFile(content)

        for text in [u'Hello world ', u'this is a link']:
            self.assertTrue(text in docx.get_document())

        for url in [u'https://www.transifex.com/']:
            self.assertTrue(url in docx.get_document_rels())

        docx.set_document(u'Modified Document')
        docx.set_document_rels(u'Modified Document Rels')

        content = docx.compress()
        docx.delete()

        docx = DocxFile(content)
        self.assertEqual(docx.get_document(), u'Modified Document')
        self.assertEqual(docx.get_document_rels(), u'Modified Document Rels')