コード例 #1
0
    def test_has_file(self):
        self.login(self.dossier_responsible)

        self.assertTrue(DocPropertyWriter(self.document).has_file())

        self.document.file = None
        self.assertFalse(DocPropertyWriter(self.document).has_file())
コード例 #2
0
    def test_is_supported_file(self):
        self.login(self.regular_user)

        writer = DocPropertyWriter(self.document)

        self.assertTrue(writer.is_supported_file())

        self.document.file.contentType = 'text/foo'

        self.assertFalse(writer.is_supported_file())
コード例 #3
0
    def test_writes_additional_recipient_property_providers(self):
        self.login(self.regular_user)
        self.with_asset_file('without_custom_properties.docx')

        peter = create(
            Builder('person')
            .having(
                firstname=u'Peter',
                lastname=u'M\xfcller',
                )
            )

        address = create(
            Builder('address')
            .for_contact(peter)
            .labeled(u'Home')
            .having(
                street=u'Musterstrasse 283',
                zip_code=u'1234',
                city=u'Hinterkappelen',
                country=u'Schweiz',
                )
            )

        writer = DocPropertyWriter(
            self.document,
            recipient_data=(peter, address),
            )

        writer.update_doc_properties(only_existing=False)

        additional_recipient_properties = {
            'ogg.recipient.contact.title': u'M\xfcller Peter',
            'ogg.recipient.person.firstname': 'Peter',
            'ogg.recipient.person.lastname': u'M\xfcller',
            'ogg.recipient.address.street': u'Musterstrasse 283',
            'ogg.recipient.address.zip_code': '1234',
            'ogg.recipient.address.city': 'Hinterkappelen',
            'ogg.recipient.address.country': 'Schweiz',
            }

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertDictContainsSubset(
                additional_recipient_properties,
                dict(properties),
                )
コード例 #4
0
    def test_properties_can_be_added_to_file_without_properties(self):
        self.document = create(
            Builder('document')
            .within(self.dossier)
            .titled("My Document")
            .having(document_date=datetime(2010, 1, 3),
                    document_author=TEST_USER_ID,
                    document_type='contract',
                    receipt_date=datetime(2010, 1, 3),
                    delivery_date=datetime(2010, 1, 3))
            .with_asset_file('without_custom_properties.docx'))

        writer = DocPropertyWriter(self.document)
        writer.update_doc_properties(only_existing=False)
        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(EXPECTED_DOC_PROPERTIES.items(), properties)
コード例 #5
0
    def test_properties_can_be_added_to_file_without_properties(self):
        self.document = create(
            Builder('document').within(
                self.dossier).titled("My Document").having(
                    document_date=datetime(2010, 1, 3),
                    document_author=TEST_USER_ID,
                    document_type='contract',
                    receipt_date=datetime(2010, 1, 3),
                    delivery_date=datetime(
                        2010, 1,
                        3)).with_asset_file('without_custom_properties.docx'))

        writer = DocPropertyWriter(self.document)
        writer.update_doc_properties(only_existing=False)
        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(EXPECTED_DOC_PROPERTIES.items(), properties)
コード例 #6
0
    def test_files_with_custom_properties_are_not_updated(self):
        self.document = create(
            Builder('document')
            .within(self.dossier)
            .titled("Document with custom props")
            .with_asset_file('with_custom_properties.docx'))

        expected_doc_properties = [('Test', 'Peter',)]

        writer = DocPropertyWriter(self.document)
        writer.update_doc_properties(only_existing=True)
        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(expected_doc_properties, properties)

        self.assertEqual(1, get_journal_length(self.document))
        entry = get_journal_entry(self.document)
        self.assertNotEqual(entry['action']['type'], DOC_PROPERTIES_UPDATED)
