Fix collection order issues and unit test failures
A randomized PYTHONHASHSEED caused the glance API to return certain data in a nondeterministic order, breaking some tests. This patch sorts the returned data before testing against a pre-sorted expected values. Change-Id: Ie294b64738bd33b31aea915183c30b5b8db2eb65
This commit is contained in:
parent
9360baac78
commit
9d4eda50f2
@ -14,6 +14,24 @@
|
||||
# under the License.
|
||||
|
||||
import StringIO
|
||||
import urllib
|
||||
import urlparse
|
||||
|
||||
|
||||
def sort_url_by_qs_keys(url):
|
||||
#NOTE(kragniz): this only sorts the keys of the query string of a url.
|
||||
# For example, an input of '/v2/tasks?sort_key=id&sort_dir=asc&limit=10'
|
||||
# returns '/v2/tasks?limit=10&sort_dir=asc&sort_key=id'. This is to prevent
|
||||
# non-deterministic ordering of the query string causing problems with unit
|
||||
# tests.
|
||||
parsed = urlparse.urlparse(url)
|
||||
queries = urlparse.parse_qsl(parsed.query, True)
|
||||
sorted_query = sorted(queries, key=lambda x: x[0])
|
||||
encoded_sorted_query = urllib.urlencode(sorted_query, True)
|
||||
url_parts = (parsed.scheme, parsed.netloc, parsed.path,
|
||||
parsed.params, encoded_sorted_query,
|
||||
parsed.fragment)
|
||||
return urlparse.urlunparse(url_parts)
|
||||
|
||||
|
||||
class FakeHTTPResponse(object):
|
||||
|
@ -179,7 +179,8 @@ class TestStore(base.StoreBaseTest):
|
||||
location, size, checksum, _ = self.store.add(expected_image_id,
|
||||
image,
|
||||
expected_size)
|
||||
self.assertEqual(expected_location, location)
|
||||
self.assertEqual(utils.sort_url_by_qs_keys(expected_location),
|
||||
utils.sort_url_by_qs_keys(location))
|
||||
self.assertEqual(expected_size, size)
|
||||
self.assertEqual(expected_checksum, checksum)
|
||||
|
||||
@ -208,7 +209,8 @@ class TestStore(base.StoreBaseTest):
|
||||
HttpConn.return_value = FakeHTTPConnection()
|
||||
location, size, checksum, _ = self.store.add(expected_image_id,
|
||||
image, 0)
|
||||
self.assertEqual(expected_location, location)
|
||||
self.assertEqual(utils.sort_url_by_qs_keys(expected_location),
|
||||
utils.sort_url_by_qs_keys(location))
|
||||
self.assertEqual(expected_size, size)
|
||||
self.assertEqual(expected_checksum, checksum)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user