def test_extract_node_id(self): n = NodeID.for_host('127.0.0.1') n1 = extract_node_id(n) self.assertIs(n, n1) n2 = extract_node_id(str(n)) self.assertEqual(n, n2) node = Node(n) n3 = extract_node_id(node) self.assertEqual(n, n3) self.assertRaises(InvalidNodeIDError, extract_node_id, 'abc') self.assertRaises(TypeError, extract_node_id, 10) node = Node(n) node.id = '10' self.assertRaises(InvalidNodeIDError, extract_node_id, node)
def test_get_set_properties(self): nid = NodeID.for_host('127.0.0.1') node = Node(nid) node.session_data = 'sd1' self.assertEqual(node.session_data, 'sd1') ctrl = TestController.new_test_instance() node.subscribe(ctrl) now = datetime.now() self.assertTrue(timedelta(seconds = 0) <= now - node.subscription_timestamp <= timedelta(seconds = 3)) self.assertEqual(node.controller, ctrl) node.task_id = 'tid789' now = datetime.now() self.assertTrue(timedelta(seconds = 0) <= now - node.task_timestamp <= timedelta(seconds = 3)) self.assertEqual(node.task_id, 'tid789')
def test_dirty(self): nid = NodeID.for_host('127.0.0.1') node = Node(nid) self.assertFalse(node.dirty) node.subscribe(TestController.new_test_instance()) self.assertTrue(node.dirty) node.dirty = False node.task_id = 123 self.assertTrue(node.dirty) node.dirty = False node.session_data = '123' self.assertTrue(node.dirty) node.dirty = False