Merge "Provide better fallback when finding id values"
This commit is contained in:
commit
bda6753837
@ -290,7 +290,10 @@ class Resource(object):
|
||||
if name in self._body:
|
||||
return self._body[name]
|
||||
else:
|
||||
try:
|
||||
return self._body[self._alternate_id()]
|
||||
except KeyError:
|
||||
return None
|
||||
else:
|
||||
return object.__getattribute__(self, name)
|
||||
|
||||
|
@ -569,6 +569,31 @@ class TestResource(base.TestCase):
|
||||
self.assertIn("y", Test._uri_mapping())
|
||||
self.assertIn("z", Test._uri_mapping())
|
||||
|
||||
def test__getattribute__id_in_body(self):
|
||||
id = "lol"
|
||||
sot = resource2.Resource(id=id)
|
||||
|
||||
result = getattr(sot, "id")
|
||||
self.assertEqual(result, id)
|
||||
|
||||
def test__getattribute__id_with_alternate(self):
|
||||
id = "lol"
|
||||
|
||||
class Test(resource2.Resource):
|
||||
blah = resource2.Body("blah", alternate_id=True)
|
||||
|
||||
sot = Test(blah=id)
|
||||
|
||||
result = getattr(sot, "id")
|
||||
self.assertEqual(result, id)
|
||||
|
||||
def test__getattribute__id_without_alternate(self):
|
||||
class Test(resource2.Resource):
|
||||
id = None
|
||||
|
||||
sot = Test()
|
||||
self.assertIsNone(sot.id)
|
||||
|
||||
def test__alternate_id_None(self):
|
||||
self.assertEqual("", resource2.Resource._alternate_id())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user