示例#1
0
    def test_can_export_zip(self, browser):
        dossier = create(Builder('dossier').titled(u'Dossier'))

        task = create(
            Builder("task").within(dossier).titled(u'Aufgabe').having(
                text='Text blabla',
                task_type='comment',
                deadline=datetime(2010, 1, 1),
                issuer=TEST_USER_ID,
                responsible=TEST_USER_ID,
            ))

        document = create(
            Builder('document').titled(u'Some document').within(
                task).with_dummy_content())

        data = {
            'zip_selected:method': 1,
            'paths:list': ['/'.join(document.getPhysicalPath())]
        }

        browser.login().open(task, view='zip_export')

        zipfile = ZipFile(StringIO(browser.contents), 'r')

        self.assertEquals([document.file.filename], zipfile.namelist())

        browser.open(task, data=data)

        zipfile = ZipFile(StringIO(browser.contents), 'r')

        self.assertEquals([document.file.filename], zipfile.namelist())
    def test_zip_export_generate_protocol_if_outdated(self, browser):
        self.login(self.committee_responsible, browser)

        browser.open(self.meeting, view='export-meeting-zip')
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertIn('Protocol-9. Sitzung der Rechnungsprufungskommission.docx',
                      zip_file.namelist())

        browser.open(self.meeting, view='edit-meeting')
        browser.fill({'Title': 'New Meeting Title'}).save()

        browser.open(self.meeting, view='export-meeting-zip')
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertIn('Agendaitem list-New Meeting Title.docx',
                      zip_file.namelist())
    def test_zip_export_agenda_items_list(self, browser):
        self.proposal_a = create(
            Builder('proposal')
            .titled(u'Proposal A')
            .within(self.dossier)
            .as_submitted()
            .having(committee=self.committee.load_model())
        )

        meeting = create(
            Builder('meeting')
            .having(committee=self.committee.load_model(),
                    start=self.localized_datetime(2013, 1, 1, 8, 30),
                    end=self.localized_datetime(2013, 1, 1, 10, 30),
                    location='There',
                    presidency=self.hugo,
                    participants=[self.peter,
                                  self.hans,
                                  self.roland],
                    secretary=self.sile)
            .scheduled_proposals([self.proposal_a, ])
            .link_with(self.meeting_dossier))

        browser.login().open(meeting.get_url(view='zipexport'))
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertIn('Agendaitem list-community-meeting.docx',
                      zip_file.namelist())
示例#4
0
    def test_write_file_stream(self):
        with NamedTemporaryFile(prefix="plone_zipexport_") as tmp_zip_file:
            with ZipFile(tmp_zip_file.name, "w") as zip_file:
                sio = StringIO("test")
                zip_file.writefile(sio, "teststream.txt")

                self.assertEquals(['teststream.txt'], zip_file.namelist())
    def test_zip_export_link_on_meeting_view(self, browser):
        meeting = create(
            Builder('meeting')
            .having(committee=self.committee.load_model(),
                    start=self.localized_datetime(2013, 1, 1, 8, 30),
                    end=self.localized_datetime(2013, 1, 1, 10, 30),
                    location='There',
                    presidency=self.hugo,
                    participants=[self.peter,
                                  self.hans,
                                  self.roland],
                    secretary=self.sile)
            .link_with(self.meeting_dossier))

        browser.login().open(meeting.get_url())
        self.assertTrue(browser.css('a.download-zipexport-btn'))
        self.assertEquals(
            'Export as Zip',
            browser.css('.item.zip-download > .title').first.text)

        browser.css('a.download-zipexport-btn').first.click()
        zip_file = ZipFile(StringIO(browser.contents), 'r')

        self.assertIsNone(zip_file.testzip(),
                          'Got a invalid zip file.')
        self.assertEquals(
            'Community meeting.zip',
            cgi.parse_header(browser.headers['content-disposition'])[1]['filename'],
            'Wrong zip filename.')
