From 45629a9e76a6887ab14e0549e09b18ae23038295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Douglas=20Mendiz=C3=A1bal?= Date: Thu, 29 Sep 2016 11:36:30 -0500 Subject: [PATCH] Test _alternate_id logic This unit test shows an underlying issue that was causing some key_manager service methods to fail. The issue has since been fixed, as the test passes now. But let's add the test. Change-Id: I3e9e737064a167694a176cc3afb20bb5bcc59f98 Related-Bug: #1628957 --- openstack/tests/unit/test_resource.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/openstack/tests/unit/test_resource.py b/openstack/tests/unit/test_resource.py index 97a61f371..35d6e0769 100644 --- a/openstack/tests/unit/test_resource.py +++ b/openstack/tests/unit/test_resource.py @@ -633,6 +633,24 @@ class TestResource(base.TestCase): self.assertEqual(sot.alt, value2) self.assertEqual(sot.id, value2) + def test__alternate_id_from_other_property(self): + class Test(resource.Resource): + foo = resource.Body("foo") + bar = resource.Body("bar", alternate_id=True) + + # NOTE(redrobot): My expectation looking at the Test class defined + # in this test is that because the alternate_id parameter is + # is being set to True on the "bar" property of the Test class, + # then the _alternate_id() method should return the name of that "bar" + # property. + self.assertEqual("bar", Test._alternate_id()) + sot = Test(bar='bunnies') + self.assertEqual(sot.id, 'bunnies') + self.assertEqual(sot.bar, 'bunnies') + sot = Test(id='chickens', bar='bunnies') + self.assertEqual(sot.id, 'chickens') + self.assertEqual(sot.bar, 'bunnies') + def test__get_id_instance(self): class Test(resource.Resource): id = resource.Body("id")