Re: How can I add the Openid session data to the Django test client Client.post() ?

2010-02-25 Thread br...@instantdirectmarketing.com
I looked at how the Django test client class method, Client.login()
stored sessions and attempt to copy the important sections into the
test so the session data could be stored.

When I broke into the test immediately before Client.post() was called
and the session looked OK.
ipdb> request.session.__dict__
{'_session_cache': {'openid': 'https://www.google.com/accounts/o8/id?
id=ItsAFakeOpenID'}, '_session_key':
'decee0b0bdbba7ad7c1a6601bbc60ef1', 'modified': True, 'accessed':
True}

However, after Client.post() the session doesn't seem to contain the
request.session['openid'] any longer.
I broke into the register view and checked:
ipdb> request.session.__dict__
{'_session_cache': {'pagesize': 10}, '_session_key': None, 'modified':
True, 'accessed': True}

Why is the session data not persisting?

class UserTestCAse(TestCase):
def test_register_should_create_UserProfile(self):
from django.test.client import Client
c = Client()

# Create a fake request to store session details.
from django.http import HttpRequest
request = HttpRequest()
from django.contrib.sessions.backends.db import SessionStore
request.session = SessionStore()

request.session['openid'] = 'https://www.google.com/accounts/
o8/id?id=ItsAFakeOpenID'
request.session.save()

response = c.post('/account/register/', {u'username':
[u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount':
[u'Signup']})
self.assertEqual(response.status_code, 200)
user = User.objects.get( username ='john')
self.assertTrue(user.get_profile())

On Feb 24, 5:12 pm, "br...@instantdirectmarketing.com"
 wrote:
> 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 Openidsessiondata 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'j...@beatles.com'], u'bnewaccount':
> [u'Signup']},)
>
>         self.assertEqual(response.status_code, 302)
>
>         user = User.objects.get( username ='john')
>         self.assertTrue(user.get_profile())
>
> I'm using django_authopenid and I want to make sure a UserProfile is
> created after the User is created.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How can I add the Openid session data to the Django test client Client.post() ?

2010-02-24 Thread br...@instantdirectmarketing.com
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'j...@beatles.com'], u'bnewaccount':
[u'Signup']},)

self.assertEqual(response.status_code, 302)

user = User.objects.get( username ='john')
self.assertTrue(user.get_profile())

I'm using django_authopenid and I want to make sure a UserProfile is
created after the User is created.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.