[openstack-dev] [Keystone] How to write unit tests for db methods?

Adam Young ayoung at redhat.com
Thu Jul 11 02:28:28 UTC 2013


On 07/10/2013 06:56 AM, Akshat Kakkar wrote:
> I have added 2 tables to keystone.

This should be done in a migration, and should be tested using the 
test_db_update.py file.

> I have methods which do the read/write/update/delete of records in 
> these tables.
PLease explain.  We are not doing direct sql, but rather using SQLalchemy.


> I want to write unit test for all this. These methods of mine inherit 
> from keystone.common.sql and hence any call that these methods will 
> make will go to the db returned by keystone.common.sql when creating a 
> session. For writing a unit test this db should be a test db and not 
> the production db. So, how can I have a session of test db? or is 
> there altogether a different way of writing the unit test.
See test_backend_sql.py
>
>
> ------------------------------------------------------------------------
> *From:* Dolph Mathews <dolph.mathews at gmail.com>
> *To:* Akshat Kakkar <the_akshat at yahoo.co.in>; OpenStack Development 
> Mailing List <openstack-dev at lists.openstack.org>
> *Sent:* Tuesday, 9 July 2013 7:39 PM
> *Subject:* Re: [openstack-dev] [Keystone] How to write unit tests for 
> db methods?
>
> I'm assuming you're referring to testing backend drivers as opposed to 
> database migrations (tests/test_sql_upgrade.py).
>
> Backend agnostic tests land in tests/test_backend.py. Backend-specific 
> tests, overrides, etc belong in tests/test_backend_sql.py, 
> tests/test_backend_kvs.py, etc.
>
> Generally, you can't assume that keystone is backed by a database, 
> however, as it's entirely possible to deploy without one.
>
>
> On Tue, Jul 9, 2013 at 10:55 AM, Akshat Kakkar <the_akshat at yahoo.co.in 
> <mailto:the_akshat at yahoo.co.in>> wrote:
>
>     How to write unit tests in keystone for the methods which are
>     directly calling the backend db? I understand that for testing
>     purpose it should be a *fake db*, but how to do that in keystone?
>
>     _______________________________________________
>     OpenStack-dev mailing list
>     OpenStack-dev at lists.openstack.org
>     <mailto:OpenStack-dev at lists.openstack.org>
>     http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
>
>
> -- 
>
> -Dolph
>
>
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130710/7d486bb7/attachment.html>


More information about the OpenStack-dev mailing list