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 6801981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:10:04+00:00 2026-05-26T19:10:04+00:00

I want to write some tests for views in a Django profile app. The

  • 0

I want to write some tests for views in a Django profile app.

The views have some smart error-handling logic. e.g. if we try to create a profile, but the profile already exists, then just redirect to the existing profile page (or maybe to the edit profile page).

How do I test that this error-handling works as desired?
What are best-practices?

One idea would be to do BDD using Zombie.js, and test that I see a page whose title isn’t “Create profile” (or maybe check that I see a page whose title is “Edit profile”). But the Django testing docs say:

  • Use Django’s test client to establish that the correct view is being
    called and that the view is collecting the correct context data.
  • Use in-browser frameworks such as Twill and Selenium to test rendered
    HTML and the behavior of Web pages, namely JavaScript functionality.

However, if I want to use the Django test client, it can do the following:

  • Simulate GET and POST requests on a URL and observe the response — everything from low-level HTTP (result headers and status codes) to page content.
  • Test that the correct view is executed for a given URL.
  • Test that a given request is rendered by a given Django template, with a template context that contains certain values.

Should I use the test client and then look at the page content? Should I see what template got rendered? What is the appropriate way to test this view?

  • 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-05-26T19:10:04+00:00Added an answer on May 26, 2026 at 7:10 pm

    Redirects and profile creation are very django so while you might use other frameworks to test JS functionality, I’d be using the django test client for this instance.

    You have to decide on a case by case basis how far to go with your tests. Time is limited, and some aspects are more prone to breakage than others. For example, I wouldn’t be worried about template resolution – a 200 status code and a quick check for content is plenty.

    Anyhoo, I’d start by identifying the different states the view has (I’m guessing here):

    • Render itself (check content, template, status code, etc.)
    • Profile form validation error
    • Profile form success: profile creation: success redirect
    • The smart error handling / redirect.

    How do I test that this error-handling works as desired?

    # create object with specific ID.
    # post form data that should trigger your special redirect. 
    # ensure the redirect takes you to the model you just created via reverse
    response = client.post(reverse('form_url'), {'valid_form_data': ''}, follow=True)
    assertRedirects(response, reverse('view_url', args=[id]), target_status_code=200)
    

    This would confirm that the correct profile is being redirected to given whatever data you’ve decided should trigger this action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some unit tests in UnitTest++ and want to write a bunch of
I want to write some javascript and have it call into the DOM for
I want to write some games, but I don't have any game development experience.
I have written a Windows Forms application and now I want to write some
I've implemented an ITimer interface because I want to write some tests around a
I am new to unit testing and I want to write some tests to
I'm trying to write some tests for an MVC application we're developing. We have
I want to write some tests to verify that an IValueConverter rotates an image
I have a ASP.NET MVC application for which I want to write some stress
I want to write some tests for a python MFCC feature extractor for running

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.