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


Python uploadedfile.SimpleUploadedFile方法代码示例

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


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

示例1: test_valid_delete

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_valid_delete(self, mock_messages):
        """
        Ensure we can delete a valid Document.
        """
        simple_file = SimpleUploadedFile("delicious.txt", self.file_contents)
        document = Document.objects.create(name="Honeycrisp",
                                           author=self.user,
                                           file=simple_file,
                                           )

        doc_pk = document.pk
        with self.login(self.user):
            response = self.get(document.delete_url())
            self.response_200(response)
            self.assertTrue("pinax/documents/document_confirm_delete.html" in response.template_name)

            response = self.post("pinax_documents:document_delete", pk=doc_pk, follow=True)
            self.response_200(response)
            self.assertFalse(Document.objects.filter(pk=doc_pk))
            self.assertTrue(mock_messages.called)

            response = self.get(self.download_urlname, pk=document.pk)
            self.response_404(response) 
开发者ID:pinax,项目名称:pinax-documents,代码行数:25,代码来源:test_views.py

示例2: test_download

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_download(self):
        """
        Ensure the requested Document file is served.
        """
        simple_file = SimpleUploadedFile("delicious.txt", self.file_contents)
        document = Document.objects.create(name="Honeycrisp",
                                           author=self.user,
                                           file=simple_file,
                                           )
        document.save()

        with self.login(self.user):
            # Verify `django.views.static.serve` is called to serve up the file.
            # See related note in .views.DocumentDownload.get().
            with mock.patch("django.views.static.serve") as serve:
                serve.return_value = HttpResponse()
                self.get_check_200(self.download_urlname, pk=document.pk)
                self.assertTrue(serve.called) 
开发者ID:pinax,项目名称:pinax-documents,代码行数:20,代码来源:test_views.py

示例3: test_search_with_imagefile

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_search_with_imagefile(self):
        from django.core.files.uploadedfile import SimpleUploadedFile

        models.SpeedRun.objects.create(
            event=self.event,
            name='Test Run',
            run_time='5:00',
            setup_time='5:00',
            order=1,
        ).clean()
        prize = models.Prize.objects.create(
            event=self.event,
            handler=self.add_user,
            name='Prize With Image',
            state='ACCEPTED',
            startrun=self.event.speedrun_set.first(),
            endrun=self.event.speedrun_set.first(),
            imagefile=SimpleUploadedFile('test.jpg', b''),
        )
        prize.refresh_from_db()
        request = self.factory.get('/api/v1/search', dict(type='prize',),)
        request.user = self.user
        data = self.parseJSON(tracker.views.api.search(request))
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0], self.format_prize(prize, request)) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:27,代码来源:test_api.py

示例4: test_hpo_term_number_table_handler

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_hpo_term_number_table_handler(self):
        url = reverse(receive_hpo_table_handler, args=['R0001_1kg'])
        self.check_collaborator_login(url)

        header = 'family_id,individual_id,affected,hpo_number,hpo_number'
        rows = [
            '1,NA19675_1,yes,HP:0002017,',
            '1,NA19675_1,no,HP:0012469,',
            '1,NA19675_1,no,,HP:0004322',
            '1,NA19678,,,',
            '1,NA19679,yes,HP:0100258,',
            '1,HG00731,yes,HP:0002017,',
            '1,HG00731,no,HP:0012469,HP:0011675',
        ]
        f = SimpleUploadedFile('updates.csv', "{}\n{}".format(header, '\n'.join(rows)).encode('utf-8'))
        response = self.client.post(url, data={'f': f})
        self._is_expected_hpo_upload(response) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:19,代码来源:individual_api_2_3_tests.py

示例5: test_collection_images

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_collection_images(self):
        image_path = "{p}test_vert.jpg".format(p=self.fixture_path)
        self.collection.original = SimpleUploadedFile(name='test_vert.jpg', content=open(image_path, 'rb').read(), content_type='image/jpeg')
        self.collection.save()
        # NOTE pytest uses some arbitrary tmp file naming structure.
        assert self.collection.original.path.split('/')[-1] == 'test_vert.jpg'
        # assert self.collection.upload.path.split('/')[-1] == 'test_vert.jpg'
        assert self.collection.header.path.split('/')[-1] == 'test_vert_header.jpg'
        assert self.collection.thumbnail.path.split('/')[-1] == 'test_vert_thumb.jpg'
        assert self.collection.original.url == "%soriginals/test_vert.jpg" % (settings.MEDIA_URL)
        # assert self.collection.upload.url == "%s/uploads/test_vert.jpg" % (settings.MEDIA_URL)
        assert self.collection.header.url == "%sheaders/test_vert_header.jpg" % (settings.MEDIA_URL)
        assert self.collection.thumbnail.url == "%sthumbnails/test_vert_thumb.jpg" % (settings.MEDIA_URL)
        assert path.isfile(self.collection.original.path)
        # assert path.isfile(self.collection.upload.path)
        assert path.isfile(self.collection.header.path)
        assert path.isfile(self.collection.thumbnail.path) 
