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

  • Home
  • SEARCH
  • 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 661299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:15:07+00:00 2026-05-13T23:15:07+00:00

I’m trying to test that a UserProfile model is created as a new User

  • 0

I’m trying to test that a UserProfile model is created as a new User is registered in django_authopenid.
I don’t understand how to add the Openid session data to the POST.

class UserTestCAse(TestCase):  
  def test_register_should_create_UserProfile(self):  
    from django.test.client import Client
    c = Client()  
    response = c.post('/account/register/', {u'username': [u'john'], u'email': [u'john@beatles.com'], u'bnewaccount': [u'Signup']},)  

    self.assertEqual(response.status_code, 302)  

    user = User.objects.get( username ='john')  
    self.assertTrue(user.get_profile())  
  • 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-13T23:15:07+00:00Added an answer on May 13, 2026 at 11:15 pm

    Apparently, adding session data to the django.test.client.Client without using Client.login() is not so easy.

    The easiest solution was to create a new RequestFactory class so I could build a Request with the OpenID session object.

        class RequestFactory(Client):  
        """  
        Class that lets you create mock Request objects for use in testing.  
    
        Usage:  
    
        rf = RequestFactory()  
        get_request = rf.get('/hello/')  
        post_request = rf.post('/submit/', {'foo': 'bar'})  
    
        This class re-uses the django.test.client.Client interface, docs here:  
        http://www.djangoproject.com/documentation/testing/#the-test-client  
    
        Once you have a request object you can pass it to any view function,   
        just as if that view had been hooked up using a URLconf.  
    
        """  
        def request(self, **request):  
            """  
            Similar to parent class, but returns the request object as soon as it  
            has created it.  
            """  
            environ = {  
                'HTTP_COOKIE': self.cookies,  
                'PATH_INFO': '/',  
                'QUERY_STRING': '',  
                'REQUEST_METHOD': 'GET',  
                'SCRIPT_NAME': '',  
                'SERVER_NAME': 'testserver',  
                'SERVER_PORT': 80,  
                'SERVER_PROTOCOL': 'HTTP/1.1',  
            }  
            environ.update(self.defaults)  
            environ.update(request)  
            request = WSGIRequest(environ)  
            handler = BaseHandler()  
            handler.load_middleware()  
            for middleware_method in handler._request_middleware:  
                if middleware_method(request):  
                    raise Exception("Couldn't create request mock object - "  
                                     "request middleware returned a response")  
            return request  
    

    I used the RequestFactory method like this:

    class UserProfileCreation(TestCase):  
        def test_register_should_create_UserProfile(self):  
            count = User.objects.count()  
            print 'Original Users' + str(count)  
    
            from forum.tests.request_factory import RequestFactory  
            rf = RequestFactory()  
            post_request = rf.post('/register/', {u'username': [u'john'], u'email': [u'john@beatles.com'], u'bnewaccount': [u'Signup'] } )  
    
            from django_authopenid.util import OpenID  
            openid_instance = OpenID('https://www.google.com/accounts/o8/id?id=AItOxxxxxxxxxxxxxxxxxA',  
                                     1267727884,  
                                     [u'openid.op_endpoint', u'openid.claimed_id', u'openid.identity', u'openid.return_to', u'openid.response_nonce', u'openid.assoc_handle'],  
                                     )  
    
            post_request.session['openid'] = openid_instance  
    
            from django_authopenid.views import register  
            response = register(post_request)  
    
            print "after POST User count: " + str(User.objects.count())  
            self.assertEqual(response.status_code, 302)  
            user = User.objects.get( username ='john')  
            self.assertTrue(user.get_profile())  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.