def test_enqueue_same_id(self): cursor = LockedCursor(index=123) dg = DeltaGenerator(cursor=cursor) self.assertEqual(123, dg._cursor.index) test_data = "some test data" text_proto = TextProto() text_proto.body = test_data new_dg = dg._enqueue("text", text_proto) self.assertEqual(dg._cursor, new_dg._cursor) msg = self.get_message_from_queue() self.assertEqual(123, msg.metadata.delta_id) self.assertEqual(msg.delta.new_element.text.body, test_data)
def test_enqueue(self, container): dg = DeltaGenerator(container=container) self.assertEqual(0, dg._cursor.index) self.assertEqual(container, dg._container) test_data = "some test data" text_proto = TextProto() text_proto.body = test_data new_dg = dg._enqueue("text", text_proto) self.assertNotEqual(dg, new_dg) self.assertEqual(1, dg._cursor.index) self.assertEqual(container, new_dg._container) element = self.get_delta_from_queue().new_element self.assertEqual(element.text.body, test_data)
def test_enqueue_same_id(self): cursor = LockedCursor(root_container=RootContainer.MAIN, index=123) dg = DeltaGenerator(root_container=RootContainer.MAIN, cursor=cursor) self.assertEqual(123, dg._cursor.index) test_data = "some test data" text_proto = TextProto() text_proto.body = test_data new_dg = dg._enqueue("text", text_proto) self.assertEqual(dg._cursor, new_dg._cursor) msg = self.get_message_from_queue() # The last element in delta_path is the delta's index in its container. self.assertEqual(make_delta_path(RootContainer.MAIN, (), 123), msg.metadata.delta_path) self.assertEqual(msg.delta.new_element.text.body, test_data)
def test_enqueue_null(self): # Test "Null" Delta generators dg = DeltaGenerator(container=None) new_dg = dg._enqueue("empty", EmptyProto()) self.assertEqual(dg, new_dg)