当前位置: 首页>>代码示例>>Python>>正文


Python webtest.Upload方法代码示例

本文整理汇总了Python中webtest.Upload方法的典型用法代码示例。如果您正苦于以下问题:Python webtest.Upload方法的具体用法?Python webtest.Upload怎么用?Python webtest.Upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webtest的用法示例。


在下文中一共展示了webtest.Upload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_import_stock_invalid_csv

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_import_stock_invalid_csv(staffapp, tmpdir):
    source = tmpdir.join('stock.csv')
    source.write(
        'module,name\n'
        'digital,Auriculaire\n'
        )

    response = staffapp.get(reverse('monitoring:stock_import'))
    form = response.forms['import']
    form['source'] = Upload(str(source), source.read_binary(), 'text/csv')
    response = form.submit()
    assert response.status_code == 302
    assert response.location.endswith(reverse('monitoring:stock'))

    response = response.follow()
    assert response.status_code == 200
    assert 'Successfully imported {} elements' not in response.text
    assert 'Missing column "description" on line 1' in response.text
    assert 'Auriculaire' not in response.text

    assert not StockItem.objects.exists() 
开发者ID:ideascube,项目名称:ideascube,代码行数:23,代码来源:test_views.py

示例2: test_guess_kind_when_editing_without_changing_original

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_guess_kind_when_editing_without_changing_original(staffapp):
    assert not Document.objects.count()
    url = reverse('mediacenter:document_create')
    form = staffapp.get(url).forms['model_form']
    form['title'] = 'my document title'
    form['summary'] = 'my document summary'
    form['credits'] = 'my document credits'
    form['original'] = Upload('audio.mp3', b'xxxxxx', 'audio/mpeg')
    form['kind'] = Document.OTHER
    form.submit().follow()

    assert Document.objects.count() == 1
    document = Document.objects.first()
    assert document.kind == Document.AUDIO

    # Now edit again, only resetting the `kind` to 'other'
    url = reverse('mediacenter:document_update', kwargs={'pk': document.pk})
    form = staffapp.get(url).forms['model_form']
    form['kind'] = Document.OTHER
    form.submit().follow()
    assert Document.objects.count() == 1
    assert Document.objects.first().kind == Document.AUDIO 
开发者ID:ideascube,项目名称:ideascube,代码行数:24,代码来源:test_views.py

示例3: test_should_create_users

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_should_create_users(staffapp, monkeypatch):
    data = (b'serial,full_name\n'
            b'12345,Gabriel Garcia Marquez\n'
            b'23456,Miguel de Cervantes')
    form = staffapp.get(reverse('user_import')).forms['import']
    form['source'] = Upload('users.csv', data, 'text/csv')
    response = form.submit()
    response = response.follow()
    assert User.objects.count() == 3  # Two users created plus the staff user.
    response.mustcontain('Successfully processed 2 users.')
    user = User.objects.order_by('pk')[1]
    assert user.serial == '12345'
    assert user.full_name == 'Gabriel Garcia Marquez'
    user = User.objects.order_by('pk')[2]
    assert user.serial == '23456'
    assert user.full_name == 'Miguel de Cervantes' 
开发者ID:ideascube,项目名称:ideascube,代码行数:18,代码来源:test_import_users.py

示例4: test_should_import_boolean

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_should_import_boolean(staffapp, monkeypatch):
    # True/False is how we do export the data, so let's accept this in input
    # too.
    data = (b'serial,full_name,is_sent_to_school\n'
            b'12345,Gabriel Garcia Marquez,True\n'
            b'23456,Miguel de Cervantes,False')
    form = staffapp.get(reverse('user_import')).forms['import']
    form['source'] = Upload('users.csv', data, 'text/csv')
    response = form.submit()
    response.follow()
    assert User.objects.count() == 3
    user = User.objects.order_by('pk')[1]
    assert user.serial == '12345'
    assert user.is_sent_to_school is True
    user = User.objects.order_by('pk')[2]
    assert user.serial == '23456'
    assert user.is_sent_to_school is False 
开发者ID:ideascube,项目名称:ideascube,代码行数:19,代码来源:test_import_users.py

示例5: test_should_not_replace_is_staff

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_should_not_replace_is_staff(staffapp, monkeypatch):
    data = (b'serial,full_name,is_staff\n'
            b'12345,Gabriel Garcia Marquez,True\n'
            b'23456,Miguel de Cervantes,False')
    UserFactory(serial='12345', is_staff=False)
    UserFactory(serial='23456', is_staff=True)
    form = staffapp.get(reverse('user_import')).forms['import']
    form['source'] = Upload('users.csv', data, 'text/csv')
    response = form.submit()
    response.follow()
    user = User.objects.order_by('pk')[1]
    assert user.serial == '12345'
    assert user.full_name == 'Gabriel Garcia Marquez'
    assert user.is_staff is False
    user = User.objects.order_by('pk')[2]
    assert user.is_staff is True
    assert user.full_name == 'Miguel de Cervantes' 
开发者ID:ideascube,项目名称:ideascube,代码行数:19,代码来源:test_import_users.py

