Skip to content

Commit 1c7727e

Browse files
authored
add tests
1 parent 7d719d7 commit 1c7727e

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

test/PyODBC_DB_Tests.robot

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
*** Settings ***
2+
Suite Setup Connect To Database pyodbc ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} dbDriver=${dbDriver}
3+
Suite Teardown Disconnect From Database
4+
Library DatabaseLibrary
5+
Library OperatingSystem
6+
7+
*** Variables ***
8+
${DBHost} ${EMPTY}
9+
${DBName} ${EMPTY}
10+
${DBPass} ${EMPTY}
11+
${DBPort} ${EMPTY}
12+
${DBUser} ${EMPTY}
13+
${dbDriver} ${EMPTY}
14+
15+
*** Test Cases ***
16+
Create person table
17+
${output} = Execute SQL String CREATE TABLE person (id integer unique, first_name varchar(20), last_name varchar(20));
18+
Log ${output}
19+
Should Be Equal As Strings ${output} None
20+
21+
Execute SQL Script - Insert Data person table
22+
${output} = Execute SQL Script ./my_db_test_insertData.sql
23+
Log ${output}
24+
Should Be Equal As Strings ${output} None
25+
26+
Execute SQL String - Create Table
27+
${output} = Execute SQL String create table foobar (id integer primary key, firstname varchar(20) unique)
28+
Log ${output}
29+
Should Be Equal As Strings ${output} None
30+
31+
Check If Exists In DB - Franz Allan
32+
Check If Exists In Database SELECT id FROM person WHERE first_name = 'Franz Allan';
33+
34+
Check If Not Exists In DB - Joe
35+
Check If Not Exists In Database SELECT id FROM person WHERE first_name = 'Joe';
36+
37+
Table Must Exist - person
38+
Table Must Exist person
39+
40+
Verify Row Count is 0
41+
Row Count is 0 SELECT * FROM person WHERE first_name = 'NotHere';
42+
43+
Verify Row Count is Equal to X
44+
Row Count is Equal to X SELECT id FROM person; 2
45+
46+
Verify Row Count is Less Than X
47+
Row Count is Less Than X SELECT id FROM person; 3
48+
49+
Verify Row Count is Greater Than X
50+
Row Count is Greater Than X SELECT * FROM person; 1
51+
52+
Retrieve Row Count
53+
${output} = Row Count SELECT id FROM person;
54+
Log ${output}
55+
Should Be Equal As Strings ${output} 2
56+
57+
Retrieve records from person table
58+
${output} = Execute SQL String SELECT * FROM person;
59+
Log ${output}
60+
Should Be Equal As Strings ${output} None
61+
62+
Verify person Description
63+
Comment Query db for table column descriptions
64+
@{queryResults} = Description SELECT TOP 1 * FROM person;
65+
Log Many @{queryResults}
66+
${output} = Set Variable ${queryResults[0]}
67+
Should Be Equal As Strings ${output} (u'id', 3, None, None, None, None, None)
68+
${output} = Set Variable ${queryResults[1]}
69+
Should Be Equal As Strings ${output} (u'first_name', 1, None, None, None, None, None)
70+
${output} = Set Variable ${queryResults[2]}
71+
Should Be Equal As Strings ${output} (u'last_name', 1, None, None, None, None, None)
72+
${NumColumns} = Get Length ${queryResults}
73+
Should Be Equal As Integers ${NumColumns} 3
74+
75+
Verify foobar Description
76+
Comment Query db for table column descriptions
77+
@{queryResults} = Description SELECT TOP 1 * FROM foobar;
78+
Log Many @{queryResults}
79+
${output} = Set Variable ${queryResults[0]}
80+
Should Be Equal As Strings ${output} (u'id', 3, None, None, None, None, None)
81+
${output} = Set Variable ${queryResults[1]}
82+
Should Be Equal As Strings ${output} (u'firstname', 1, None, None, None, None, None)
83+
${NumColumns} = Get Length ${queryResults}
84+
Should Be Equal As Integers ${NumColumns} 2
85+
86+
Verify Query - Row Count person table
87+
${output} = Query SELECT COUNT(*) FROM person;
88+
Log ${output}
89+
Should Be Equal As Strings ${output} [(2,)]
90+
91+
Verify Query - Row Count foobar table
92+
${output} = Query SELECT COUNT(*) FROM foobar;
93+
Log ${output}
94+
Should Be Equal As Strings ${output} [(0,)]
95+
96+
Verify Query - Get results as a list of dictionaries
97+
${output} = Query SELECT * FROM person; \ True
98+
Log ${output}
99+
Should Be Equal As Strings &{output[0]}[first_name] Franz Allan
100+
Should Be Equal As Strings &{output[1]}[first_name] Jerry
101+
102+
Verify Execute SQL String - Row Count person table
103+
${output} = Execute SQL String SELECT COUNT(*) FROM person;
104+
Log ${output}
105+
Should Be Equal As Strings ${output} None
106+
107+
Verify Execute SQL String - Row Count foobar table
108+
${output} = Execute SQL String SELECT COUNT(*) FROM foobar;
109+
Log ${output}
110+
Should Be Equal As Strings ${output} None
111+
112+
Insert Data Into Table foobar
113+
${output} = Execute SQL String INSERT INTO foobar VALUES(1,'Jerry');
114+
Log ${output}
115+
Should Be Equal As Strings ${output} None
116+
117+
Verify Query - Row Count foobar table 1 row
118+
${output} = Query SELECT COUNT(*) FROM foobar;
119+
Log ${output}
120+
Should Be Equal As Strings ${output} [(1,)]
121+
122+
Verify Delete All Rows From Table - foobar
123+
Delete All Rows From Table foobar
124+
Comment Sleep 2s
125+
126+
Verify Query - Row Count foobar table 0 row
127+
Row Count Is 0 SELECT * FROM foobar;
128+
129+
Begin first transaction
130+
${output} = Execute SQL String SAVE TRANSACTION first True
131+
Log ${output}
132+
Should Be Equal As Strings ${output} None
133+
134+
Add person in first transaction
135+
${output} = Execute SQL String INSERT INTO person VALUES(101,'Bilbo','Baggins'); True
136+
Log ${output}
137+
Should Be Equal As Strings ${output} None
138+
139+
Verify person in first transaction
140+
Row Count is Equal to X SELECT * FROM person WHERE last_name = 'Baggins'; 1 True
141+
142+
Begin second transaction
143+
${output} = Execute SQL String SAVE TRANSACTION second True
144+
Log ${output}
145+
Should Be Equal As Strings ${output} None
146+
147+
Add person in second transaction
148+
${output} = Execute SQL String INSERT INTO person VALUES(102,'Frodo','Baggins'); True
149+
Log ${output}
150+
Should Be Equal As Strings ${output} None
151+
152+
Verify persons in first and second transactions
153+
Row Count is Equal to X SELECT * FROM person WHERE last_name = 'Baggins'; 2 True
154+
155+
Rollback second transaction
156+
${output} = Execute SQL String ROLLBACK TRANSACTION second True
157+
Log ${output}
158+
Should Be Equal As Strings ${output} None
159+
160+
Verify second transaction rollback
161+
Row Count is Equal to X SELECT * FROM person WHERE last_name = 'Baggins'; 1 True
162+
163+
Rollback first transaction
164+
${output} = Execute SQL String ROLLBACK TRANSACTION first True
165+
Log ${output}
166+
Should Be Equal As Strings ${output} None
167+
168+
Verify first transaction rollback
169+
Row Count is 0 SELECT * FROM person WHERE last_name = 'Baggins'; True
170+
171+
Drop person and foobar tables
172+
${output} = Execute SQL String DROP TABLE IF EXISTS person;
173+
Log ${output}
174+
Should Be Equal As Strings ${output} None
175+
${output} = Execute SQL String DROP TABLE IF EXISTS foobar;
176+
Log ${output}
177+
Should Be Equal As Strings ${output} None

0 commit comments

Comments
 (0)