summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2011-02-23 12:36:09 -0800
committerJustin Santa Barbara <justin@fathomdb.com>2011-02-23 12:36:09 -0800
commitb3b005f50de54b5ef6c62e387dcec5a123f93cf6 (patch)
tree70aa46c02622e40341cc7d6311b6a265bf65c263 /nova/tests
parent5283e1c131a21ea4963c702a7137536f7b894bb6 (diff)
Cope when we pass a non-list to xpath_select - wrap it in a list
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_minixpath.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/nova/tests/test_minixpath.py b/nova/tests/test_minixpath.py
index 7fddcf9e9..3b1bdf40b 100644
--- a/nova/tests/test_minixpath.py
+++ b/nova/tests/test_minixpath.py
@@ -139,3 +139,41 @@ class MiniXPathTestCase(test.TestCase):
self.assertRaises(exception.Error, xp, [], "a//a")
self.assertRaises(exception.Error, xp, [], "a//a/")
self.assertRaises(exception.Error, xp, [], "a/a/")
+
+ def test_real_failure1(self):
+ # Real world failure case...
+ # We weren't coping when the input was a Dictionary instead of a List
+ # This led to test_accepts_dictionaries
+ xp = utils.minixpath_select
+
+ inst = {'fixed_ip': {'floating_ips': [{'address': '1.2.3.4'}],
+ 'address': '192.168.0.3'},
+ 'hostname': ''}
+
+ private_ips = xp(inst, 'fixed_ip/address')
+ public_ips = xp(inst, 'fixed_ip/floating_ips/address')
+ self.assertEquals(['192.168.0.3'], private_ips)
+ self.assertEquals(['1.2.3.4'], public_ips)
+
+ def test_accepts_dictionaries(self):
+ xp = utils.minixpath_select
+
+ input = {'a': [1, 2, 3]}
+ self.assertEquals([1, 2, 3], xp(input, "a"))
+ self.assertEquals([], xp(input, "a/b"))
+ self.assertEquals([], xp(input, "a/b/c"))
+
+ input = {'a': {'b': [1, 2, 3]}}
+ self.assertEquals([{'b': [1, 2, 3]}], xp(input, "a"))
+ self.assertEquals([1, 2, 3], xp(input, "a/b"))
+ self.assertEquals([], xp(input, "a/b/c"))
+
+ input = {'a': [{'b': [1, 2, 3]}, {'b': [4, 5, 6]}]}
+ self.assertEquals([1, 2, 3, 4, 5, 6], xp(input, "a/b"))
+ self.assertEquals([], xp(input, "a/b/c"))
+
+ input = {'a': [1, 2, {'b': 'b_1'}]}
+ self.assertEquals([1, 2, {'b': 'b_1'}], xp(input, "a"))
+ self.assertEquals(['b_1'], xp(input, "a/b"))
+
+