示例6: test_import_from_llavedelsaber_format

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_import_from_llavedelsaber_format(staffapp, settings):
    settings.USER_IMPORT_FORMATS = (
        ('llavedelsaber', 'Llave del Saber'),
        ('ideascube', 'Ideascube'),
    )

    # TODO: The format of Llave del Saber exports is not finalized
    data = '\n'.join([
        '"serial";"a_field";"another_field";"a_third_field";"last_field"',
        '"206678478";"";"";"";""',
        '"206678201";"";"";"";""',
    ])

    form = staffapp.get(reverse('user_import')).forms['import']
    form['format'] = 'llavedelsaber'
    form['source'] = Upload('users.csv', data.encode('utf-8'), 'text/csv')
    form.submit(status=302).follow(status=200)

    users = User.objects.all().order_by('serial')
    assert users.count() == 3  # The two imported, plus the staff

    # TODO: Test the other imported fields eventually
    serials = [u.serial for u in users]
    assert serials == ['123456staff', '206678201', '206678478'] 
开发者ID:ideascube,项目名称:ideascube,代码行数:26,代码来源:test_import_users.py

示例7: test_import_from_llavedelsaber_format_invalid_data

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_import_from_llavedelsaber_format_invalid_data(staffapp, settings):
    settings.USER_IMPORT_FORMATS = (
        ('llavedelsaber', 'Llave del Saber'),
        ('ideascube', 'Ideascube'),
    )

    # TODO: The format of Llave del Saber exports is not finalized
    data = '\n'.join([
        '"llave";"a_field";"another_field";"a_third_field";"last_field"',
        '"206678478";"";"";"";""',
        '"206678201";"";"";"";""',
    ])

    form = staffapp.get(reverse('user_import')).forms['import']
    form['format'] = 'llavedelsaber'
    form['source'] = Upload('users.csv', data.encode('utf-8'), 'text/csv')
    response = form.submit(status=302).follow(status=200)
    assert 'Invalid row at line 1: serial missing' in response.text
    assert 'Invalid row at line 2: serial missing' in response.text

    users = User.objects.all()
    assert users.count() == 1  # The staff 
开发者ID:ideascube,项目名称:ideascube,代码行数:24,代码来源:test_import_users.py

示例8: test_import_from_invalid_format

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_import_from_invalid_format(staffapp, settings):
    settings.USER_IMPORT_FORMATS = (
        ('llavedelsaber', 'Llave del Saber'),
        ('ideascube', 'Ideascube'),
    )
    data = 'whatever, this will not be imported'

    form = staffapp.get(reverse('user_import')).forms['import']
    form['format'].force_value('no-such-format')
    form['source'] = Upload('users.csv', data.encode('utf-8'), 'text/csv')
    response = form.submit(status=200)
    assert (
        'Select a valid choice. no-such-format is not one of the available '
        'choices.') in response.text

    users = User.objects.all()
    assert users.count() == 1  # The staff 
开发者ID:ideascube,项目名称:ideascube,代码行数:19,代码来源:test_import_users.py

示例9: test_import_from_ideascube_export

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_import_from_ideascube_export(staffapp, monkeypatch):
    expected = {
        'isbn': '123456',
        'authors': 'Marcel Pagnol',
        'serie': "L'Eau des collines",
        'name': 'Jean de Florette',
        'description': u"Les Bastides Blanches, c'était une paroisse de cent cinquante habitants, perchée sur la proue de l'un des derniers contreforts du massif de l'Étoile, à deux lieues d'Aubagne… Une route de terre y conduisait par une montée si abrupte que de loin elle paraissait verticale : mais du côté des collines il n'en sortait qu'un chemin muletier d'où partaient quelques sentiers qui menaient au ciel.",  # noqa
        'publisher': u'Éditions de Provence',
        'lang': 'fr',
    }
    BookFactory(**expected)
    resp = staffapp.get(reverse('library:book_export'))
    Book.objects.all().delete()
    form = staffapp.get(reverse('library:book_import')).forms['import']
    form['files_format'] = 'ideascube'
    form['from_files'] = Upload('archive.zip', resp.content,
                                'application/zip')
    response = form.submit()
    response.follow()
    assert Book.objects.count()
    book = Book.objects.last()
    for name, value in expected.items():
        assert getattr(book, name) == value
    assert book.cover 
开发者ID:ideascube,项目名称:ideascube,代码行数:26,代码来源:test_views.py

示例10: test_upload_authorized

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_upload_authorized(self):
        response = self.app.get(
            '/election/2015/post/65808/dulwich-and-west-norwood',
            user=self.user_who_can_upload_documents
        )
        self.assertIn(
            'As you have permission to upload documents',
            response.text
        )
        response = self.app.get(
            reverse('upload_document_view', args=('2015', self.post_extra.slug)),
            user=self.user_who_can_upload_documents,
        )
        form = response.forms['document-upload-form']
        form['source_url'] = 'http://example.org/foo'
        with open(self.example_image_filename, 'rb') as f:
            form['uploaded_file'] = Upload('pilot.jpg', f.read())
        form.submit()
        self.assertEqual(response.status_code, 200)
        ods = OfficialDocument.objects.all()
        self.assertEqual(ods.count(), 1)
        od = ods[0]
        self.assertEqual(od.source_url, 'http://example.org/foo')
        self.assertEqual(od.post.extra.slug, '65808') 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:26,代码来源:test_upload.py

