Re: how can a test log in as a given user before calling client.get()?
I would use the create_user[1] function, then you can just enter the password, instead of the hash value. Might make your code a little more readable. Alex [1]http://docs.djangoproject.com/en/dev/topics/auth/#creating-users On Jan 6, 3:19 pm, Phlip wrote: > > Google cannot find any traffic on this topic, so I'm warming up the > > question here before researching it myself. If I figure out how to > > write login_as() for tests, I will post it here. > > Do I always have to see the same hands?? > > from django.contrib.auth.models import User > hell_yeah = True > > u = User.objects.create(username=u'admin', is_active=True, > email=u'ad...@admin.admin', > is_superuser=hell_yeah, is_staff=True, > password=u'sha1$e34de > $49632495b9ab78a54ff53a0d1145e2b9e8eb2af6') > > self.client.login(username='admin', password='admin') # <-- > the money line > > self.get('/shop-admin/') # TODO get should demand a 200 > > Some of you might see fit to put that User into a reusable (but test- > only) JSON file... to each her or his own. > > > > > -- > > Phlip > > http://twitter.com/Pen_Bird -- 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.
Re: how can a test log in as a given user before calling client.get()?
> Google cannot find any traffic on this topic, so I'm warming up the > question here before researching it myself. If I figure out how to > write login_as() for tests, I will post it here. Do I always have to see the same hands?? from django.contrib.auth.models import User hell_yeah = True u = User.objects.create(username=u'admin', is_active=True, email=u'ad...@admin.admin', is_superuser=hell_yeah, is_staff=True, password=u'sha1$e34de $49632495b9ab78a54ff53a0d1145e2b9e8eb2af6') self.client.login(username='admin', password='admin') # <-- the money line self.get('/shop-admin/') # TODO get should demand a 200 Some of you might see fit to put that User into a reusable (but test- only) JSON file... to each her or his own. > -- > Phlip > http://twitter.com/Pen_Bird -- 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 a test log in as a given user before calling client.get()?
Djangoids: Google cannot find any traffic on this topic, so I'm warming up the question here before researching it myself. If I figure out how to write login_as() for tests, I will post it here. The issue is, with the contrib/auth system turned on, client.get() can't fetch a page; it redirects to the login page. Fair enough, but tests have to run security-free (unless your administrators and premium users like bugs). So what do I set into the "session", and how do I add that to the .get(), to test a protected page? Watch this space! -- Phlip http://twitter.com/Pen_Bird -- 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.