<s> import unittest <EOL> import os <EOL> import teradata <EOL> from teradata import tdrest , util <EOL> class TdRestTest ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . username = cls . password = util . setupTestUser ( udaExec , dsn ) <EOL> def testGlobals ( self ) : <EOL> self . assertEqual ( tdrest . apilevel , "<STR_LIT>" ) <EOL> self . assertEqual ( tdrest . threadsafety , <NUM_LIT:1> ) <EOL> self . assertEqual ( tdrest . paramstyle , "<STR_LIT>" ) <EOL> def testBadHost ( self ) : <EOL> badHost = "<STR_LIT>" <EOL> with self . assertRaises ( tdrest . InterfaceError ) as cm : <EOL> tdrest . connect ( <EOL> host = badHost , system = system , username = self . username , <EOL> password = self . password ) <EOL> self . assertEqual ( cm . exception . code , tdrest . REST_ERROR ) <EOL> self . assertTrue ( badHost in cm . exception . msg , <EOL> '<STR_LIT>' . format ( <EOL> badHost , cm . exception . msg ) ) <EOL> def testSystemNotFound ( self ) : <EOL> with self . assertRaises ( tdrest . InterfaceError ) as cm : <EOL> tdrest . connect ( <EOL> host = host , system = "<STR_LIT>" , username = self . username , <EOL> password = self . password ) <EOL> self . assertEqual ( cm . exception . code , <NUM_LIT> ) <EOL> self . assertTrue ( <EOL> "<STR_LIT>" in cm . exception . msg , <EOL> '<STR_LIT>' . format ( cm . exception . msg ) ) <EOL> def testBadCredentials ( self ) : <EOL> with self . assertRaises ( tdrest . DatabaseError ) as cm : <EOL> tdrest . connect ( <EOL> host = host , system = system , username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> self . assertEqual ( cm . exception . code , <NUM_LIT> , cm . exception . msg ) <EOL> def testConnect ( self ) : <EOL> conn = tdrest . connect ( <EOL> host = host , system = system , username = self . username , <EOL> password = self . password ) <EOL> self . assertIsNotNone ( conn ) <EOL> conn . close ( ) <EOL> def testCursorBasics ( self ) : <EOL> with tdrest . connect ( host = host , system = system , username = self . username , <EOL> password = self . password ) as conn : <EOL> self . assertIsNotNone ( conn ) <EOL> cursor = conn . cursor ( ) <EOL> count = <NUM_LIT:0> <EOL> for row in cursor . execute ( "<STR_LIT>" ) : <EOL> self . assertEqual ( len ( row ) , <NUM_LIT:2> ) <EOL> self . assertIsNotNone ( row [ <NUM_LIT:0> ] ) <EOL> self . assertIsNotNone ( row [ '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( row [ '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( row . InfoKey ) <EOL> self . assertIsNotNone ( row . infokey ) <EOL> self . assertIsNotNone ( row [ <NUM_LIT:1> ] ) <EOL> self . assertIsNotNone ( row [ '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( row [ '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( row . infodata ) <EOL> self . assertIsNotNone ( row . InfoData ) <EOL> row [ <NUM_LIT:0> ] = "<STR_LIT>" <EOL> self . assertEqual ( row [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( row [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( row . infokey , "<STR_LIT>" ) <EOL> row [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> self . assertEqual ( row [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( row [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( row . infokey , "<STR_LIT>" ) <EOL> row . infokey = "<STR_LIT>" <EOL> self . assertEqual ( row [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( row [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( row . InfoKey , "<STR_LIT>" ) <EOL> count += <NUM_LIT:1> <EOL> self . assertEqual ( cursor . description [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( cursor . description [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , tdrest . STRING ) <EOL> self . assertEqual ( cursor . description [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> self . assertEqual ( cursor . description [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , tdrest . STRING ) <EOL> self . assertEqual ( count , <NUM_LIT:3> ) <EOL> def testExecuteWithParamsMismatch ( self ) : <EOL> with self . assertRaises ( teradata . InterfaceError ) as cm : <EOL> with tdrest . connect ( host = host , system = system , <EOL> username = self . username , <EOL> password = self . password , <EOL> autoCommit = True ) as conn : <EOL> self . assertIsNotNone ( conn ) <EOL> with conn . cursor ( ) as cursor : <EOL> cursor . execute ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> cursor . execute ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , ( <NUM_LIT:1> , "<STR_LIT>" , ) ) <EOL> self . assertEqual ( cm . exception . code , <NUM_LIT> , cm . exception . msg ) <EOL> def testSessionAlreadyClosed ( self ) : <EOL> with tdrest . connect ( host = host , system = system , username = self . username , <EOL> password = self . password , autoCommit = True ) as conn : <EOL> self . assertIsNotNone ( conn ) <EOL> with conn . template . connect ( ) as http : <EOL> http . delete ( <EOL> "<STR_LIT>" . format ( conn . system , <EOL> conn . sessionId ) ) <EOL> configFiles = [ os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ] <EOL> udaExec = teradata . UdaExec ( configFiles = configFiles , configureLogging = False ) <EOL> dsn = '<STR_LIT>' <EOL> restConfig = udaExec . config . section ( dsn ) <EOL> host = restConfig [ '<STR_LIT:host>' ] <EOL> system = restConfig [ '<STR_LIT>' ] <EOL> super_username = restConfig [ '<STR_LIT:username>' ] <EOL> super_password = restConfig [ '<STR_LIT:password>' ] <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
