Exemplo n.º 1
0
 def testBadCredentials(self):
     with self.assertRaises(tdrest.DatabaseError) as cm:
         tdrest.connect(host=host,
                        system=system,
                        username="******",
                        password="******")
     # print(cm.exception)
     self.assertEqual(cm.exception.code, 8017, cm.exception.msg)
Exemplo n.º 2
0
 def testSystemNotFound(self):
     with self.assertRaises(tdrest.InterfaceError) as cm:
         tdrest.connect(
             host=host, system="unknown", username=self.username,
             password=self.password)
     self.assertEqual(cm.exception.code, 404)
     # print(cm.exception)
     self.assertTrue(
         "404" in cm.exception.msg,
         '404 not found in "{}"'.format(cm.exception.msg))
Exemplo n.º 3
0
 def testSystemNotFound(self):
     with self.assertRaises(tdrest.InterfaceError) as cm:
         tdrest.connect(host=host,
                        system="unknown",
                        username=self.username,
                        password=self.password)
     self.assertEqual(cm.exception.code, 404)
     # print(cm.exception)
     self.assertTrue("404" in cm.exception.msg,
                     '404 not found in "{}"'.format(cm.exception.msg))
Exemplo n.º 4
0
 def testBadHost(self):
     badHost = "badhostname"
     with self.assertRaises(tdrest.InterfaceError) as cm:
         tdrest.connect(
             host=badHost, system=system, username=self.username,
             password=self.password)
     self.assertEqual(cm.exception.code, tdrest.REST_ERROR)
     self.assertTrue(badHost in cm.exception.msg,
                     '{} not found in "{}"'.format(
                         badHost, cm.exception.msg))
Exemplo n.º 5
0
 def testBadHost(self):
     badHost = "badhostname"
     with self.assertRaises(tdrest.InterfaceError) as cm:
         tdrest.connect(host=badHost,
                        system=system,
                        username=self.username,
                        password=self.password)
     self.assertEqual(cm.exception.code, tdrest.REST_ERROR)
     self.assertTrue(
         badHost in cm.exception.msg,
         '{} not found in "{}"'.format(badHost, cm.exception.msg))
Exemplo n.º 6
0
 def testConnect(self):
     conn = tdrest.connect(host=host,
                           system=system,
                           username=self.username,
                           password=self.password)
     self.assertIsNotNone(conn)
     conn.close()
Exemplo n.º 7
0
 def testSessionAlreadyClosed(self):
     with tdrest.connect(host=host, system=system, username=self.username,
                         password=self.password, autoCommit=True) as conn:
         self.assertIsNotNone(conn)
         with conn.template.connect() as http:
             http.delete(
                 "/systems/{}/sessions/{}".format(conn.system,
                                                  conn.sessionId))
Exemplo n.º 8
0
 def testSessionAlreadyClosed(self):
     with tdrest.connect(host=host,
                         system=system,
                         username=self.username,
                         password=self.password,
                         autoCommit=True) as conn:
         self.assertIsNotNone(conn)
         with conn.template.connect() as http:
             http.delete("/systems/{}/sessions/{}".format(
                 conn.system, conn.sessionId))
Exemplo n.º 9
0
 def testExecuteWithParamsMismatch(self):
     with self.assertRaises(teradata.InterfaceError) as cm:
         with tdrest.connect(host=host, system=system,
                             username=self.username,
                             password=self.password,
                             autoCommit=True) as conn:
             self.assertIsNotNone(conn)
             with conn.cursor() as cursor:
                 cursor.execute(
                     "CREATE TABLE testExecuteWithParamsMismatch (id INT, "
                     "name VARCHAR(128), dob TIMESTAMP)")
                 cursor.execute(
                     "INSERT INTO testExecuteWithParamsMismatch "
                     "VALUES (?, ?, ?)", (1, "TEST", ))
     self.assertEqual(cm.exception.code, 400, cm.exception.msg)
Exemplo n.º 10
0
 def testExecuteWithParamsMismatch(self):
     with self.assertRaises(teradata.InterfaceError) as cm:
         with tdrest.connect(host=host,
                             system=system,
                             username=self.username,
                             password=self.password,
                             autoCommit=True) as conn:
             self.assertIsNotNone(conn)
             with conn.cursor() as cursor:
                 cursor.execute(
                     "CREATE TABLE testExecuteWithParamsMismatch (id INT, "
                     "name VARCHAR(128), dob TIMESTAMP)")
                 cursor.execute(
                     "INSERT INTO testExecuteWithParamsMismatch "
                     "VALUES (?, ?, ?)", (
                         1,
                         "TEST",
                     ))
     self.assertEqual(cm.exception.code, 400, cm.exception.msg)