示例#6
0
 def test_directory_tree_gets_builded_correctly_in_zip(self):
     self.browser.open("%s/zip_export" % self.superfolder.absolute_url())
     zipfile = ZipFile(StringIO(self.browser.contents), 'r')
     self.assertEquals([
         'SUPERFILE', 'Folder/testdata.txt', 'Folder/moretest.data',
         u'Empty f\xf6lder/'
     ], zipfile.namelist())
    def test_zip_export_generated_protocol(self, browser):
        meeting = create(
            Builder('meeting')
            .having(committee=self.committee.load_model(),
                    start=self.localized_datetime(2013, 1, 1, 8, 30),
                    end=self.localized_datetime(2013, 1, 1, 10, 30),
                    location='There',
                    presidency=self.hugo,
                    participants=[self.peter,
                                  self.hans,
                                  self.roland],
                    secretary=self.sile)
            .link_with(self.meeting_dossier))

        # Add new protocol
        browser.login().visit(meeting.get_url())
        browser.css('a[href*="@@generate_protocol"]').first.click()
        browser.open(meeting.get_url(view='zipexport'))

        zip_file = ZipFile(StringIO(browser.contents), 'r')
        meeting = Meeting.query.get(meeting.meeting_id)

        self.assertTrue(meeting.has_protocol_document())
        self.assertIn('Protocol-Community meeting.docx',
                      zip_file.namelist())
 def test_zip_export_generate_protocol_if_there_is_none(self, browser):
     self.login(self.committee_responsible, browser)
     browser.open(self.meeting, view='export-meeting-zip')
     zip_file = ZipFile(StringIO(browser.contents), 'r')
     self.assertFalse(self.meeting.model.has_protocol_document())
     self.assertIn('Protocol-9. Sitzung der Rechnungsprufungskommission.docx',
                   zip_file.namelist())
 def test_zip_export_agenda_items_list(self, browser):
     self.login(self.committee_responsible, browser)
     browser.open(self.meeting, view='export-meeting-zip')
     zip_file = ZipFile(StringIO(browser.contents), 'r')
     self.assertIn(
         'Agendaitem list-9. Sitzung der Rechnungsprufungskommission.docx',
         zip_file.namelist())
    def test_filename_conflicts_are_avoided_by_prefixing_attachment_number(self, browser):
        set_preferred_language(self.portal.REQUEST, 'de-ch')
        browser.append_request_header('Accept-Language', 'de-ch')
        self.login(self.committee_responsible, browser)

        documents = [
            create(Builder('document')
                   .within(self.dossier)
                   .titled('The same title')
                   .with_dummy_content())
            for i in range(3)]
        proposal, submitted_proposal = create(Builder('proposal')
                          .within(self.dossier)
                          .having(committee=self.committee.load_model())
                          .with_submitted()
                          .relate_to(*documents))
        self.schedule_proposal(self.meeting, submitted_proposal)

        browser.open(self.meeting, view='export-meeting-zip')
        self.assertEquals('application/zip', browser.contenttype)
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        meeting_json = json.loads(zip_file.read('meeting.json'))

        expected_file_names = [u'Traktandum 1/Beilage/1_The same title.doc',
                               u'Traktandum 1/Beilage/2_The same title.doc',
                               u'Traktandum 1/Beilage/3_The same title.doc']
        json_file_names = [attachment.get("file") for attachment in
                           meeting_json["meetings"][0]['agenda_items'][0]["attachments"]]

        self.assertItemsEqual(expected_file_names, json_file_names)

        expected_file_names.extend(['meeting.json', 'Traktandum 1/Fooo.docx'])

        file_names = zip_file.namelist()
        self.assertItemsEqual(expected_file_names, file_names)
    def test_zip_export_excerpt_is_not_exported(self, browser):
        excerpt = create(Builder('document')
                         .titled(u'Excerpt')
                         .attach_file_containing(u"excerpt",
                                                 u"excerpt.docx")
                         .within(self.dossier))

        generated_excerpt = create(Builder('generated_excerpt')
                                   .for_document(excerpt))
        # restore session by refreshing instance
        generated_excerpt = GeneratedExcerpt.get(generated_excerpt.document_id)

        meeting = create(
            Builder('meeting')
            .having(committee=self.committee.load_model(),
                    start=self.localized_datetime(2013, 1, 1, 8, 30),
                    end=self.localized_datetime(2013, 1, 1, 10, 30),
                    location='There',
                    presidency=self.hugo,
                    participants=[self.peter,
                                  self.hans,
                                  self.roland],
                    secretary=self.sile,
                    excerpt_documents=[generated_excerpt], )
            .link_with(self.meeting_dossier))

        browser.login().open(meeting.get_url(view='zipexport'))
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertNotIn('excerpt.docx', zip_file.namelist())
示例#12
0
 def test_zip_selected_files(self):
     postdata = "zip_selected:method=1&paths:list=%s&paths:list=%s" % (
         '/'.join(self.folderfile.getPhysicalPath()), '/'.join(
             self.folderfile2.getPhysicalPath()))
     self.browser.open(self.superfolder.absolute_url(), postdata)
     zipfile = ZipFile(StringIO(self.browser.contents), 'r')
     self.assertEquals(['testdata.txt', 'moretest.data'],
                       zipfile.namelist())
