def test___init__(self): manager = Mock() manager.write_to_completion_cache = Mock(return_value=None) info_ = {} robj = base.Resource(manager, info_) self.assertEqual(0, manager.write_to_completion_cache.call_count) info_ = {"id": "id-with-less-than-36-char"} robj = base.Resource(manager, info_) self.assertEqual(info_["id"], robj.id) self.assertEqual(0, manager.write_to_completion_cache.call_count) id_ = "id-with-36-char-" for i in range(36 - len(id_)): id_ = id_ + "-" info_ = {"id": id_} robj = base.Resource(manager, info_) self.assertEqual(info_["id"], robj.id) self.assertEqual(1, manager.write_to_completion_cache.call_count) info_["name"] = "test-human-id" # Resource.HUMAN_ID is False robj = base.Resource(manager, info_) self.assertEqual(info_["id"], robj.id) self.assertEqual(None, robj.human_id) self.assertEqual(2, manager.write_to_completion_cache.call_count) # base.Resource.HUMAN_ID = True info_["HUMAN_ID"] = True robj = base.Resource(manager, info_) self.assertEqual(info_["id"], robj.id) self.assertEqual(info_["name"], robj.human_id) self.assertEqual(4, manager.write_to_completion_cache.call_count)
def test_human_id(self): manager = Mock() manager.write_to_completion_cache = Mock(return_value=None) info_ = {"name": "test-human-id"} robj = base.Resource(manager, info_) self.assertEqual(None, robj.human_id) info_["HUMAN_ID"] = True robj = base.Resource(manager, info_) self.assertEqual(info_["name"], robj.human_id) robj.name = "new-human-id" self.assertEqual("new-human-id", robj.human_id)
def index(self): """Get a list of all accounts with non-deleted instances""" url = "/mgmt/accounts" resp, body = self.api.client.get(url) check_for_exceptions(resp, body) if not body: raise Exception("Call to " + url + " did not return a body.") return base.Resource(self, body)
def tes___eq__(self): robj = self.get_mock_resource_obj() other = base.Resource() info_ = {"name": "test-human-id", "test_attr": 5} robj._info = info_ other._info = {} self.assertNotTrue(robj.__eq__(other)) robj._info = info_ self.assertTrue(robj.__eq__(other)) robj.id = "rid" other.id = "oid" self.assertNotTrue(robj.__eq__(other)) other.id = "rid" self.assertTrue(robj.__eq__(other)) # not instance of the same class other = Mock() self.assertNotTrue(robj.__eq__(other))
def get_mock_resource_obj(self): base.Resource.__init__ = Mock(return_value=None) robj = base.Resource() return robj