Exemplo n.º 11
0
    def testCursorBasics(self):
        with tdrest.connect(host=host,
                            system=system,
                            username=self.username,
                            password=self.password) as conn:
            self.assertIsNotNone(conn)
            cursor = conn.cursor()
            count = 0
            for row in cursor.execute("SELECT * FROM DBC.DBCInfo"):
                self.assertEqual(len(row), 2)
                self.assertIsNotNone(row[0])
                self.assertIsNotNone(row['InfoKey'])
                self.assertIsNotNone(row['infokey'])
                self.assertIsNotNone(row.InfoKey)
                self.assertIsNotNone(row.infokey)
                self.assertIsNotNone(row[1])
                self.assertIsNotNone(row['InfoData'])
                self.assertIsNotNone(row['infodata'])
                self.assertIsNotNone(row.infodata)
                self.assertIsNotNone(row.InfoData)

                row[0] = "test1"
                self.assertEqual(row[0], "test1")
                self.assertEqual(row['InfoKey'], "test1")
                self.assertEqual(row.infokey, "test1")

                row['infokey'] = "test2"
                self.assertEqual(row[0], "test2")
                self.assertEqual(row['InfoKey'], "test2")
                self.assertEqual(row.infokey, "test2")

                row.infokey = "test3"
                self.assertEqual(row[0], "test3")
                self.assertEqual(row['InfoKey'], "test3")
                self.assertEqual(row.InfoKey, "test3")
                count += 1

            self.assertEqual(cursor.description[0][0], "InfoKey")
            self.assertEqual(cursor.description[0][1], tdrest.STRING)
            self.assertEqual(cursor.description[1][0], "InfoData")
            self.assertEqual(cursor.description[1][1], tdrest.STRING)
            self.assertEqual(count, 3)
Exemplo n.º 12
0
    def testCursorBasics(self):
        with tdrest.connect(host=host, system=system, username=self.username,
                            password=self.password) as conn:
            self.assertIsNotNone(conn)
            cursor = conn.cursor()
            count = 0
            for row in cursor.execute("SELECT * FROM DBC.DBCInfo"):
                self.assertEqual(len(row), 2)
                self.assertIsNotNone(row[0])
                self.assertIsNotNone(row['InfoKey'])
                self.assertIsNotNone(row['infokey'])
                self.assertIsNotNone(row.InfoKey)
                self.assertIsNotNone(row.infokey)
                self.assertIsNotNone(row[1])
                self.assertIsNotNone(row['InfoData'])
                self.assertIsNotNone(row['infodata'])
                self.assertIsNotNone(row.infodata)
                self.assertIsNotNone(row.InfoData)

                row[0] = "test1"
                self.assertEqual(row[0], "test1")
                self.assertEqual(row['InfoKey'], "test1")
                self.assertEqual(row.infokey, "test1")

                row['infokey'] = "test2"
                self.assertEqual(row[0], "test2")
                self.assertEqual(row['InfoKey'], "test2")
                self.assertEqual(row.infokey, "test2")

                row.infokey = "test3"
                self.assertEqual(row[0], "test3")
                self.assertEqual(row['InfoKey'], "test3")
                self.assertEqual(row.InfoKey, "test3")
                count += 1

            self.assertEqual(cursor.description[0][0], "InfoKey")
            self.assertEqual(cursor.description[0][1], tdrest.STRING)
            self.assertEqual(cursor.description[1][0], "InfoData")
            self.assertEqual(cursor.description[1][1], tdrest.STRING)
            self.assertEqual(count, 3)
Exemplo n.º 13
0
 def testConnect(self):
     conn = tdrest.connect(
         host=host, system=system, username=self.username,
         password=self.password)
     self.assertIsNotNone(conn)
     conn.close()
Exemplo n.º 14
0
 def testBadCredentials(self):
     with self.assertRaises(tdrest.DatabaseError) as cm:
         tdrest.connect(
             host=host, system=system, username="******", password="******")
     # print(cm.exception)
     self.assertEqual(cm.exception.code, 8017, cm.exception.msg)