JSON Home Tests and Keystone API changes

If you change the public signature of an API, or add a new API in Keystone, there is a good chance the Tests that confirm JSON home layout will break.  And that test is fairly unfriendly:  It compares a JSON doc with another JSON doc, and spews out the entirety of both JSON docs, without telling you which section breaks.  Here is how I deal with it:

First, run the test in a manner that you can do some qyerying. I did this:


tox -e py27 -- keystone.tests.unit.test_versions.VersionTestCase.test_json_home_v3 2>&1 | less

That lets me search through the output dynamically.  It runs only the one test.


Here is the change I made to the keystone/assignment/routers.py file:


If I run the test and search through the output for the value url_pattern I see that this section is new:

 u'http://docs.openstack.org/api/openstack-identity/3/rel/url_pattern': {u'href-template': u'/url_patterns/{url_pattern_id}',
 u'href-vars': {u'url_pattern_id': u'http://docs.openstack.org/api/openstack-identity/3/param/url_pattern_id'}},
 u'http://docs.openstack.org/api/openstack-identity/3/rel/url_patterns': {u'href': u'/url_patterns'},

Sorry for the formatting:  it is really long lines in the output.

To start, I modify the test_versions.py file to add something that I think will be comparable:

 json_home.build_v3_resource_relation('url_pattern'): {
 'href-template': '/url_pattern/{url_pattern_id}',
 'href-vars': {
 'url_pattern_id': json_home.Parameters.URL_PATTERN_ID},

Rerunning the test, I now see that it matches earlier:  this is in the expected output:

 'http://docs.openstack.org/api/openstack-identity/3/rel/url_pattern': {'hints': {'status': 'experimental'},
 'href-template': '/url_patterns/{url_pattern_id}',
 'href-vars': {'url_pattern_id': 'http://docs.openstack.org/api/openstack-identity/3/param/pattern_id'}},

Which looks good, but I need the second line, with url_patterns.  So I add:

 json_home.build_v3_resource_relation('url_patterns'): {
 'href': '/url_patterns'},

Note that it is href, and not href-template.



Leave a Reply

Your email address will not be published. Required fields are marked *