<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:12pt">If I follow tests for "Catalog", I see that only one test is overwritten in test_backend_sql.py while the remaining 2 test are new (i.e. not declared in test_backend.py). I am only having SQL driver interface. So, should I write any test in test_backend.py or not?<br>Can I write tests only in test_backend_sql.py and a blank class definition in test_backend.py and nothing anywhere else?<br>What all care should I take in doing this?<br><br><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" size="2"> <b><span style="font-weight:bold;">From:</span></b> Dolph Mathews <dolph.mathews@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Akshat Kakkar
 <the_akshat@yahoo.co.in> <br><b><span style="font-weight: bold;">Cc:</span></b> Adam Young <ayoung@redhat.com>; OpenStack Development Mailing List <openstack-dev@lists.openstack.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Monday, 15 July 2013 5:44 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 class="y_msg_container"><br><div id="yiv9248864649"><div dir="ltr"><br><div class="yiv9248864649gmail_extra"><div class="yiv9248864649gmail_quote">On Mon, Jul 15, 2013 at 9:36 AM, Akshat Kakkar <span dir="ltr"><<a rel="nofollow" ymailto="mailto:the_akshat@yahoo.co.in" target="_blank" href="mailto:the_akshat@yahoo.co.in">the_akshat@yahoo.co.in</a>></span> wrote:<br>
<blockquote class="yiv9248864649gmail_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="yiv9248864649gmail_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="yiv9248864649">  </div><div style="font-family:arial, helvetica, sans-serif;font-size:12pt;"><div class="yiv9248864649"> </div><div style="font-size:12pt;">
<div class="yiv9248864649"> </div><div dir="ltr"><div class="yiv9248864649"> <hr size="1">  </div><font face="Arial"><div class="yiv9248864649"> <b><span style="font-weight:bold;">From:</span></b> Adam Young <<a rel="nofollow" ymailto="mailto:ayoung@redhat.com" target="_blank" href="mailto:ayoung@redhat.com">ayoung@redhat.com</a>><br>
 <b><span style="font-weight:bold;">To:</span></b> Akshat Kakkar <<a rel="nofollow" ymailto="mailto:the_akshat@yahoo.co.in" target="_blank" href="mailto:the_akshat@yahoo.co.in">the_akshat@yahoo.co.in</a>> <br><b><span style="font-weight:bold;">Cc:</span></b> OpenStack Development Mailing List <<a rel="nofollow" ymailto="mailto:openstack-dev@lists.openstack.org" target="_blank" href="mailto:openstack-dev@lists.openstack.org">openstack-dev@lists.openstack.org</a>>;
 "<a rel="nofollow" ymailto="mailto:dolph.mathews@gmail.com" target="_blank" href="mailto:dolph.mathews@gmail.com">dolph.mathews@gmail.com</a>" <<a rel="nofollow" ymailto="mailto:dolph.mathews@gmail.com" target="_blank" href="mailto:dolph.mathews@gmail.com">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="yiv9248864649h5"><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="yiv9248864649h5"> <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-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" ymailto="mailto:ayoung@redhat.com" target="_blank" href="mailto:ayoung@redhat.com"><ayoung@redhat.com></a><br>
                <b><span style="font-weight:bold;">To:</span></b>
                <a rel="nofollow" ymailto="mailto:openstack-dev@lists.openstack.org" target="_blank" href="mailto:openstack-dev@lists.openstack.org">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-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" ymailto="mailto:dolph.mathews@gmail.com" target="_blank" href="mailto:dolph.mathews@gmail.com"><dolph.mathews@gmail.com></a><br>
                              <b><span style="font-weight:bold;">To:</span></b>
                              Akshat Kakkar <a rel="nofollow" ymailto="mailto:the_akshat@yahoo.co.in" target="_blank" href="mailto:the_akshat@yahoo.co.in"><the_akshat@yahoo.co.in></a>;
                              OpenStack Development Mailing List <a rel="nofollow" ymailto="mailto:openstack-dev@lists.openstack.org" target="_blank" href="mailto:openstack-dev@lists.openstack.org"><openstack-dev@lists.openstack.org></a></font><font face="Arial"><a rel="nofollow" ymailto="mailto:openstack-dev@lists.openstack.org" target="_blank" href="mailto:openstack-dev@lists.openstack.org">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" ymailto="mailto:the_akshat@yahoo.co.in" target="_blank" href="mailto:the_akshat@yahoo.co.in">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" ymailto="mailto:OpenStack-dev@lists.openstack.org" target="_blank" href="mailto:OpenStack-dev@lists.openstack.org">OpenStack-dev@lists.openstack.org</a><br>
                                    <a rel="nofollow" target="_blank" href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev">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" ymailto="mailto:OpenStack-dev@lists.openstack.org" target="_blank" href="mailto:OpenStack-dev@lists.openstack.org">OpenStack-dev@lists.openstack.org</a>
<a rel="nofollow" target="_blank" href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev">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" ymailto="mailto:OpenStack-dev@lists.openstack.org" target="_blank" href="mailto:OpenStack-dev@lists.openstack.org">OpenStack-dev@lists.openstack.org</a><br>
              <a rel="nofollow" target="_blank" href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev">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></div><br><br></div> </div> </div>  </div></body></html>