示例#13
0
 def test_zip_export_agenda_items_attachments(self, browser):
     self.login(self.committee_responsible, browser)
     self.schedule_proposal(self.meeting, self.submitted_proposal)
     browser.open(self.meeting, view='export-meeting-zip')
     zip_file = ZipFile(StringIO(browser.contents), 'r')
     self.assertIn(
         '1. Vertragsentwurf fur weitere Bearbeitung bewilligen/Vertragsentwurf.docx',
         zip_file.namelist())
 def test_export_proposal_word_documents(self, browser):
     self.login(self.committee_responsible, browser)
     self.schedule_proposal(self.meeting, self.submitted_word_proposal)
     browser.open(self.meeting, view='export-meeting-zip')
     zip_file = ZipFile(StringIO(browser.contents), 'r')
     self.assertIn(
         '1. Anderungen am Personalreglement/Anderungen am Personalreglement.docx',
         zip_file.namelist())
 def test_export_proposal_word_documents(self, browser):
     browser.append_request_header('Accept-Language', 'de-ch')
     self.login(self.committee_responsible, browser)
     self.schedule_proposal(self.meeting, self.submitted_proposal)
     browser.open(self.meeting, view='export-meeting-zip')
     zip_file = ZipFile(StringIO(browser.contents), 'r')
     self.assertIn(
         'Traktandum 1/Vertraege.docx',
         zip_file.namelist())
    def test_exported_meeting_contains_json(self, browser):
        self.login(self.committee_responsible, browser)
        browser.open(self.meeting, view='export-meeting-zip')
        self.assertEquals('application/zip', browser.contenttype)

        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertEquals(
            ['meeting.json'],
            zip_file.namelist())
示例#17
0
    def test_zip_export_includes_generated_protocol(self, browser):
        self.login(self.committee_responsible, browser)
        browser.open(GenerateProtocol.url_for(self.meeting.model))
        self.assertTrue(self.meeting.model.has_protocol_document())

        browser.open(self.meeting, view='export-meeting-zip')
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertIn('Protocol-9. Sitzung der Rechnungsprufungskommission.docx',
                      zip_file.namelist())
示例#18
0
    def test_write_normal_file(self):
        with NamedTemporaryFile(prefix="plone_zipexport_") as tmp_test_file:
            test_file = open(tmp_test_file.name, "w")
            test_file.write("Testdata.")
            with NamedTemporaryFile(prefix="plone_zipexport_") as tmp_zip_file:
                with ZipFile(tmp_zip_file.name, "w") as zip_file:
                    zip_file.writefile(test_file, "testfile.txt")

                    self.assertEquals(['testfile.txt'], zip_file.namelist())
    def test_exported_meeting_contains_json(self, browser):
        self.login(self.committee_responsible, browser)
        browser.open(self.meeting, view='export-meeting-zip')
        self.assertEquals('application/zip', browser.contenttype)

        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertEquals(
            ['Protocol-9. Sitzung der Rechnungsprufungskommission.docx',
             'Agendaitem list-9. Sitzung der Rechnungsprufungskommission.docx',
             'meeting.json'],
            zip_file.namelist())
