def test_set_list(self):
     list_ops_response = ops.ListOperationsResponse()
     protobuf.set(list_ops_response, 'operations', [
         {
             'name': 'foo'
         },
         ops.Operation(name='bar'),
     ])
     assert len(list_ops_response.operations) == 2
     for operation in list_ops_response.operations:
         assert isinstance(operation, ops.Operation)
     assert list_ops_response.operations[0].name == 'foo'
     assert list_ops_response.operations[1].name == 'bar'
 def test_set_pb2(self):
     operation = ops.Operation()
     protobuf.set(operation, 'name', 'foo')
     assert operation.name == 'foo'
 def test_get_pb2_default(self):
     operation = ops.Operation()
     assert protobuf.get(operation, 'foo', default='bar') == 'bar'
 def test_get_pb2_present(self):
     operation = ops.Operation(name='foo')
     assert protobuf.get(operation, 'name') == 'foo'
 def test_get_pb2_sentinel(self):
     operation = ops.Operation()
     with pytest.raises(KeyError):
         assert protobuf.get(operation, 'foo')
 def test_pb2_truthy(self):
     operation = ops.Operation(name='bar')
     protobuf.setdefault(operation, 'name', 'foo')
     assert operation.name == 'bar'
 def test_pb2_falsy(self):
     operation = ops.Operation()
     protobuf.setdefault(operation, 'name', 'foo')
     assert operation.name == 'foo'