<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 15, 2013 at 9:36 AM, Akshat Kakkar <span dir="ltr"><<a href="mailto:the_akshat@yahoo.co.in" target="_blank">the_akshat@yahoo.co.in</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:arial,helvetica,sans-serif">
<div>As in my methods, I do not pass session object from outside so I am followin the unit test for catalog. But what I am unable to understand is that there are some test in test_backend.py and some in test_backend_sql.py. What is the difference in between the two?</div>
</div></div></blockquote><div><br></div><div>Tests in test_backend.py are run against all implementations of a driver's interface (KVS, SQL, LDAP, memcache, etc). Each driver type has a module (e.g. test_backend_sql.py) that sets up & tears down a backend for the driver, inherits tests from test_backend.py, overwrites/extends tests as necessary to document exceptions to the expected behavior (e.g. LDAP doesn't support multiple domains). Follow the inheritance hierarchy for any given class in test_backend_sql.py to illustrate.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:arial,helvetica,sans-serif">
<div><br></div><div class=""> </div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt"><div class=""> </div><div style="font-family:'times new roman','new york',times,serif;font-size:12pt">
<div class=""> </div><div dir="ltr"><div class=""> <hr size="1"> </div><font face="Arial"><div class=""> <b><span style="font-weight:bold">From:</span></b> Adam Young <<a href="mailto:ayoung@redhat.com" target="_blank">ayoung@redhat.com</a>><br>
<b><span style="font-weight:bold">To:</span></b> Akshat Kakkar <<a href="mailto:the_akshat@yahoo.co.in" target="_blank">the_akshat@yahoo.co.in</a>> <br><b><span style="font-weight:bold">Cc:</span></b> OpenStack Development Mailing List <<a href="mailto:openstack-dev@lists.openstack.org" target="_blank">openstack-dev@lists.openstack.org</a>>;
"<a href="mailto:dolph.mathews@gmail.com" target="_blank">dolph.mathews@gmail.com</a>" <<a href="mailto:dolph.mathews@gmail.com" target="_blank">dolph.mathews@gmail.com</a>> <br> <b><span style="font-weight:bold">Sent:</span></b> Thursday, 11 July 2013 4:29 PM</div>
<div><div class="h5"><br> <b><span style="font-weight:bold">Subject:</span></b> Re: [openstack-dev] [Keystone] How to write unit tests for db methods?<br> </div></div></font> </div><div><div class="h5"> <div><br><div>
<div>
<div>On 07/11/2013 05:23 AM, Akshat Kakkar
wrote:<br>
</div>
<blockquote type="cite">
<div style="font-size:12pt;font-family:arial,helvetica,sans-serif">
<div><br>
<span>The methods of read/write/update/delete of records in
the tables are written using SQLalchemy only and no direct
sql is used.</span></div>
<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif"><br>
<span></span></div>
<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif"><span>I have implemented the things on
the lines of trusts only. Similar to trusts, I am also
having RESTful APIs and unit tests for them are succesfully
written. </span><span><span>In test_backend_sql.py, it is
seen that no unit tests are defined for trusts. </span>So,
it's confusing for me to implement the unit test for my
backend sql code.</span></div>
</div>
</blockquote>
<br>
Yeah, trusts themselves are pretty simple as far as REST, and they
are exercised via the Token backend code as well as test_auth.py and
test_v3_auth.py.<br>
<br>
Look at the tests for identity and catalog, those should be a better
example to follow.<br>
<br>
<br>
<blockquote type="cite">
<div style="font-size:12pt;font-family:arial,helvetica,sans-serif">
<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif"><br>
<span></span></div>
<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:arial,helvetica,sans-serif"><span>I know I am confusing the things
and I apologise for that, but I am asking because of that
confusion only!<br>
</span></div>
<div><br>
</div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt">
<div style="font-family:'times new roman','new york',times,serif;font-size:12pt">
<div dir="ltr">
<hr size="1"> <font face="Arial"> <b><span style="font-weight:bold">From:</span></b> Adam
Young <a rel="nofollow" href="mailto:ayoung@redhat.com" target="_blank"><ayoung@redhat.com></a><br>
<b><span style="font-weight:bold">To:</span></b>
<a rel="nofollow" href="mailto:openstack-dev@lists.openstack.org" target="_blank">openstack-dev@lists.openstack.org</a> <br>
<b><span style="font-weight:bold">Sent:</span></b>
Thursday, 11 July 2013 4:28 AM<br>
<b><span style="font-weight:bold">Subject:</span></b>
Re: [openstack-dev] [Keystone] How to write unit tests
for db methods?<br>
</font> </div>
<div><br>
<div>
<div>
<div>On
07/10/2013 06:56 AM, Akshat Kakkar wrote:<br>
</div>
<blockquote type="cite">
<div style="font-size:12pt;font-family:arial,helvetica,sans-serif">I have
added 2 tables to keystone.</div>
</blockquote>
<br>
This should be done in a migration, and should be
tested using the test_db_update.py file.<br>
<br>
<blockquote type="cite">
<div style="font-size:12pt;font-family:arial,helvetica,sans-serif"> I have
methods which do the read/write/update/delete of
records in these tables. </div>
</blockquote>
PLease explain. We are not doing direct sql, but
rather using SQLalchemy.<br>
<br>
<br>
<blockquote type="cite">
<div style="font-size:12pt;font-family:arial,helvetica,sans-serif">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.<br>
</div>
</blockquote>
See test_backend_sql.py<br>
<blockquote type="cite">
<div style="font-size:12pt;font-family:arial,helvetica,sans-serif"><br>
<div><br>
</div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt">
<div style="font-family:'times new roman','new york',times,serif;font-size:12pt">
<div dir="ltr">
<hr size="1"> <font face="Arial">
<b><span style="font-weight:bold">From:</span></b>
Dolph Mathews <a rel="nofollow" href="mailto:dolph.mathews@gmail.com" target="_blank"><dolph.mathews@gmail.com></a><br>
<b><span style="font-weight:bold">To:</span></b>
Akshat Kakkar <a rel="nofollow" href="mailto:the_akshat@yahoo.co.in" target="_blank"><the_akshat@yahoo.co.in></a>;
OpenStack Development Mailing List <a rel="nofollow" href="mailto:openstack-dev@lists.openstack.org" target="_blank"><openstack-dev@lists.openstack.org></a></font><font face="Arial"><a rel="nofollow" href="mailto:openstack-dev@lists.openstack.org" target="_blank">see
</a> <br>
<b><span style="font-weight:bold">Sent:</span></b>
Tuesday, 9 July 2013 7:39 PM<br>
<b><span style="font-weight:bold">Subject:</span></b>
Re: [openstack-dev] [Keystone] How to
write unit tests for db methods?<br>
</font> </div>
<div><br>
<div>
<div dir="ltr">I'm assuming you're
referring to testing backend drivers as
opposed to database migrations
(tests/test_sql_upgrade.py).
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>Generally, you can't
assume that keystone is backed by a
database, however, as it's entirely
possible to deploy without one.</div>
</div>
<div><br>
<br>
<div>
On Tue, Jul 9, 2013 at 10:55 AM,
Akshat Kakkar <span dir="ltr"><<a rel="nofollow" href="mailto:the_akshat@yahoo.co.in" target="_blank">the_akshat@yahoo.co.in</a>></span>
wrote:<br>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>
<div style="font-size:12pt;font-family:arial,helvetica,sans-serif">
<div>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?<br>
</div>
</div>
</div>
<br>
_______________________________________________<br>
OpenStack-dev mailing list<br>
<a rel="nofollow" href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.org</a><br>
<a rel="nofollow" href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div><br>
</div>
-Dolph </div>
</div>
<br>
<br>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
OpenStack-dev mailing list
<a rel="nofollow" href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.org</a>
<a rel="nofollow" href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a>
</pre>
</blockquote>
<br>
</div>
</div>
<br>
_______________________________________________<br>
OpenStack-dev mailing list<br>
<a rel="nofollow" href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.org</a><br>
<a rel="nofollow" href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
<br>
<br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</div>
</div><br><br></div> </div></div></div> </div> </div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><br></div>-Dolph
</div></div>