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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:21:04+00:00 2026-06-16T16:21:04+00:00

I set up a unit test as such: class UserViewTests(TestCase): def setUp(self): self.user_passwords =

  • 0

I set up a unit test as such:

class UserViewTests(TestCase):
    def setUp(self):
        self.user_passwords = '123456'
        self.user1 = User.objects.create(username='Bobby Johnson', password=self.user_passwords)

    ...

    def test_view_user(self):
        """
        Check that you can view a user's information correctly in their profile
        """
        response = self.client.get(reverse('login'))
        self.assertContains(response, "You're not logged in yet", status_code=200)
        self.client.login(username=self.user1.username, password=self.user_passwords)
        response = self.client.get(reverse('login'))
        self.assertContains(response, "You've logged in already", status_code=200)

Only the last assertion fails, and replacing “You’ve logged in already” with “You’re not logged in yet” in that last assertion makes the test pass, so it appears my login failed. I’m guessing this is because I’m using django-social-auth to allow OpenId logins.

How can I somehow get the unit tests to think that my user has logged in, so that user.is_authenticated is true? I just want to test that my views display correctly when a user is logged in vs otherwise, and don’t particularly care about unit-testing that the login actually works.

  • 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-16T16:21:06+00:00Added an answer on June 16, 2026 at 4:21 pm
     self.user1 = User.objects.create(username='Bobby Johnson', password=self.user_passwords)
    

    Should be:

    self.user1 = User.objects.create_user(username='Bobby Johnson', password=self.user_passwords)
    

    Otherwise the password is not hashed and is not usable.


    You’ll also need to have django.contrib.auth.backends.ModelBackend present in your authentication backends.


    Then,

    self.client.login(username=self.user1.username, password=self.user_passwords)
    

    will just work.

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

Sidebar

Related Questions

I have a VS2010 unit test project set to using SpecFlow 1.8.1 and mstest.
I've set up a project with unit test files in NetBeans. I set bootstrap
In my Controller Action I set Cookie with Response.SetCookie(myCookie) method. In my Unit Test
HI, I want to have set configuration settings for a unit test project that
I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on
I'm using Google Test Framework to set some unit tests. I have got three
I had set up a bunch of NUnit unit tests using the Test connection
I have a set of unit test cases that depend on a test.properties file.
I've got a setup where I use doxygen to describe a set on unit
I am trying to set up a unit test for a piece of code

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.