def test_hash_changes_on_changing_everything(self): info_node = InformationNode(randomPK, **temp_info) old_hash = info_node._info_hash info_node._pk = randint(1,1000) new_hash = info_node._info_hash self.assertTrue(check_valid_hash(new_hash)) self.assertNotEqual(old_hash, new_hash) info_node._data_holder = {} old_hash, new_hash = new_hash, info_node._info_hash self.assertTrue(check_valid_hash(new_hash)) self.assertNotEqual(old_hash, new_hash)
def test_information_node_creation(self): info_node = InformationNode(randomPK, **temp_info) self.assertIsInstance(info_node, InformationNode) self.assertEqual(info_node._pk, randomPK) self.assertEqual(info_node._data_holder, temp_info) self.assertEqual(info_node._info_hash, hash_md5(str(info_node))) self.assertTrue(check_valid_hash(info_node._info_hash))
def test_add_child(self): update_queue = set() parent = Node(randomPK, update_queue) childPK = randomPK + 1 old_sync_hash = parent.get_sync_hash() child = Node(childPK, set()) parent.add_child(child) new_sync_hash = parent.get_sync_hash() self.assertEqual(child._parent, parent) self.assertIn(child, parent._children) self.assertEqual(parent._number_of_children(), 1) for x in sum((old_sync_hash, new_sync_hash), ()): if x != DEFAULT_HASH_VALUE: self.assertTrue(check_valid_hash(x)) self.assertTrue(TestNodeCore.check_sync_hash_old_new(old_sync_hash, new_sync_hash, False, True, False)) with self.assertRaises(NotImplementedError): parent.remove_child(childPK) # update_queue should have only parent added. self.assertSetEqual(parent._update_hash_queue, set([parent._pk, child._pk]))
def test_hash_changes_on_changes(self): info_node = InformationNode(randomPK, **temp_info) old_hash = info_node._info_hash info_node.name = "something else" new_hash = info_node._info_hash self.assertNotEqual(old_hash, new_hash) self.assertTrue(check_valid_hash(new_hash))
def test_hash_changes_on_setting_getting_deleting_data(self): node = Node(randomPK, set()) old_hash = node.get_hash() node.abc = "abc" new_hash = node.get_hash() self.assertTrue(check_valid_hash(new_hash)) self.assertNotEqual(old_hash, new_hash) temp = node.abc old_hash, new_hash = new_hash, node.get_hash() self.assertEqual(new_hash, old_hash) del node.abc new_hash = node.get_hash() self.assertTrue(check_valid_hash(new_hash)) self.assertNotEqual(old_hash, new_hash)
def test_hash_changes_on_delete(self): info_node = InformationNode(randomPK, **temp_info) old_hash = info_node._info_hash del info_node.name new_hash = info_node._info_hash self.assertTrue(check_valid_hash(new_hash)) self.assertNotEqual(old_hash, new_hash)
def test_hash_changes_on_setting(self): info_node = InformationNode(randomPK) old_hash = info_node._info_hash info_node.abc = "abc" new_hash = info_node._info_hash self.assertTrue(check_valid_hash(new_hash)) self.assertNotEqual(new_hash, old_hash)