示例#20
0
    def test_can_export_zip(self, browser):
        self.login(self.regular_user, browser=browser)

        browser.open(self.task, view='zip_export')
        zipfile = ZipFile(StringIO(browser.contents), 'r')

        self.assertEquals([
            u'Task - Rechtliche Grundlagen in Vertragsentwurf \xdcberpr\xfcfen/',
            'feedback-zum-vertragsentwurf.docx'
        ], zipfile.namelist())

        data = {
            'zip_selected:method': 1,
            'paths:list': ['/'.join(self.taskdocument.getPhysicalPath())]
        }
        browser.open(self.task, data=data)

        zipfile = ZipFile(StringIO(browser.contents), 'r')
        self.assertEquals([self.taskdocument.file.filename],
                          zipfile.namelist())
示例#21
0
    def test_smoke_debug_docxcompose(self, browser):
        self.login(self.manager, browser)

        self.schedule_proposal(self.meeting, self.submitted_word_proposal)
        self.schedule_ad_hoc(self.meeting, "Foo")
        self.schedule_paragraph(self.meeting, "Bar")

        browser.open(self.meeting, view='debug_docxcompose')
        zip_file = ZipFile(StringIO(browser.contents), 'r')

        self.assertIsNone(zip_file.testzip(), 'Got a invalid zip file.')
示例#22
0
    def test_exclude_empty_folders_if_setting_is_deactivated(self):
        registry = getUtility(IRegistry)
        registry.forInterface(IZipExportSettings).include_empty_folders = False

        transaction.commit()

        self.browser.open("%s/zip_export" % self.superfolder.absolute_url())
        zipfile = ZipFile(StringIO(self.browser.contents), 'r')
        self.assertEquals(
            ['SUPERFILE', 'Folder/testdata.txt', 'Folder/moretest.data'],
            zipfile.namelist())
示例#23
0
    def test_zip_selected_files(self, browser):
        self.login(self.regular_user, browser=browser)

        docs = [self.document, self.subdocument]
        data = {'zip_selected:method': 1}
        data.update(self.make_path_param(*docs))
        # /plone/ordnungssystem/...

        browser.open(self.dossier, data=data)

        zipfile = ZipFile(StringIO(browser.contents), 'r')
        self.assertEquals([doc.file.filename for doc in docs],
                          zipfile.namelist())