开发者ID:ecds,项目名称:readux,代码行数:19,代码来源:tests.py

示例6: test_check_submission_ok

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_check_submission_ok(self):
        contest_submition = ContestSubmission()
        contest_submition.issue = self.issue
        contest_submition.author = self.student
        contest_submition.run_id = "1"

        event_create_file = Event.objects.create(issue=self.issue, field=IssueField.objects.get(name='file'))
        f = File.objects.create(file=SimpleUploadedFile('test_fail_rb.py', b'print "_failed_"'),
                                event=event_create_file)
        contest_submition.file = f

        contest_submition.save()

        comment = contest_submition.check_submission()
        self.assertIn(u'<p>{0}: ok</p>'.format(_(u'verdikt_jakontest')), comment)
        self.assertTrue(contest_submition.got_verdict) 
开发者ID:znick,项目名称:anytask,代码行数:18,代码来源:tests.py

示例7: test_check_submission_precompile_check_failed

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_check_submission_precompile_check_failed(self):
        contest_submition = ContestSubmission()
        contest_submition.issue = self.issue
        contest_submition.author = self.student
        contest_submition.run_id = "2"

        event_create_file = Event.objects.create(issue=self.issue, field=IssueField.objects.get(name='file'))
        f = File.objects.create(file=SimpleUploadedFile('test_fail_rb.py', b'print "_failed_"'),
                                event=event_create_file)
        contest_submition.file = f

        contest_submition.save()

        comment = contest_submition.check_submission()
        self.assertIn(u'<p>{0}: precompile-check-failed</p>'.format(_(u'verdikt_jakontest')), comment)
        self.assertTrue(contest_submition.got_verdict)
        self.assertIn('precompile-check-failed-1', comment)
        self.assertIn('precompile-check-failed-2', comment)
        self.assertIn('precompile-check-failed-3', comment) 
开发者ID:znick,项目名称:anytask,代码行数:21,代码来源:tests.py

示例8: test__delete_an_image

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test__delete_an_image(api_client, settings, user, organization):
    api_client.force_authenticate(user)

    image_file = create_in_memory_image_file(name='existing_test_image')
    uploaded_image = SimpleUploadedFile(
        'existing_test_image.png',
        image_file.read(),
        'image/png',
    )
    existing_image = Image.objects.create(image=uploaded_image,
                                          publisher=organization)
    assert Image.objects.all().count() == 1

    # verify that the image file exists at first just in case
    image_path = os.path.join(settings.MEDIA_ROOT, existing_image.image.url)
    assert os.path.isfile(image_path)

    detail_url = reverse('image-detail', kwargs={'pk': existing_image.pk})
    response = api_client.delete(detail_url)
    assert response.status_code == 204
    assert Image.objects.all().count() == 0

    # check that the image file is deleted
    assert not os.path.isfile(image_path) 
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:26,代码来源:test_event_images_v1.py

示例9: test_query_is_executed_for_multipart_form_request_with_file

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_query_is_executed_for_multipart_form_request_with_file(
    view, request_factory, snapshot
):
    request = request_factory.post(
        "/",
        {
            "operations": json.dumps(
                {
                    "query": "mutation($file: Upload!) { upload(file: $file) }",
                    "variables": {"file": None},
                }
            ),
            "map": json.dumps({"0": ["variables.file"]}),
            "0": SimpleUploadedFile("test.txt", b"test"),
        },
    )
    response = view(request)
    assert response.status_code == 200
    snapshot.assert_match(response.content) 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_query_execution.py

示例10: test_multipart_form_request_fails_if_map_is_not_valid_json

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_multipart_form_request_fails_if_map_is_not_valid_json(
    view, request_factory, snapshot
):
    request = request_factory.post(
        "/",
        {
            "operations": json.dumps(
                {
                    "query": "mutation($file: Upload!) { upload(file: $file) }",
                    "variables": {"file": None},
                }
            ),
            "map": "not a valid json",
            "0": SimpleUploadedFile("test.txt", b"test"),
        },
    )
    response = view(request)
    assert response.status_code == 400
    snapshot.assert_match(response.content) 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_query_execution.py