コード例 #7
0
    def test_writes_additional_recipient_property_providers(self):
        self.document = create(
            Builder('document')
            .within(self.dossier)
            .titled("My Document")
            .having(document_date=datetime(2010, 1, 3),
                    document_author=TEST_USER_ID,
                    document_type='contract',
                    receipt_date=datetime(2010, 1, 3),
                    delivery_date=datetime(2010, 1, 3))
            .with_asset_file('without_custom_properties.docx'))

        peter = create(Builder('person')
                       .having(firstname=u'Peter',
                               lastname=u'M\xfcller'))
        address = create(Builder('address')
                         .for_contact(peter)
                         .labeled(u'Home')
                         .having(street=u'Musterstrasse 283',
                                 zip_code=u'1234',
                                 city=u'Hinterkappelen',
                                 country=u'Schweiz'))

        writer = DocPropertyWriter(
            self.document, recipient_data=(peter, address))
        writer.update_doc_properties(only_existing=False)

        additional_recipient_properties = {
            'ogg.recipient.contact.title': u'M\xfcller Peter',
            'ogg.recipient.person.firstname': 'Peter',
            'ogg.recipient.person.lastname': u'M\xfcller',
            'ogg.recipient.address.street': u'Musterstrasse 283',
            'ogg.recipient.address.zip_code': '1234',
            'ogg.recipient.address.city': 'Hinterkappelen',
            'ogg.recipient.address.country': 'Schweiz',
        }

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(
                EXPECTED_DOC_PROPERTIES.items() +
                additional_recipient_properties.items(),
                properties)
コード例 #8
0
    def test_files_with_custom_properties_are_not_updated(self):
        self.document = create(
            Builder('document').within(
                self.dossier).titled("Document with custom props").
            with_asset_file('with_custom_properties.docx'))

        expected_doc_properties = [(
            'Test',
            'Peter',
        )]

        writer = DocPropertyWriter(self.document)
        writer.update_doc_properties(only_existing=True)
        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(expected_doc_properties, properties)

        self.assertEqual(1, get_journal_length(self.document))
        entry = get_journal_entry(self.document)
        self.assertNotEqual(entry['action']['type'], DOC_PROPERTIES_UPDATED)
コード例 #9
0
    def test_writes_additional_recipient_property_providers(self):
        self.document = create(
            Builder('document').within(
                self.dossier).titled("My Document").having(
                    document_date=datetime(2010, 1, 3),
                    document_author=TEST_USER_ID,
                    document_type='contract',
                    receipt_date=datetime(2010, 1, 3),
                    delivery_date=datetime(
                        2010, 1,
                        3)).with_asset_file('without_custom_properties.docx'))

        peter = create(
            Builder('person').having(firstname=u'Peter',
                                     lastname=u'M\xfcller'))
        address = create(
            Builder('address').for_contact(peter).labeled(u'Home').having(
                street=u'Musterstrasse 283',
                zip_code=u'1234',
                city=u'Hinterkappelen',
                country=u'Schweiz'))

        writer = DocPropertyWriter(self.document,
                                   recipient_data=(peter, address))
        writer.update_doc_properties(only_existing=False)

        additional_recipient_properties = {
            'ogg.recipient.contact.title': u'M\xfcller Peter',
            'ogg.recipient.person.firstname': 'Peter',
            'ogg.recipient.person.lastname': u'M\xfcller',
            'ogg.recipient.address.street': u'Musterstrasse 283',
            'ogg.recipient.address.zip_code': '1234',
            'ogg.recipient.address.city': 'Hinterkappelen',
            'ogg.recipient.address.country': 'Schweiz',
        }

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(
                EXPECTED_DOC_PROPERTIES.items() +
                additional_recipient_properties.items(), properties)
コード例 #10
0
    def test_doc_property_writer_creates_initial_version(self):
        self.activate_feature('doc-properties')
        self.login(self.dossier_responsible)

        versioner = Versioner(self.document)
        self.assertFalse(versioner.has_initial_version())

        DocPropertyWriter(self.document).update_doc_properties(only_existing=False)

        self.assertTrue(versioner.has_initial_version())
        self.assertEquals(
            1, versioner.get_history_metadata().getLength(countPurged=False))
コード例 #11
0
    def test_properties_can_be_added_to_file_without_properties(self):
        self.login(self.regular_user)
        self.with_asset_file('without_custom_properties.docx')

        (
            DocPropertyWriter(self.document)
            .update_doc_properties(only_existing=False)
            )

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(EXPECTED_DOC_PROPERTIES.items(), properties)
コード例 #12
0
    def test_document_with_content_controls_gets_updated(self):
        self.login(self.regular_user)
        self.with_asset_file('content_controls.docx')

        prop_writer = DocPropertyWriter(self.document)
        prop_writer.update_doc_properties(True)

        expected_properties = {
            'ogg.document.document_date': '03.01.2010',
            'ogg.document.reference_number': u'Client1 1.1 / 1 / 14',
            'ogg.document.title': u'Vertr\xe4gsentwurf',
            'ogg.document.version_number': '0',
            'ogg.dossier.title': u'Vertr\xe4ge mit der kantonalen Finanzverwaltung',
        }

        content_control_properties = {}
        with TemporaryDocFile(self.document.file) as tmpfile:
            doc = Document(tmpfile.path)
            sdt = StructuredDocumentTags(doc)
            for key, value in expected_properties.items():
                content_control_properties[key] = sdt.get_text(key)
        self.assertEqual(content_control_properties, expected_properties)
コード例 #13
0
    def test_document_with_gever_properties_is_updated_with_all_properties(
            self,
        ):
        self.login(self.regular_user)
        self.with_asset_file('with_gever_properties.docx')

        (
            DocPropertyWriter(self.document)
            .update_doc_properties(only_existing=True)
            )

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(EXPECTED_DOC_PROPERTIES.items(), properties)
コード例 #14
0
    def execute(self):
        obj = super(CreateDocumentFromTemplateCommand, self).execute()
        DocPropertyWriter(obj, recipient_data=self.recipient_data).initialize()

        # Set blocking of role inheritance based on the template object
        if self.block_role_inheritance is not None:
            obj.__ac_local_roles_block__ = self.block_role_inheritance

        # Copy the local roles assignations over from the template
        if self.role_assignments is not None:
            manager = RoleAssignmentManager(obj)
            # Passing an empty iterable in here creates an empty mapping
            manager.add_or_update_assignments(self.role_assignments)
        return obj
コード例 #15
0
def _update_docproperties(document, raise_on_error=False):
    try:
        DocPropertyWriter(document).update()
    except Exception as exc:
        if not raise_on_error:
            path = '/'.join(document.getPhysicalPath())
            logger.warn('Failed to update DocProperties for %r' % path)
            logger.warn('\n%s' % format_exc(exc))
            logger.warn('Updating of DocProperties has therefore been skipped')
            log_msg_to_sentry('DocProperties update skipped',
                              level='warning',
                              extra={'document_that_failed': repr(document)})
            return

        raise
コード例 #16
0
    def test_overwrites_properties_of_wrong_type(self):
        self.login(self.regular_user)
        self.with_asset_file('with_property_of_wrong_type.docx')

        (
            DocPropertyWriter(self.document)
            .update_doc_properties(only_existing=False)
            )

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = dict(read_properties(tmpfile.path))
            self.assertEqual(
                datetime(2010, 1, 3),
                properties['ogg.document.document_date'],
                )
コード例 #17
0
    def test_bumblebee_checksum_updated_when_document_modified(self):
        self.login(self.dossier_responsible)

        pre_update_checksum = IBumblebeeDocument(self.document).get_checksum()

        DocPropertyWriter(
            self.document).update_doc_properties(only_existing=False)

        post_update_checksum = IBumblebeeDocument(self.document).get_checksum()
        self.assertEqual(
            post_update_checksum,
            IBumblebeeDocument(self.document).update_checksum(),
            "Cached checksum and freshly calculated checksums must match.")
        self.assertNotEqual(
            pre_update_checksum, post_update_checksum,
            "Expected bumblebee checksum to change when the document has been "
            "modified")
コード例 #18
0
    def test_files_with_custom_properties_are_not_updated(self):
        self.login(self.regular_user)
        self.with_asset_file('with_custom_properties.docx')

        expected_doc_properties = [('Test', 'Peter',)]

        (
            DocPropertyWriter(self.document)
            .update_doc_properties(only_existing=True)
            )

        with TemporaryDocFile(self.document.file) as tmpfile:
            properties = read_properties(tmpfile.path)
            self.assertItemsEqual(expected_doc_properties, properties)

        self.assertEqual(1, get_journal_length(self.document))

        entry = get_journal_entry(self.document)

        self.assertNotEqual(entry['action']['type'], DOC_PROPERTIES_UPDATED)
コード例 #19
0
 def writer(self):
     return DocPropertyWriter(self.document)
コード例 #20
0
ファイル: command.py プロジェクト: lukasgraf/opengever.core
 def execute(self):
     obj = super(CreateDocumentFromTemplateCommand, self).execute()
     DocPropertyWriter(obj, recipient_data=self.recipient_data).initialize()
     return obj
コード例 #21
0
def _update_docproperties(document):
    DocPropertyWriter(document).update()
コード例 #22
0
 def set_document_property_referencenumber(self):
     DocPropertyWriter(self.doc_with_gever_properties).write_properties(
         False, {'Dossier.ReferenceNumber': 'ClientXY / 42'})
コード例 #23
0
    def test_export_is_enabled_when_feature_is_enabled(self):
        self.login(self.regular_user)

        self.assertTrue(DocPropertyWriter(self.document).is_export_enabled())