示例#24
0
    def test_smoke_debug_excerpt_docxcompose(self, browser):
        self.login(self.manager, browser)

        agenda_1 = self.schedule_proposal(self.meeting,
                                          self.submitted_proposal)
        agenda_2 = self.schedule_ad_hoc(self.meeting, "Foo")
        agenda_paragraph = self.schedule_paragraph(self.meeting, "Bar")

        browser.open(
            self.agenda_item_url(agenda_1, 'debug_excerpt_docxcompose'))
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertIsNone(zip_file.testzip(), 'Got a invalid zip file.')

        browser.open(
            self.agenda_item_url(agenda_2, 'debug_excerpt_docxcompose'))
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertIsNone(zip_file.testzip(), 'Got a invalid zip file.')

        with browser.expect_http_error(404):
            browser.open(
                self.agenda_item_url(agenda_paragraph,
                                     'debug_excerpt_docxcompose'))
    def test_zip_export_link_on_meeting_view(self, browser):
        self.login(self.committee_responsible, browser)
        browser.open(self.meeting)
        editbar.menu_option('Actions', 'Export as Zip').click()

        zip_file = ZipFile(StringIO(browser.contents), 'r')

        self.assertIsNone(zip_file.testzip(),
                          'Got a invalid zip file.')
        self.assertEquals(
            '9. Sitzung der Rechnungsprufungskommission.zip',
            cgi.parse_header(browser.headers['content-disposition'])[1]['filename'],
            'Wrong zip filename.')
    def test_excerpt_is_not_exported(self, browser):
        browser.append_request_header('Accept-Language', 'de-ch')
        self.login(self.committee_responsible, browser)
        agenda_item = self.schedule_proposal(self.meeting,
                                             self.submitted_proposal)
        agenda_item.decide()
        agenda_item.generate_excerpt(title='Ahoi McEnroe!')

        browser.open(self.meeting, view='export-meeting-zip')
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertItemsEqual(
            ['Traktandum 1/Beilage/1_Vertraegsentwurf.docx',
             'Traktandum 1/Vertraege.docx',
             'meeting.json'],
            zip_file.namelist())
    def test_zip_export_skips_agenda_items_attachments_without_file(self, browser):
        browser.append_request_header('Accept-Language', 'de-ch')
        self.login(self.committee_responsible, browser)

        self.proposal.submit_additional_document(self.empty_document)
        self.proposal.submit_additional_document(self.subdocument)
        self.schedule_proposal(self.meeting, self.submitted_proposal)

        browser.open(self.meeting, view='export-meeting-zip')
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertItemsEqual(
            ['Traktandum 1/Vertraege.docx',
             'Traktandum 1/Beilage/1_Vertraegsentwurf.docx',
             'Traktandum 1/Beilage/2_Uebersicht der Vertraege von 2016.xlsx',
             'meeting.json'],
            zip_file.namelist())
    def test_excerpt_is_not_exported(self, browser):
        self.login(self.committee_responsible, browser)
        agenda_item = self.schedule_proposal(self.meeting,
                                             self.submitted_word_proposal)
        agenda_item.decide()
        agenda_item.generate_excerpt(title='Ahoi McEnroe!')

        browser.open(self.meeting, view='export-meeting-zip')
        zip_file = ZipFile(StringIO(browser.contents), 'r')
        self.assertEquals(
            ['Protocol-9. Sitzung der Rechnungsprufungskommission.docx',
             '1. Anderungen am Personalreglement/Vertragsentwurf.docx',
             '1. Anderungen am Personalreglement/Anderungen am Personalreglement.docx',
             'Agendaitem list-9. Sitzung der Rechnungsprufungskommission.docx',
             'meeting.json'],
            zip_file.namelist())
示例#29
0
    def test_zip_export_link_on_meeting_view(self, browser):
        self.login(self.committee_responsible, browser)
        browser.open(self.meeting)
        self.assertTrue(browser.css('a.download-zipexport-btn'))
        self.assertEquals(
            'Export as Zip',
            browser.css('.item.zip-download > .title').first.text)

        browser.css('a.download-zipexport-btn').first.click()
        zip_file = ZipFile(StringIO(browser.contents), 'r')

        self.assertIsNone(zip_file.testzip(),
                          'Got a invalid zip file.')
        self.assertEquals(
            '9. Sitzung der Rechnungsprufungskommission.zip',
            cgi.parse_header(browser.headers['content-disposition'])[1]['filename'],
            'Wrong zip filename.')
    def test_zip_export_generate_protocol_if_outdated(self, browser):
        protocol = create(Builder('document')
                          .titled(u'Protocol')
                          .attach_file_containing(u"protocol",
                                                  u"protocol.docx")
                          .within(self.dossier))

        generated_protocol = create(Builder('generated_protocol')
                                    .for_document(protocol))

        meeting = create(
            Builder('meeting')
            .having(committee=self.committee.load_model(),
                    start=self.localized_datetime(2013, 1, 1, 8, 30),
                    end=self.localized_datetime(2013, 1, 1, 10, 30),
                    location='There',
                    presidency=self.hugo,
                    participants=[self.peter,
                                  self.hans,
                                  self.roland],
                    secretary=self.sile,
                    protocol_document=generated_protocol)
            .link_with(self.meeting_dossier))

        # Do a modification
        browser.login().open(meeting.get_url(view='protocol'))
        browser.fill({'Title': u'This is the modified different title than '
                               u'before'}).submit()
        browser.open(meeting.get_url(view='zipexport'))

        zip_file = ZipFile(StringIO(browser.contents), 'r')

        self.assertNotEquals(protocol.file.filename,
                             zip_file.filelist[0].filename)
        self.assertNotEquals(protocol.file.getSize(),
                             zip_file.filelist[0].file_size)
        self.assertIn('Protocol-This is the modified different title than'
                      ' before.docx',
                      zip_file.namelist())