示例11: test_create

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_create(self, import_tool, siu):
        project = M.Project.query.get(shortname='test')
        params = {
            'discussions_json': webtest.Upload('discussions.json',
                                               b'{"key": "val"}'),
            'mount_label': 'mylabel',
            'mount_point': 'mymount',
        }
        r = self.app.post('/p/test/admin/ext/import/forge-discussion/create', params, status=302)
        self.assertEqual(r.location, 'http://localhost/p/test/admin/')
        siu.assert_called_once_with(project,
                                    'discussions.json',
                                    '{"key": "val"}'
                                    )
        self.assertEqual('mymount', import_tool.post.call_args[1]['mount_point'])
        self.assertEqual('mylabel', import_tool.post.call_args[1]['mount_label']) 
开发者ID:apache,项目名称:allura,代码行数:18,代码来源:test_discussion.py

示例12: test_import_stock

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_import_stock(staffapp, tmpdir):
    source = tmpdir.join('stock.csv')
    source.write_text(
        'module,name,description\n'
        'cinema,C\'est arrivé près de chez vous,"Conte féérique pour les '
        'petits et les grands, le film relate les aventures de Benoît, preux '
        'chevalier en quête de justice, et des ménestrels Rémy, André et '
        'Patrick.\n\nBenoît parviendra-t-il à leur enseigner le principe de '
        'la poussée d\'Archimède ? Patrick reverra-t-il Marie-Paule ?"\n'
        'notamodule,Not a name,This is not a description.\n',
        encoding='utf-8')

    response = staffapp.get(reverse('monitoring:stock_import'))
    form = response.forms['import']
    form['source'] = Upload(str(source), source.read_binary(), 'text/csv')
    response = form.submit()
    assert response.status_code == 302
    assert response.location.endswith(reverse('monitoring:stock'))

    response = response.follow()
    assert response.status_code == 200
    assert 'Successfully imported 1 items' in response.text
    assert 'C'est arrivé près de chez vous' in response.text
    assert 'Could not import line 2: ' in response.text
    assert 'Not a name' not in response.text

    assert StockItem.objects.count() == 1
    movie = StockItem.objects.last()
    assert movie.name == "C'est arrivé près de chez vous"
    assert movie.module == 'cinema'
    assert movie.description == (
        'Conte féérique pour les petits et les grands, le film relate les '
        'aventures de Benoît, preux chevalier en quête de justice, et des '
        'ménestrels Rémy, André et Patrick.\n\nBenoît parviendra-t-il à leur '
        'enseigner le principe de la poussée d\'Archimède ? Patrick '
        'reverra-t-il Marie-Paule ?') 
开发者ID:ideascube,项目名称:ideascube,代码行数:38,代码来源:test_views.py

示例13: test_can_create_document

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_can_create_document(staffapp):
    assert not Document.objects.count()
    url = reverse('mediacenter:document_create')
    form = staffapp.get(url).forms['model_form']
    form['title'] = 'my document title'
    form['summary'] = 'my document summary'
    form['credits'] = 'my document credits'
    form['original'] = Upload('image.jpg', b'xxxxxx', 'image/jpeg')
    form.submit().follow()
    assert Document.objects.count() == 1
    doc = Document.objects.first()
    assert doc.kind == Document.IMAGE 
开发者ID:ideascube,项目名称:ideascube,代码行数:14,代码来源:test_views.py

示例14: test_can_create_app_document

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_can_create_app_document(staffapp):
    assert not Document.objects.count()
    url = reverse('mediacenter:document_create')
    form = staffapp.get(url).forms['model_form']
    form['title'] = 'my document title'
    form['summary'] = 'my document summary'
    form['credits'] = 'my document credits'
    form['kind'] = Document.APP
    form['original'] = Upload('soft.exe', b'xxxxxx',
                              'application/x-msdos-program')
    form.submit().follow()
    assert Document.objects.count() == 1
    doc = Document.objects.first()
    assert doc.kind == Document.APP 
开发者ID:ideascube,项目名称:ideascube,代码行数:16,代码来源:test_views.py

示例15: test_can_create_document_without_lang

# 需要导入模块: import webtest [as 别名]
# 或者: from webtest import Upload [as 别名]
def test_can_create_document_without_lang(staffapp):
    assert not Document.objects.count()
    url = reverse('mediacenter:document_create')
    form = staffapp.get(url).forms['model_form']
    form['title'] = 'my document title'
    form['summary'] = 'my document summary'
    form['credits'] = 'my document credits'
    form['original'] = Upload('image.jpg', b'xxxxxx', 'image/jpeg')
    form['lang'] = ''
    form.submit().follow()
    assert Document.objects.count() == 1 
开发者ID:ideascube,项目名称:ideascube,代码行数:13,代码来源:test_views.py


注:本文中的webtest.Upload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。