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)
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)
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_document_with_gever_properties_is_updated_with_all_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('with_gever_properties.docx')) self.writer.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)
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_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)