On Nov 22, 11:32 pm, "Dalius Dobravolskas"
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> > I am attempting to setup unit testing with Pylons 0.9.6.1, AuthKit
> > 0.4.0 and SQLAlchemy 0.4.0 using the AuthKit database driver.
> ...
> > Has anyone managed to these three work together and have functional
> > unit testing? Thanks for any advice or suggestions that you could
> > provide.
>
> I have managed and I do a lot of testing with exactly this configuration.
>
> Entry from my test.ini file:
> sqlalchemy.url = sqlite:///:memory:
> sqlalchemy.echo = false
> authkit.setup.method = form, cookie
> authkit.form.authenticate.user.data = admin:admin
In my case I used authkit.setup.method = form, cookie which I
thought was assumed since I never mentioned using forward
authentication that you seem to think I'm using later on this post.
Have you worked with the SQLAlchemy database model at all yet? My
question was specifically related to this driver because I need to be
able to test adding and modifying user accounts within the application
which you can't do if the user data is specified directly within the
authkit.form.authenticate.user.data definition.
>
> My application works with OpenID but AuthKit's OpenID method is not
> suitable for unit-testing. Because of that I set that AuthKit method
> is form (while it means nothing in this context). While actually I
> have proposed to AuthKit author to introduce stub method for
> unit-testing (maybe in the future I will get rights to commit to
> AuthKit :)).
>
> And you should be able to test actually. To test AuthKit protected
> methods you must specify REMOTE_USER (and maybe REMOTE_USER_DATA) in
> extra_environ. E.g.:
>
> self.app.get(url_for(controller='release', action='save', id=None),
> params = {'author': 'test author',
> 'publisher': 'test publisher',
> 'date': '2007',
> 'name': 'test name'},
> extra_environ = {'REMOTE_USER': 'test'})
>
Thanks for the advice regarding extra_environ, as I definitely found
that to be correct in regards to my secured application. So far I
have not required REMOTE_USER_DATA.
> > the error I am receiving when I attempt to run nosetests is that the
> > "AuthKit database has already been setup."
>
> I guess you have mis-configured something. I don't have experience
> with forward method of AuthKit (which you are using I guess) but it
> looks like that you do not clean-up database properly after each test.
Actually I followed the guidelines specified in Authentication and
Authorization in the Pylons Book located at
http://wiki.pylonshq.com/display/pysbook/Authentication+and+Authorization
where the references needs to be added in two places - if I
misconfigured anything that it would be direct flaw in the
documentation itself (my guess is the documentation wasn't actually
tested with unit testing):
1) development.ini
authkit.form.authenticate.user.type =
authkit.users.sqlalchemy_driver:UsersFromDatabase
2) websetup.py
users = UsersFromDatabase(model)
Perhaps the UsersFromDatabase(model) in the websetup.py should
actually be done in app_globals to prevent the multiple loads that
would occur with each successive unit test that is run and uses the
setup-app command? Perhaps there is a better way to unload the
UsersFromDatabase from the model afterward - or refer to it later
instead of reinitializing?
>
> Here is excerpt from my tests/__init__.py file. If you have something
> similar it might be that tearDown method is missing something.
>
> class TestModel(TestCase):
> """
> We want the database to be created from scratch before each test
> and dropped after
> each test (thus making them unit tests).
> """
> def setUp(self):
> model.Session.remove()
> model.metadata.create_all(model.Session.bind)
>
> def tearDown(self):
> model.metadata.drop_all(model.Session.bind)
>
> class TestController(TestModel):
>
> def __init__(self, *args, **kwargs):
> wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
> self.app = paste.fixture.TestApp(wsgiapp)
> TestCase.__init__(self, *args, **kwargs)
I have found this to be very helpful in terms of the model loading,
thank you. I still would like to be able to use the database driver
in the unit testing process as I have already been able to make it
functional when my web application runs and unit testing is only
accurate to those elements that can be tested.
>
> HTH,
> Daliushttp://blog.sandbox.lt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---