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), )
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)
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)
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)
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)
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)
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)
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)