@@ -569,6 +569,7 @@ def test_patch_w_alternate_client(self):
569569 import datetime
570570 import pytz
571571 from gcloud .bigquery ._helpers import _millis
572+ from gcloud .bigquery .table import SchemaField
572573 PATH = 'projects/%s/datasets/%s/tables/%s' % (
573574 self .PROJECT , self .DS_NAME , self .TABLE_NAME )
574575 QUERY = 'select fullname, age from person_ages'
@@ -586,9 +587,11 @@ def test_patch_w_alternate_client(self):
586587 client2 = _Client (project = self .PROJECT , connection = conn2 )
587588 dataset = _Dataset (client1 )
588589 table = self ._makeOne (self .TABLE_NAME , dataset = dataset )
590+ full_name = SchemaField ('full_name' , 'STRING' , mode = 'REQUIRED' )
591+ age = SchemaField ('age' , 'INTEGER' , mode = 'OPTIONAL' )
589592
590593 table .patch (client = client2 , view_query = QUERY , location = LOCATION ,
591- expires = self .EXP_TIME )
594+ expires = self .EXP_TIME , schema = [ full_name , age ] )
592595
593596 self .assertEqual (len (conn1 ._requested ), 0 )
594597 self .assertEqual (len (conn2 ._requested ), 1 )
@@ -599,10 +602,38 @@ def test_patch_w_alternate_client(self):
599602 'view' : {'query' : QUERY },
600603 'location' : LOCATION ,
601604 'expirationTime' : _millis (self .EXP_TIME ),
605+ 'schema' : {'fields' : [
606+ {'name' : 'full_name' , 'type' : 'STRING' , 'mode' : 'REQUIRED' },
607+ {'name' : 'age' , 'type' : 'INTEGER' , 'mode' : 'OPTIONAL' }]},
602608 }
603609 self .assertEqual (req ['data' ], SENT )
604610 self ._verifyResourceProperties (table , RESOURCE )
605611
612+ def test_patch_w_schema_None (self ):
613+ # Simulate deleting schema: not sure if back-end will actually
614+ # allow this operation, but the spec says it is optional.
615+ PATH = 'projects/%s/datasets/%s/tables/%s' % (
616+ self .PROJECT , self .DS_NAME , self .TABLE_NAME )
617+ DESCRIPTION = 'DESCRIPTION'
618+ TITLE = 'TITLE'
619+ RESOURCE = self ._makeResource ()
620+ RESOURCE ['description' ] = DESCRIPTION
621+ RESOURCE ['friendlyName' ] = TITLE
622+ conn = _Connection (RESOURCE )
623+ client = _Client (project = self .PROJECT , connection = conn )
624+ dataset = _Dataset (client )
625+ table = self ._makeOne (self .TABLE_NAME , dataset = dataset )
626+
627+ table .patch (schema = None )
628+
629+ self .assertEqual (len (conn ._requested ), 1 )
630+ req = conn ._requested [0 ]
631+ self .assertEqual (req ['method' ], 'PATCH' )
632+ SENT = {'schema' : None }
633+ self .assertEqual (req ['data' ], SENT )
634+ self .assertEqual (req ['path' ], '/%s' % PATH )
635+ self ._verifyResourceProperties (table , RESOURCE )
636+
606637 def test_update_w_bound_client (self ):
607638 from gcloud .bigquery .table import SchemaField
608639 PATH = 'projects/%s/datasets/%s/tables/%s' % (
0 commit comments