コード例 #1
0
    def test_binary_file_uploading(self, browser):
        browser.login(SITE_OWNER_NAME).open()
        factoriesmenu.add('File')

        with asset('file.pdf') as pdf:
            browser.fill({'Title': 'The PDF',
                          'File': pdf}).submit()

        browser.find('file.pdf').click()
        self.assert_file_metadata(filename='file.pdf',
                                  content_type='application/pdf',
                                  browser=browser)

        with asset('file.pdf') as pdf:
            self.assertTrue(pdf.read().strip() == browser.contents.strip(),
                            'The PDF was changed when uploaded!')
コード例 #2
0
    def test_upload_unicode(self, browser):
        browser.login(SITE_OWNER_NAME).open()
        factoriesmenu.add('File')

        with asset('cities-utf8.xml') as pdf:
            browser.fill({'Title': u'Hall\xf6chen',
                          'File': pdf}).save()

        statusmessages.assert_no_error_messages()
コード例 #3
0
    def test_filling_image_upload_widget_by_label(self, browser):
        browser.login(SITE_OWNER_NAME).open()
        factoriesmenu.add('Image')

        with asset('mario.gif') as mario:
            browser.fill({'Image': (mario.read(), 'mario.gif')}).save()
        statusmessages.assert_message('Item created')

        browser.open(browser.context, view='@@images/image.gif')
        self.assertEquals('image/gif', browser.headers.get('Content-Type'))
コード例 #4
0
    def test_filling_image_upload_widget_by_label(self, browser):
        browser.login(SITE_OWNER_NAME).open()
        factoriesmenu.add('Image')

        with asset('mario.gif') as mario:
            browser.fill({'Image': (mario.read(), 'mario.gif')}).submit()

        browser.find('Download').click()
        self.assertEquals('attachment; filename="mario.gif"',
                          browser.headers.get('Content-Disposition'))
        self.assertEquals('image/gif',
                          browser.headers.get('Content-Type'))
コード例 #5
0
    def test_requests_library_file_uploads(self):
        with Browser() as browser:
            browser.login(SITE_OWNER_NAME).open(
                view='createObject?type_name=File')
            with asset('helloworld.py') as helloworld:
                browser.fill({'Title': 'Hello World',
                              'File': helloworld}).submit()

            browser.find('helloworld.py').click()
            self.assert_file_download('print "Hello World"\n',
                                      filename='helloworld.py',
                                      content_type='text/x-python',
                                      browser=browser)
コード例 #6
0
    def test_filesystem_file_uploading(self, browser):
        browser.login(SITE_OWNER_NAME).open()
        factoriesmenu.add('File')

        with asset('helloworld.py') as helloworld:
            browser.fill({'Title': 'Hello World',
                          'File': helloworld}).submit()

        browser.find('helloworld.py').click()
        self.assert_file_download('print "Hello World"\n',
                                  filename='helloworld.py',
                                  content_type='text/x-python',
                                  browser=browser)
コード例 #7
0
    def test_remove_cropped_image_if_main_image_has_changed(self, browser):
        page = create(Builder('sl content page'))
        block = create(Builder('sl textblock').within(page)
                       .with_cropped_image())

        self.assertIsNotNone(block.cropped_image)

        browser.login().visit(block, view='edit.json')
        browser.parse(browser.json['content'])

        with asset('mario.gif') as mario:
            browser.fill({'Image': (mario.read(), 'mario.gif')}).save()

        self.assertIsNone(block.cropped_image)