def test_updating_agendaitem_list_updates_docproperties(self, browser): self.login(self.committee_responsible, browser) browser.open(self.meeting) meeting = self.meeting.model browser.css('.document-actions .action.generate').first.click() self.assertIsNotNone(meeting.agendaitem_list_document) document = meeting.agendaitem_list_document.oguid.resolve_object() with TemporaryDocFile(document.file) as tmpfile: properties = dict(CustomProperties(Document(tmpfile.path)).items()) self.assertEqual('Sitzungsdossier 9/2017', properties['ogg.dossier.title']) # change dossier title self.meeting_dossier.title = u'New dossier title' # update agendaitem list browser.css('.document-actions .action.generate').first.click() document = meeting.agendaitem_list_document.oguid.resolve_object() with TemporaryDocFile(document.file) as tmpfile: properties = dict(CustomProperties(Document(tmpfile.path)).items()) self.assertEqual(u'New dossier title', properties['ogg.dossier.title'])
def test_moving_documents_updates_doc_properties(self): api.content.move(source=self.doc_with_gever_properties, target=self.target_dossier) moved_doc = self.target_dossier.getFirstChild() expected_doc_properties = [ ('Document.ReferenceNumber', 'Client1 / 2 / 1'), ('Document.SequenceNumber', '1'), ('Dossier.ReferenceNumber', 'Client1 / 2'), ('Dossier.Title', 'Target'), ('ogg.document.document_date', datetime(2010, 12, 30, 0, 0)), ('ogg.document.reference_number', 'Client1 / 2 / 1'), ('ogg.document.sequence_number', '1'), ('ogg.document.title', 'Document with file'), ('ogg.dossier.reference_number', 'Client1 / 2'), ('ogg.dossier.sequence_number', '2'), ('ogg.dossier.title', 'Target'), ('ogg.user.email', '*****@*****.**'), ('ogg.user.firstname', 'User'), ('ogg.user.lastname', 'Test'), ('ogg.user.title', 'Test User'), ('ogg.user.userid', TEST_USER_ID), ('User.FullName', 'Test User'), ('User.ID', TEST_USER_ID), ] with TemporaryDocFile(moved_doc.file) as tmpfile: properties = read_properties(tmpfile.path) self.assertItemsEqual(expected_doc_properties, properties) self.assert_doc_properties_updated_journal_entry_generated(moved_doc)
def test_document_checkin_updates_doc_properties(self): manager = getMultiAdapter( (self.doc_with_gever_properties, self.request), ICheckinCheckoutManager) manager.checkout() self.set_document_property_referencenumber() manager.checkin() expected_doc_properties = [ ('Document.ReferenceNumber', 'Client1 / 1 / 1'), ('Document.SequenceNumber', '1'), ('Dossier.ReferenceNumber', 'Client1 / 1'), ('Dossier.Title', 'Dossier'), ('ogg.document.document_date', datetime(2010, 12, 30, 0, 0)), ('ogg.document.reference_number', 'Client1 / 1 / 1'), ('ogg.document.sequence_number', '1'), ('ogg.document.title', 'Document with file'), ('ogg.dossier.reference_number', 'Client1 / 1'), ('ogg.dossier.sequence_number', '1'), ('ogg.dossier.title', 'Dossier'), ('ogg.user.email', '*****@*****.**'), ('ogg.user.firstname', 'User'), ('ogg.user.lastname', 'Test'), ('ogg.user.title', 'Test User'), ('ogg.user.userid', TEST_USER_ID), ('User.FullName', 'Test User'), ('User.ID', TEST_USER_ID), ] with TemporaryDocFile(self.doc_with_gever_properties.file) as tmpfile: properties = read_properties(tmpfile.path) self.assertItemsEqual(expected_doc_properties, properties) self.assert_doc_properties_updated_journal_entry_generated( self.doc_with_gever_properties, entry=-2)
def test_copying_dossier_updates_doc_properties_of_contained_document(self, browser): browser.login() browser.open(self.dossier, view='copy_item') browser.open(self.target_dossier, view='tabbed_view') browser.css('#contentActionMenus a#paste').first.click() copied_dossier = self.target_dossier.getFirstChild() copied_doc = copied_dossier.getFirstChild() expected_doc_properties = [ ('Document.ReferenceNumber', 'Client1 / 2.1 / 2'), ('Document.SequenceNumber', '2'), ('Dossier.ReferenceNumber', 'Client1 / 2.1'), ('Dossier.Title', 'Dossier'), ('ogg.document.document_date', datetime(2010, 12, 30, 0, 0)), ('ogg.document.reference_number', 'Client1 / 2.1 / 2'), ('ogg.document.sequence_number', '2'), ('ogg.document.title', 'copy of Document with file'), ('ogg.document.version_number', 0), ('ogg.dossier.reference_number', 'Client1 / 2.1'), ('ogg.dossier.sequence_number', '3'), ('ogg.dossier.title', 'Dossier'), ('ogg.user.email', '*****@*****.**'), ('ogg.user.firstname', 'User'), ('ogg.user.lastname', 'Test'), ('ogg.user.title', 'Test User'), ('ogg.user.userid', TEST_USER_ID), ('User.FullName', 'Test User'), ('User.ID', TEST_USER_ID), ] with TemporaryDocFile(copied_doc.file) as tmpfile: properties = CustomProperties(Document(tmpfile.path)).items() self.assertItemsEqual(expected_doc_properties, properties) self.assert_doc_properties_updated_journal_entry_generated(copied_doc)
def test_ogds_user_recipient_properties_are_added(self, browser): api.portal.set_registry_record('is_feature_enabled', True, interface=IContactSettings) template_word = create( Builder('document').titled('Word Docx template').within( self.templatefolder).with_asset_file( 'without_custom_properties.docx')) ogds_user = create( Builder('ogds_user').id('peter').having( **OGDS_USER_ATTRIBUTES).as_contact_adapter()) with freeze(self.document_date): # submit first wizard step browser.login().open(self.dossier, view='document_with_template') browser.fill({ 'form.widgets.template': _make_token(template_word), 'Title': 'Test Docx' }) form = browser.find_form_by_field('Recipient') form.find_widget('Recipient').fill(get_contacts_token(ogds_user)) form.save() # submit second wizard step browser.fill({ 'form.widgets.address': '{}_1'.format(ogds_user.id), 'form.widgets.mail_address': '{}_2'.format(ogds_user.id), 'form.widgets.phonenumber': '{}_3'.format(ogds_user.id), 'form.widgets.url': '{}_1'.format(ogds_user.id) }).save() document = self.dossier.listFolderContents()[0] self.assertEquals(u'test-docx.docx', document.file.filename) expected_org_role_properties = { 'ogg.recipient.contact.title': u'M\xfcller Peter', 'ogg.recipient.contact.description': u'nix', 'ogg.recipient.person.salutation': 'Prof. Dr.', 'ogg.recipient.person.firstname': 'Peter', 'ogg.recipient.person.lastname': u'M\xfcller', 'ogg.recipient.address.street': u'Kappelenweg 13, Postfach 1234', 'ogg.recipient.address.zip_code': '1234', 'ogg.recipient.address.city': u'Vorkappelen', 'ogg.recipient.address.country': u'Schweiz', 'ogg.recipient.email.address': u'*****@*****.**', 'ogg.recipient.phone.number': u'012 34 56 76', 'ogg.recipient.url.url': u'http://www.example.com', } expected_org_role_properties.update(self.expected_doc_properties) with TemporaryDocFile(document.file) as tmpfile: self.assertItemsEqual(expected_org_role_properties.items(), read_properties(tmpfile.path)) self.assert_doc_properties_updated_journal_entry_generated(document)
def test_properties_are_added_when_created_from_template_without_doc_properties(self, browser): self.login(self.regular_user, browser) with freeze(datetime(2020, 10, 28, 0, 0)): browser.open(self.dossier, view='document_with_template') browser.fill({ 'form.widgets.template': str(getUtility(IIntIds).getId(self.asset_template)), 'Title': 'Test Docx', }).save() document = self.dossier.listFolderContents()[-1] self.assertEquals(u'test-docx.docx', document.file.filename) expected_doc_properties = { 'Document.ReferenceNumber': 'Client1 1.1 / 1 / 27', 'Document.SequenceNumber': '27', 'Dossier.ReferenceNumber': 'Client1 1.1 / 1', 'Dossier.Title': u'Vertr\xe4ge mit der kantonalen Finanzverwaltung', 'User.FullName': u'B\xe4rfuss K\xe4thi', 'User.ID': 'kathi.barfuss', 'ogg.document.document_date': datetime(2020, 10, 28, 0, 0), 'ogg.document.reference_number': 'Client1 1.1 / 1 / 27', 'ogg.document.sequence_number': '27', 'ogg.document.title': 'Test Docx', 'ogg.document.version_number': 0, 'ogg.dossier.reference_number': 'Client1 1.1 / 1', 'ogg.dossier.sequence_number': '1', 'ogg.dossier.title': u'Vertr\xe4ge mit der kantonalen Finanzverwaltung', 'ogg.user.address1': 'Kappelenweg 13', 'ogg.user.address2': 'Postfach 1234', 'ogg.user.city': 'Vorkappelen', 'ogg.user.country': 'Schweiz', 'ogg.user.department': 'Staatskanzlei', 'ogg.user.department_abbr': 'SK', 'ogg.user.description': 'nix', 'ogg.user.directorate': 'Staatsarchiv', 'ogg.user.directorate_abbr': 'Arch', 'ogg.user.email': '*****@*****.**', 'ogg.user.email2': '*****@*****.**', 'ogg.user.firstname': u'K\xe4thi', 'ogg.user.lastname': u'B\xe4rfuss', 'ogg.user.phone_fax': '012 34 56 77', 'ogg.user.phone_mobile': '012 34 56 76', 'ogg.user.phone_office': '012 34 56 78', 'ogg.user.salutation': 'Prof. Dr.', 'ogg.user.title': u'B\xe4rfuss K\xe4thi', 'ogg.user.url': 'http://www.example.com', 'ogg.user.userid': 'kathi.barfuss', 'ogg.user.zip_code': '1234', } with TemporaryDocFile(document.file) as tmpfile: self.assertItemsEqual( expected_doc_properties.items(), read_properties(tmpfile.path)) self.assert_doc_properties_updated_journal_entry_generated(document, self.regular_user)
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_disable_docproperty_updating(self): inbox = create(Builder('inbox')) forwarding = create(Builder('forwarding').within(inbox)) doc = create(Builder('document') .within(forwarding) .titled("Document with file") .with_asset_file('with_gever_user_properties.docx')) IYearfolderStorer(forwarding).store_in_yearfolder() with TemporaryDocFile(doc.file) as tmpfile: properties = dict(read_properties(tmpfile.path)) self.assertItemsEqual(TEST_USER_ID, properties.get('User.ID'))
def test_overwrites_properties_of_wrong_type(self): frozen_date = datetime(2010, 1, 1) with freeze(frozen_date): self.document = create( Builder('document').within( self.dossier).titled("Document with prop of wrong type"). with_asset_file('with_property_of_wrong_type.docx')) with TemporaryDocFile(self.document.file) as tmpfile: self.assertIn(( 'ogg.document.document_date', frozen_date, ), list(read_properties(tmpfile.path)))
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_doc_properties_are_not_created_when_disabled(self, browser): self.login(self.regular_user, browser) with freeze(datetime(2020, 10, 28, 0, 0)): browser.open(self.dossier, view='document_with_template') browser.fill({ 'form.widgets.template': str(getUtility(IIntIds).getId(self.asset_template)), 'Title': 'Test Docx', }).save() document = self.dossier.listFolderContents()[-1] self.assertEquals(u'test-docx.docx', document.file.filename) with TemporaryDocFile(document.file) as tmpfile: self.assertItemsEqual([], read_properties(tmpfile.path))
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'], )
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_doc_properties_are_not_created_when_disabled(self, browser): self.props.create_doc_properties = False template_word = create( Builder('document').titled('Word Docx template').within( self.templatefolder).with_asset_file( 'without_custom_properties.docx')) browser.login().open(self.dossier, view='document_with_template') browser.fill({ 'form.widgets.template': _make_token(template_word), 'Title': 'Test Docx' }).save() document = self.dossier.listFolderContents()[0] self.assertEquals(u'test-docx.docx', document.file.filename) with TemporaryDocFile(document.file) as tmpfile: self.assertItemsEqual([], read_properties(tmpfile.path))
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_are_added_when_created_from_template_without_doc_properties( self, browser): template_word = create( Builder('document').titled('Word Docx template').within( self.templatefolder).with_asset_file( 'without_custom_properties.docx')) with freeze(self.document_date): browser.login().open(self.dossier, view='document_with_template') browser.fill({ 'form.widgets.template': _make_token(template_word), 'Title': 'Test Docx' }).save() document = self.dossier.listFolderContents()[0] self.assertEquals(u'test-docx.docx', document.file.filename) with TemporaryDocFile(document.file) as tmpfile: self.assertItemsEqual(self.expected_doc_properties.items(), read_properties(tmpfile.path)) self.assert_doc_properties_updated_journal_entry_generated(document)
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_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)
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_org_role_recipient_properties_are_added(self, browser): organization = create( Builder('organization') .having(name=u'Meier AG'), ) org_role = create( Builder('org_role') .having( person=self.peter, organization=organization, function=u'cheffe', ), ) create( Builder('address') .for_contact(organization) .labeled(u'Home') .having( street=u'Musterstrasse 283', zip_code=u'1234', city=u'Hinterkappelen', country=u'Schweiz', ), ) mailaddress = create( Builder('mailaddress') .for_contact(organization) .having(address=u'*****@*****.**'), ) phonenumber = create( Builder('phonenumber') .for_contact(self.peter) .having(phone_number=u'1234 123 123'), ) url = create( Builder('url') .for_contact(organization) .having(url=u'http://www.example.com'), ) address_id = org_role.addresses[0].address_id with freeze(self.document_date): # submit first wizard step browser.login().open(self.dossier, view='document_with_template') browser.fill({ 'form.widgets.template': self._make_token(self.template_word), 'Title': 'Test Docx', }) form = browser.find_form_by_field('Recipient') form.find_widget('Recipient').fill(get_contacts_token(org_role)) form.save() # submit second wizard step browser.fill({ 'form.widgets.address': address_id, 'form.widgets.mail_address': str(mailaddress.mailaddress_id), 'form.widgets.phonenumber': str(phonenumber.phone_number_id), 'form.widgets.url': str(url.url_id), }).save() document = self.dossier.listFolderContents()[0] self.assertEquals(u'test-docx.docx', document.file.filename) expected_org_role_properties = { 'ogg.recipient.contact.title': u'M\xfcller Peter', 'ogg.recipient.person.firstname': 'Peter', 'ogg.recipient.person.lastname': u'M\xfcller', 'ogg.recipient.orgrole.function': u'cheffe', 'ogg.recipient.organization.name': u'Meier AG', 'ogg.recipient.address.street': u'Musterstrasse 283', 'ogg.recipient.address.zip_code': '1234', 'ogg.recipient.address.city': 'Hinterkappelen', 'ogg.recipient.address.country': 'Schweiz', 'ogg.recipient.email.address': u'*****@*****.**', 'ogg.recipient.phone.number': u'1234 123 123', 'ogg.recipient.url.url': u'http://www.example.com', } expected_org_role_properties.update(self.expected_doc_properties) with TemporaryDocFile(document.file) as tmpfile: self.assertItemsEqual(expected_org_role_properties.items(), read_properties(tmpfile.path)) self.assert_doc_properties_updated_journal_entry_generated(document)
def test_contact_recipient_properties_are_added(self, browser): api.portal.set_registry_record('is_feature_enabled', True, interface=IContactSettings) template_word = create( Builder('document').titled('Word Docx template').within( self.templatefolder).with_asset_file( 'without_custom_properties.docx')) peter = create( Builder('person').having(firstname=u'Peter', lastname=u'M\xfcller')) address1 = create( Builder('address').for_contact(peter).labeled(u'Home').having( street=u'Musterstrasse 283', zip_code=u'1234', city=u'Hinterkappelen', country=u'Schweiz')) create( Builder('address').for_contact(peter).labeled(u'Home').having( street=u'Hauptstrasse 1', city=u'Vorkappelen')) mailaddress = create( Builder('mailaddress').for_contact(peter).having( address=u'*****@*****.**')) phonenumber = create( Builder('phonenumber').for_contact(peter).having( phone_number=u'1234 123 123')) url = create( Builder('url').for_contact(peter).having( url=u'http://www.example.com')) with freeze(self.document_date): # submit first wizard step browser.login().open(self.dossier, view='document_with_template') browser.fill({ 'form.widgets.template': _make_token(template_word), 'Title': 'Test Docx' }) form = browser.find_form_by_field('Recipient') form.find_widget('Recipient').fill(get_contacts_token(peter)) form.save() # submit second wizard step browser.fill({ 'form.widgets.address': str(address1.address_id), 'form.widgets.mail_address': str(mailaddress.mailaddress_id), 'form.widgets.phonenumber': str(phonenumber.phone_number_id), 'form.widgets.url': str(url.url_id) }).save() document = self.dossier.listFolderContents()[0] self.assertEquals(u'test-docx.docx', document.file.filename) expected_person_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', 'ogg.recipient.email.address': u'*****@*****.**', 'ogg.recipient.phone.number': u'1234 123 123', 'ogg.recipient.url.url': u'http://www.example.com', } expected_person_properties.update(self.expected_doc_properties) with TemporaryDocFile(document.file) as tmpfile: self.assertItemsEqual(expected_person_properties.items(), read_properties(tmpfile.path)) self.assert_doc_properties_updated_journal_entry_generated(document)