Skip to content

Commit 7c54701

Browse files
authored
Merge pull request MarketSquare#124 from adrianyorke/master
added support for Teradata 15 & 16
2 parents 5dbfd78 + ec8a62a commit 7c54701

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ test/log.html
77
test/my_db_test.db
88
test/output.xml
99
test/report.html
10+
test/logs/

src/DatabaseLibrary/assertion.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def table_must_exist(self, tableName, sansTran=False):
210210
selectStatement = ("SELECT name FROM sqlite_master WHERE type='table' AND name='%s' COLLATE NOCASE" % tableName)
211211
elif self.db_api_module_name in ["ibm_db", "ibm_db_dbi"]:
212212
selectStatement = ("SELECT name FROM SYSIBM.SYSTABLES WHERE type='T' AND name=UPPER('%s')" % tableName)
213+
elif self.db_api_module_name in ["teradata"]:
214+
selectStatement = ("SELECT TableName FROM DBC.TablesV WHERE TableKind='T' AND TableName='%s'" % tableName)
213215
else:
214216
selectStatement = ("SELECT * FROM information_schema.tables WHERE table_name='%s'" % tableName)
215217
num_rows = self.row_count(selectStatement, sansTran)

src/DatabaseLibrary/connection_manager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ def connect_to_database(self, dbapiModuleName=None, dbName=None, dbUsername=None
126126
oracle_dsn = db_api_2.makedsn(host=dbHost, port=dbPort, service_name=dbName)
127127
logger.info('Connecting using: %s.connect(user=%s, password=%s, dsn=%s) ' % (dbapiModuleName, dbUsername, dbPassword, oracle_dsn))
128128
self._dbconnection = db_api_2.connect(user=dbUsername, password=dbPassword, dsn=oracle_dsn)
129+
elif dbapiModuleName in ["teradata"]:
130+
dbPort = dbPort or 1025
131+
teradata_udaExec = db_api_2.UdaExec(appName="RobotFramework", version="1.0", logConsole=False)
132+
logger.info('Connecting using : %s.connect(database=%s, user=%s, password=%s, host=%s, port=%s) ' % (dbapiModuleName, dbName, dbUsername, dbPassword, dbHost, dbPort))
133+
self._dbconnection = teradata_udaExec.connect(
134+
method="odbc",
135+
system=dbHost,
136+
database=dbName,
137+
username=dbUsername,
138+
password=dbPassword,
139+
host=dbHost,
140+
port=dbPort
141+
)
129142
else:
130143
logger.info('Connecting using : %s.connect(database=%s, user=%s, password=%s, host=%s, port=%s) ' % (dbapiModuleName, dbName, dbUsername, dbPassword, dbHost, dbPort))
131144
self._dbconnection = db_api_2.connect(database=dbName, user=dbUsername, password=dbPassword, host=dbHost, port=dbPort)

test/Teradata_DB_Tests.robot

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
*** Settings ***
2+
Suite Setup Connect To Database teradata ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort}
3+
Suite Teardown Disconnect From Database
4+
Library DatabaseLibrary
5+
Library OperatingSystem
6+
Library Collections
7+
8+
*** Variables ***
9+
${DBHost} 192.168.10.45
10+
${DBName} ADRIAN
11+
${DBPass} dbc
12+
${DBPort} 1025
13+
${DBUser} dbc
14+
15+
*** Test Cases ***
16+
Create person table
17+
[Tags] db smoke
18+
${output} = Execute SQL String CREATE TABLE person (id integer not null unique,first_name varchar(20),last_name varchar(20));
19+
Log ${output}
20+
Should Be Equal As Strings ${output} None
21+
22+
Execute SQL Script - Insert Data person table
23+
Comment ${output} = Execute SQL Script ./${DBName}_insertData.sql
24+
${output} = Execute SQL Script ./my_db_test_insertData.sql
25+
Log ${output}
26+
Should Be Equal As Strings ${output} None
27+
28+
Create foobar table
29+
${output} = Execute SQL String create table foobar (id integer not null primary key, firstname varchar(100) not null unique)
30+
Log ${output}
31+
Should Be Equal As Strings ${output} None
32+
33+
Check If Exists In DB - Franz Allan
34+
Check If Exists In Database SELECT id FROM person WHERE first_name = 'Franz Allan';
35+
36+
Check If Not Exists In DB - Joe
37+
Check If Not Exists In Database SELECT id FROM person WHERE first_name = 'Joe';
38+
39+
Table Must Exist - person
40+
Table Must Exist person
41+
42+
Verify Row Count is 0
43+
Row Count is 0 SELECT * FROM person WHERE first_name = 'NotHere';
44+
45+
Verify Row Count is Equal to X
46+
Row Count is Equal to X SELECT id FROM person; 2
47+
48+
Verify Row Count is Less Than X
49+
Row Count is Less Than X SELECT id FROM person; 3
50+
51+
Verify Row Count is Greater Than X
52+
Row Count is Greater Than X SELECT * FROM person; 1
53+
54+
Retrieve Row Count
55+
${output} = Row Count SELECT id FROM person;
56+
Log ${output}
57+
Should Be Equal As Strings ${output} 2
58+
59+
Retrieve records from person table
60+
${output} = Execute SQL String SELECT * FROM person;
61+
Log ${output}
62+
Should Be Equal As Strings ${output} None
63+
64+
Verify person Description
65+
[Tags] db smoke
66+
Comment Query db for table column descriptions
67+
@{queryResults} = Description SELECT * FROM person SAMPLE 1;
68+
Log Many @{queryResults}
69+
${output} = Set Variable ${queryResults[0]}
70+
Should Be Equal As Strings ${output} ('id', <class 'decimal.Decimal'>, None, 10, 0, None, 0)
71+
${output} = Set Variable ${queryResults[1]}
72+
Should Be Equal As Strings ${output} ('first_name', <class 'str'>, None, 20, 0, None, 1)
73+
${output} = Set Variable ${queryResults[2]}
74+
Should Be Equal As Strings ${output} ('last_name', <class 'str'>, None, 20, 0, None, 1)
75+
${NumColumns} = Get Length ${queryResults}
76+
Should Be Equal As Integers ${NumColumns} 3
77+
78+
Verify foobar Description
79+
[Tags] db smoke
80+
Comment Query db for table column descriptions
81+
@{queryResults} = Description SELECT * FROM foobar SAMPLE 1;
82+
Log Many @{queryResults}
83+
${output} = Set Variable ${queryResults[0]}
84+
Should Be Equal As Strings ${output} ('id', <class 'decimal.Decimal'>, None, 10, 0, None, 0)
85+
${output} = Set Variable ${queryResults[1]}
86+
Should Be Equal As Strings ${output} ('firstname', <class 'str'>, None, 100, 0, None, 0)
87+
${NumColumns} = Get Length ${queryResults}
88+
Should Be Equal As Integers ${NumColumns} 2
89+
90+
Verify Query - Row Count person table
91+
${output} = Query SELECT COUNT(*) FROM person;
92+
Log ${output}
93+
${val}= Get from list ${output} 0
94+
${val}= Convert to list ${val}
95+
${val}= Get from list ${val} 0
96+
Should be equal as Integers ${val} 2
97+
98+
Verify Query - Row Count foobar table
99+
${output} = Query SELECT COUNT(*) FROM foobar;
100+
Log ${output}
101+
${val}= Get from list ${output} 0
102+
${val}= Convert to list ${val}
103+
${val}= Get from list ${val} 0
104+
Should be equal as Integers ${val} 0
105+
106+
Verify Query - Get results as a list of dictionaries
107+
[Tags] db smoke
108+
${output} = Query SELECT * FROM person; \ True
109+
Log ${output}
110+
Should Be Equal As Strings &{output[0]}[first_name] Franz Allan
111+
Should Be Equal As Strings &{output[1]}[first_name] Jerry
112+
113+
Verify Execute SQL String - Row Count person table
114+
${output} = Execute SQL String SELECT COUNT(*) FROM person;
115+
Log ${output}
116+
Should Be Equal As Strings ${output} None
117+
118+
Verify Execute SQL String - Row Count foobar table
119+
${output} = Execute SQL String SELECT COUNT(*) FROM foobar;
120+
Log ${output}
121+
Should Be Equal As Strings ${output} None
122+
123+
Insert Data Into Table foobar
124+
${output} = Execute SQL String INSERT INTO foobar VALUES(1,'Jerry');
125+
Log ${output}
126+
Should Be Equal As Strings ${output} None
127+
128+
Verify Query - Row Count foobar table 1 row
129+
${output} = Query SELECT COUNT(*) FROM foobar;
130+
Log ${output}
131+
${val}= Get from list ${output} 0
132+
${val}= Convert to list ${val}
133+
${val}= Get from list ${val} 0
134+
Should be equal as Integers ${val} 1
135+
136+
Verify Delete All Rows From Table - foobar
137+
Delete All Rows From Table foobar
138+
Comment Sleep 2s
139+
140+
Verify Query - Row Count foobar table 0 row
141+
Row Count Is 0 SELECT * FROM foobar;
142+
Comment ${output} = Query SELECT COUNT(*) FROM foobar;
143+
Comment Log ${output}
144+
Comment Should Be Equal As Strings ${output} [(0,)]
145+
146+
Drop person table
147+
${output} = Execute SQL String DROP TABLE person;
148+
Log ${output}
149+
Should Be Equal As Strings ${output} None
150+
151+
Drop foobar table
152+
${output} = Execute SQL String DROP TABLE foobar;
153+
Log ${output}
154+
Should Be Equal As Strings ${output} None

0 commit comments

Comments
 (0)