示例11: test_can_modify_uploaded_file_with_edit_post

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_can_modify_uploaded_file_with_edit_post(self):
        uploaded_file = SimpleUploadedFile(AttachmentModelTest.SAVED_TEST_FILE_NAME_1,
                                           open(AttachmentModelTest.UPLOAD_TEST_FILE_NAME, 'rb').read())
        Attachment.objects.create(post=self.default_post, attachment=uploaded_file)

        self.assertEqual(Attachment.objects.get(post=self.default_post).attachment.name,
                         AttachmentModelTest.SAVED_TEST_FILE_NAME_1)

        upload_file = open(os.path.join(settings.BASE_DIR, 'test_file/attachment_test_2.txt'))
        self.client.post(reverse('board:edit_post', args=[self.default_post.id]), {
            'title': 'some post title',
            'content': 'some post content',
            'attachment': upload_file,
        })

        self.assertEqual(Attachment.objects.get(post=self.default_post).attachment.name,
                         AttachmentModelTest.SAVED_TEST_FILE_NAME_2) 
开发者ID:kboard,项目名称:kboard,代码行数:19,代码来源:test_views.py

示例12: test_record_edited_attachment_if_attachment_is_modified

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_record_edited_attachment_if_attachment_is_modified(self):
        uploaded_file = SimpleUploadedFile(AttachmentModelTest.SAVED_TEST_FILE_NAME_1,
                                           open(AttachmentModelTest.UPLOAD_TEST_FILE_NAME, 'rb').read())
        origin_attachment = Attachment.objects.create(post=self.default_post, attachment=uploaded_file)

        upload_file = open(os.path.join(settings.BASE_DIR, 'test_file/attachment_test_2.txt'))
        self.client.post(reverse('board:edit_post', args=[self.default_post.id]), {
            'title': 'NEW POST TITLE',
            'content': 'NEW POST CONTENT',
            'attachment': upload_file,
        })

        origin_attachment.refresh_from_db()
        new_attachment = Attachment.objects.get(post=self.default_post)
        edtied_post_history = EditedPostHistory.objects.get(post=self.default_post)

        self.assertEqual(origin_attachment.post, None)
        self.assertEqual(origin_attachment.editedPostHistory, edtied_post_history)
        self.assertEqual(new_attachment.post, self.default_post)
        self.assertEqual(new_attachment.editedPostHistory, None) 
开发者ID:kboard,项目名称:kboard,代码行数:22,代码来源:test_views.py

示例13: test_view_edited_attachment_in_post_history_list

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_view_edited_attachment_in_post_history_list(self):
        edited_post_history = EditedPostHistory.objects.create(
            post=self.default_post,
            title='edited post title',
            content='edited post content',
        )
        uploaded_file = SimpleUploadedFile(AttachmentModelTest.SAVED_TEST_FILE_NAME_1,
                                           open(AttachmentModelTest.UPLOAD_TEST_FILE_NAME, 'rb').read())
        attachment = Attachment.objects.create(
            post=None,
            editedPostHistory=edited_post_history,
            attachment=uploaded_file,
        )

        response = self.client.get(reverse('board:post_history_list', args=[self.default_post.id]))
        self.assertContains(response, 'edited post title')
        self.assertContains(response, attachment.attachment.name) 
开发者ID:kboard,项目名称:kboard,代码行数:19,代码来源:test_views.py

示例14: setUp

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def setUp(self):
        self.target = TargetFactory.create()
        self.observation_record = ObservingRecordFactory.create(
            target_id=self.target.id,
            facility=FakeRoboticFacility.name,
            parameters='{}'
        )
        self.data_product = DataProduct.objects.create(
            product_id='testproductid',
            target=self.target,
            observation_record=self.observation_record,
            data=SimpleUploadedFile('afile.fits', b'somedata')
        )
        user = User.objects.create_user(username='test', email='test@example.com')
        assign_perm('tom_targets.view_target', user, self.target)
        self.client.force_login(user) 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:18,代码来源:tests.py

示例15: test_upload_data_extended_permissions

# 需要导入模块: from django.core.files import uploadedfile [as 别名]
# 或者: from django.core.files.uploadedfile import SimpleUploadedFile [as 别名]
def test_upload_data_extended_permissions(self, dp_mock):
        group = Group.objects.create(name='permitted')
        group.user_set.add(self.user)
        response = self.client.post(
            reverse('dataproducts:upload'),
            {
                'facility': 'LCO',
                'files': SimpleUploadedFile('afile.fits', b'afile'),
                'target': self.target.id,
                'groups': Group.objects.filter(name='permitted'),
                'data_product_type': settings.DATA_PRODUCT_TYPES['spectroscopy'][0],
                'observation_timestamp_0': date(2019, 6, 1),
                'observation_timestamp_1': time(12, 0, 0),
                'referrer': reverse('targets:detail', kwargs={'pk': self.target.id})
            },
            follow=True
        )
        self.assertContains(response, 'afile.fits')
        self.client.force_login(self.user2)
        response = self.client.get(reverse('targets:detail', kwargs={'pk': self.target.id}))
        self.assertNotContains(response, 'afile.fits') 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:23,代码来源:tests.py


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