Hello,

You can simulate being logged or not by using os.environ
['USER_EMAIL']. The following tests pass on Rietveld/codereview:

from django.test.client import Client
from django.test import TestCase
import os

class Test(TestCase):
  def setUp(self):
    self.client = Client()

  def testStart(self):
    response = self.client.get('/')
    self.failUnlessEqual(response.status_code, 200)
    self.assertContains(response,'Code Review')

    os.environ['USER_EMAIL'] = '' # simulate not logged in
    response = self.client.get('/mine')
    self.failUnlessEqual(response.status_code, 302)

    os.environ['USER_EMAIL'] = 't...@example.com' # simulate logged in
    response = self.client.get('/mine')
    self.failUnlessEqual(response.status_code, 200)
    self.assertContains(response,'Issues Created by me')

    os.environ['USER_EMAIL'] = '' # simulate not logged in
    response = self.client.get('/mine')
    self.failUnlessEqual(response.status_code, 302)

Hope it helps,

Michel

On Jun 30, 1:33 am, Akume <akume...@gmail.com> wrote:
> ok,
> what about this scenario.  some of my pages require a login prior to
> seeing the content and i can't see to get this to work using the
> django
> client.  any suggestions?  this is what my test looks like so far.
>
> import unittest
> from django.test.client import Client
>
> class Test(unittest.TestCase):
>   def setUp(self):
>     self.client = Client()
>
>   def testStart(self):
>     response = self.client.get('/app/layout')
>     self.failUnlessEqual(response.status_code, 301)
>
> #attempting to log in here.
>     response = self.client.get('/_ah/login?continue=http%3A//localhost
> %3A8081/app/layout')
>     self.failUnlessEqual(response.status_code, 302)
>
>     # another attempt at logging in.
>     #response = self.client.get('/_ah/login?email=Aliquam.nec
> %40Vestibulumante.edu&action=Login&continue=http%3A%2F%2Flocalhost
> %3A8081%2Fapp%2Flayout')
>     response = self.client.login(path='/app/layout',
> username='Aliquam.nec%40Vestibulumante.edu', password='')
>     self.failUnlessEqual(response, True)
>
>     response = self.client.get('/app/layout')
>     self.failUnlessEqual(response.status_code, 200)
>
> On Jun 26, 12:15 pm, Michelschr <michels...@gmail.com> wrote:
>
> > I had GaeUnit working on Rietveld (à la Guido...), the test:
>
> > import unittest
> > from django.test.client import Client
>
> > class Test(unittest.TestCase):
>
> >     def testDjango(self):
> >         c = Client()
> >         response = c.get('/code')
> >         self.failUnlessEqual(response.status_code, 200)
> >         self.failIf(not ('SERVER' in response.content))
>
> > passed, not possible (for me) to 'from django.test import TestCase'
> > only from unittest.
>
> > But it is not out of the box! You should search a lot by yourself...
>
> > I will continue to investigate...
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to