[Repoze-dev] Is the Test authentication independently how-to correct?

2010-08-16 Thread Ryan McKillen
Hello,

I am following the
http://code.gustavonarea.net/repoze.who-testutil/HowTo/TestingAuthentication.htmlhow-to
and trying to write a passing test based on the
test_voluntary_login example:

def test_voluntary_login(self):
Voluntary logins should work perfectly
# Requesting the login form:
login_page = self.app.get('/login', status=200)
login_form = login_page.form
login_form['login'] = 'username'
login_form['password'] = 'password'
# Submitting the login form:
login_handler = login_form.submit(status=302)
assert login_handler.location == 'http://localhost/'
# Checking that the user was correctly authenticated:
initial_page = login_handler.follow(status=200)
assert 'auth_tkt' in initial_page.request.cookies, \
   Session cookie wasn't defined: %s %
initial_page.request.cookies

I'm using the repoze.what Quickstart plugin (just easy installed the most
recent version) with Pylons 1.0 and this test fails
because login_handler.follow(status=200) is 302'ing.

When I leave my test environment and do my own user testing in my
development environment, everything works fine. I've also made certain that
I do in fact have the correct username and password I am trying to
authenticate against in my database.

Can anyone confirm or deny that this example works in Pylons? Any help on
how I can get it to pass?

Thanks!
Ryan
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] repoze.who testing on Pylons

2010-08-16 Thread Gustavo Narea
Hello, Wojtek.

I've had a quick look at the auth_repozepylons template in Shabti and I 
think I've found the problem.

The test case TestController doesn't seem to be setting skip_authentication. 
Can you please modify it to make it look like this:

class TestController(TestModel):

# Protected areas should be tested with authentication disabled:
application_under_test = 'main'

def __init__(self, *args, **kwargs):
conf_dir = config['here']
wsgiapp = loadapp('config:test.ini#%s' % self.application_under_test,
  relative_to=conf_dir)
self.app = TestApp(wsgiapp)
url._push_object(URLGenerator(config['routes.map'], environ))
TestCase.__init__(self, *args, **kwargs)


Then go to tests/functional/test_auth_login.py and add the 
application_under_test attribute to TestLoginController, like this:

class TestLoginController(TestController):
application_under_test = 'main_without_authn'

...


Does it work now? If so, can you please report the bug on 
https://bitbucket.org/gjhiggins/shabti/issues?status=new 

Cheers.

 - Gustavo.


Wojtek said:
 Thanks for reply, Gustavo.
 I did check that, though I'm using the *shabti* templates and they are up
 to par.
 I guess my problem isn't with authentication so much as with
 identification, maybe?:
 
 In my controller I have *request.environ.get('repoze.who.identity')['user']
 *and its just keeps coming up as 'None' on my tests (only)...
 
 sigh
 
 I've been at it for a couple of days now.  I even went as far as doing
 another virtualenv and creating a new app and it persists.
 
 
 I really appreciate the help.
 
 On Sun, Aug 15, 2010 at 3:45 PM, Gustavo Narea m...@gustavonarea.net wrote:
  Hello,
  
  Setting REMOTE_USER is the preferred method. It should make everything
  work with no additional code.
  
  If it doesn't work, the only reason I can think of would be that
  skip_authentication is not set during the tests:
  http://code.gustavonarea.net/repoze.who-testutil/HowTo/Reconfiguring.html
  
  HTH.
  
   - Gustavo.
  
  Chris said:
Greetings,



I'm using the shabti paster templates for a repoze auth'n'auth set up
on Pylons.
The templates preconfigure the set up with repoze.who_testutil.



I've been struggling trying to get these tests to run.
The instructions for the testutil show that I just need to pass in
the REMOTE_USER dictionary in the enviorn:
response = self.app.get(url(controller='mycontroller',
action='index', extra_environ={'REMOTE_USER':'tester'}))



Someone else on the Pylons bored told me to just create a
repoze.what.credentials dictionary with userid, groups, and
premissions keys.



I'm chocking here...
On my controller I use the helper get_user to get a user instance
which keeps showing as None in the error stack...
  
  --
  Gustavo Narea xri://=Gustavo.
  
  | Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |
-- 
Gustavo Narea xri://=Gustavo.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev