Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:56:38+00:00 2026-06-06T07:56:38+00:00

In my django app, I have a view which accomplishes file upload.The core snippet

  • 0

In my django app, I have a view which accomplishes file upload.The core snippet is like this

...
if  (request.method == 'POST'):
    if request.FILES.has_key('file'):
        file = request.FILES['file']
        with open(settings.destfolder+'/%s' % file.name, 'wb+') as dest:
            for chunk in file.chunks():
                dest.write(chunk)

I would like to unit test the view.I am planning to test the happy path as well as the fail path..ie,the case where the request.FILES has no key ‘file’ , case where request.FILES['file'] has None..

How do I set up the post data for the happy path?Can somebody tell me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:56:40+00:00Added an answer on June 6, 2026 at 7:56 am

    From Django docs on Client.post:

    Submitting files is a special case. To POST a file, you need only
    provide the file field name as a key, and a file handle to the file
    you wish to upload as a value. For example:

    c = Client()
    with open('wishlist.doc') as fp:
      c.post('/customers/wishes/', {'name': 'fred', 'attachment': fp})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this view which generates interface language options menu def lang_menu(request,language): lang_choices =
In my project I have one app which have its own urls.py like this
I have a Django app that use a django-tagging. I need to port this
I have a django app which is used for managing registrations to a survey.
I have a Django app where multiple teams upload content that will be parsed.
I have a Django app which, submitting a package, should return values that are
I'm creating a Django app in which I have a table which has 'items',
# settings.py EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' # view.py from django.core.mail import send_mail def send_letter(request): the_text
Suppose I have a Django app named blog. There's a model called Post and
I have a ModelForm in my Django app that uses a forms.ModelMultipleChoiceField, which displays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.