def test_getsetattr(self): bm = core.JSONableDict() self.assertNotIn('TestResource', bm) bm.test_resource = TestResource() self.assertIn('TestResource', bm) del (bm.test_resource) self.assertNotIn('TestResource', bm)
def test_crazy_addchild_ordering(self): # We should be able to add children to any element at any time, # before or after that element has been added to a parent. bm = core.JSONableDict() tr1 = TestResource({'Id': 1}) tr2 = TestResource({'Id': 2}) # Tack the TestResource onto the template bm.add(tr1) # Add a child to tr1 *after* adding it to bm tr1.add(tr2) # Then make sure tr2 is visible from the template self.assertIn('TestResource', bm['TestResource']) # Double check Ids... self.assertEqual(bm['TestResource']['Id'], 1) self.assertEqual(bm['TestResource']['TestResource']['Id'], 2) # Now mess with the nested child, and make sure those changes # are still seen in the template tr2.update({'This Is': 'A Test'}) self.assertEqual(bm['TestResource']['TestResource']['This Is'], 'A Test')
def test_contructor_dict_arg(self): # Making sure that a resource instantiated with a params dict is updated correctly update_dict = {'Test': 'A custom custructydict'} bm = core.JSONableDict() bm.add(TestResource(update_dict)) self.assertEqual(bm['TestResource'], update_dict)