<s> import unittest <EOL> from libsaas import port , xml <EOL> from libsaas . executors import test_executor <EOL> from libsaas . services import googlespreadsheets <EOL> from libsaas . services . base import MethodNotSupported <EOL> class GoogleSpreadsheetsTestCase ( unittest . TestCase ) : <EOL> def expect ( self , method = None , uri = None , params = None , headers = None ) : <EOL> if method : <EOL> self . assertEqual ( method , self . executor . request . method ) <EOL> if uri : <EOL> self . assertEqual ( self . executor . request . uri , <EOL> '<STR_LIT>' + uri ) <EOL> self . assertEqual ( self . executor . request . params , params ) <EOL> if headers : <EOL> self . assertEqual ( self . executor . request . headers , headers ) <EOL> class GoogleSpreadsheetsXMLTestCase ( GoogleSpreadsheetsTestCase ) : <EOL> def setUp ( self ) : <EOL> self . executor = test_executor . use ( ) <EOL> self . executor . set_response ( <EOL> b'<STR_LIT>' , <NUM_LIT:200> , { } ) <EOL> self . service = googlespreadsheets . GoogleSpreadsheets ( '<STR_LIT>' ) <EOL> def test_worksheets ( self ) : <EOL> if hasattr ( xml . etree , '<STR_LIT>' ) : <EOL> return <EOL> create = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:50> , <EOL> '<STR_LIT>' : <NUM_LIT:10> <EOL> } <EOL> } <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheets ( '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . create ( create . copy ( ) ) ) <EOL> self . expect ( '<STR_LIT:POST>' , '<STR_LIT>' , <EOL> params = xml . dict_to_xml ( create ) ) <EOL> update = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:15> <EOL> } <EOL> } <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . update ( '<STR_LIT>' , update . copy ( ) ) ) <EOL> self . expect ( '<STR_LIT>' , '<STR_LIT>' , <EOL> params = xml . dict_to_xml ( update ) ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . delete ( '<STR_LIT>' ) ) <EOL> self . expect ( '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> def test_rows ( self ) : <EOL> if hasattr ( xml . etree , '<STR_LIT>' ) : <EOL> return <EOL> create = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:7> , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . rows ( ) <EOL> . create ( create . copy ( ) ) ) <EOL> self . expect ( '<STR_LIT:POST>' , '<STR_LIT>' , <EOL> params = xml . dict_to_xml ( create ) ) <EOL> update = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } <EOL> } <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . row ( '<STR_LIT>' ) <EOL> . update ( '<STR_LIT>' , update . copy ( ) ) ) <EOL> self . expect ( '<STR_LIT>' , '<STR_LIT>' , <EOL> params = xml . dict_to_xml ( update ) ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . row ( '<STR_LIT>' ) <EOL> . delete ( '<STR_LIT>' ) ) <EOL> self . expect ( '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> def test_cells ( self ) : <EOL> if hasattr ( xml . etree , '<STR_LIT>' ) : <EOL> return <EOL> with port . assertRaises ( MethodNotSupported ) : <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . cells ( ) <EOL> . create ( { } ) ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . cell ( '<STR_LIT>' ) . delete ( '<STR_LIT>' ) ) <EOL> cell = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:5>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' <EOL> } <EOL> } <EOL> } <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . cell ( '<STR_LIT>' ) <EOL> . update ( '<STR_LIT>' , cell . copy ( ) ) ) <EOL> self . expect ( '<STR_LIT>' , '<STR_LIT>' , <EOL> params = xml . dict_to_xml ( cell ) ) <EOL> class GoogleSpreadsheetsJSONTestCase ( GoogleSpreadsheetsTestCase ) : <EOL> def setUp ( self ) : <EOL> self . executor = test_executor . use ( ) <EOL> self . executor . set_response ( b'<STR_LIT:{}>' , <NUM_LIT:200> , { } ) <EOL> self . service = googlespreadsheets . GoogleSpreadsheets ( '<STR_LIT>' ) <EOL> def test_spreadsheets ( self ) : <EOL> self . service . spreadsheets ( ) . get ( ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> with port . assertRaises ( MethodNotSupported ) : <EOL> self . service . spreadsheet ( '<STR_LIT:key>' ) . get ( ) <EOL> self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheets ( '<STR_LIT:v>' , '<STR_LIT:p>' ) . get ( ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . get ( ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . rows ( ) . get ( ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . rows ( ) . get ( reverse = True ) ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:true>' } ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . rows ( ) . get ( sq = '<STR_LIT>' ) ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> with port . assertRaises ( MethodNotSupported ) : <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . row ( '<STR_LIT>' ) . get ( ) ) <EOL> self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) . cells ( ) . get ( ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . cells ( ) . get ( min_col = <NUM_LIT:2> , max_col = <NUM_LIT:4> ) ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . cells ( ) . get ( min_row = <NUM_LIT:2> , max_row = <NUM_LIT:4> ) ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> ( self . service . spreadsheet ( '<STR_LIT:key>' ) . worksheet ( '<STR_LIT:id>' , '<STR_LIT:v>' , '<STR_LIT:p>' ) <EOL> . cell ( '<STR_LIT>' ) . get ( ) ) <EOL> self . expect ( '<STR_LIT:GET>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) </s>
