示例#1
0
    def test__update_state_metadata(self):
        from google.longrunning import operations_pb2
        from google.protobuf.any_pb2 import Any
        from google.protobuf.struct_pb2 import Value
        from google.cloud._testing import _Monkey
        from google.cloud import operation as MUT

        operation = self._make_one(None, None)
        self.assertIsNone(operation.metadata)

        val_pb = Value(number_value=1337)
        type_url = 'type.googleapis.com/%s' % (Value.DESCRIPTOR.full_name, )
        val_any = Any(type_url=type_url, value=val_pb.SerializeToString())
        operation_pb = operations_pb2.Operation(metadata=val_any)

        with _Monkey(MUT, _TYPE_URL_MAP={type_url: Value}):
            operation._update_state(operation_pb)

        self.assertEqual(operation.metadata, val_pb)
示例#2
0
    def test__update_state_response(self):
        from google.longrunning import operations_pb2
        from google.protobuf.any_pb2 import Any
        from google.protobuf.struct_pb2 import Value
        from google.cloud._testing import _Monkey
        from google.cloud import operation as MUT

        operation = self._make_one(None, None)
        self.assertIsNone(operation.error)
        self.assertIsNone(operation.response)

        response_pb = Value(string_value='totes a response')
        type_url = 'type.googleapis.com/%s' % (Value.DESCRIPTOR.full_name, )
        response_any = Any(type_url=type_url,
                           value=response_pb.SerializeToString())
        operation_pb = operations_pb2.Operation(response=response_any)

        with _Monkey(MUT, _TYPE_URL_MAP={type_url: Value}):
            operation._update_state(operation_pb)

        self.assertIsNone(operation.error)
        self.assertEqual(operation.response, response_pb)