Skip to content

Commit 6407f58

Browse files
committed
Edited src/DatabaseLibrary/assertion.py via GitHub
1 parent f40f518 commit 6407f58

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

src/DatabaseLibrary/assertion.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,94 @@ def check_if_not_exists_in_database(self,selectStatement):
6363
if queryResults:
6464
raise AssertionError("Expected to have have no rows from '%s' "
6565
"but got some rows : %s." % (selectStatement, queryResults))
66+
67+
def row_count_is_0(self,selectStatement):
68+
"""
69+
Check if any rows are returned from the submitted `selectStatement`.
70+
If there are, then this will throw an AssertionError.
71+
72+
For example, given we have a table `person` with the following data:
73+
| id | first_name | last_name |
74+
| 1 | Franz Allan | See |
75+
76+
When you have the following assertions in your robot
77+
| Row Count is 0 | select id from person where first_name = 'Franz Allan' |
78+
| Row Count is 0 | select id from person where first_name = 'John' |
79+
80+
Then you will get the following:
81+
| Row Count is 0 | select id from person where first_name = 'Franz Allan' | # FAIL |
82+
| Row Count is 0 | select id from person where first_name = 'John' | # PASS |
83+
"""
84+
num_rows = self.row_count(selectStatement)
85+
if (num_rows > 0):
86+
raise AssertionError("Expected zero rows to be returned from '%s' "
87+
"but got rows back. Number of rows returned was %s" % (selectStatement, num_rows))
88+
89+
def row_count_is_equal_to_x(self,selectStatement,numRows):
90+
"""
91+
Check if the number of rows returned from `selectStatement` is equal to
92+
the value submitted. If not, then this will throw an AssertionError.
93+
94+
For example, given we have a table `person` with the following data:
95+
| id | first_name | last_name |
96+
| 1 | Franz Allan | See |
97+
| 1 | Jerry | Schneider |
98+
99+
When you have the following assertions in your robot
100+
| Row Count Is Equal To X | select id from person | 1 |
101+
| Row Count Is Equal To X | select id from person where first_name = 'John' | 0 |
102+
103+
Then you will get the following:
104+
| Row Count Is Equal To X | select id from person | 1 | # FAIL |
105+
| Row Count Is Equal To X | select id from person where first_name = 'John' | 0 | # PASS |
106+
"""
107+
num_rows = self.row_count(selectStatement)
108+
if (num_rows != int(numRows.encode('ascii'))):
109+
raise AssertionError("Expected same number of rows to be returned from '%s' "
110+
"than the returned rows of %s" % (selectStatement, num_rows))
111+
112+
def row_count_is_greater_than_x(self,selectStatement,numRows):
113+
"""
114+
Check if the number of rows returned from `selectStatement` is greater
115+
than the value submitted. If not, then this will throw an AssertionError.
116+
117+
For example, given we have a table `person` with the following data:
118+
| id | first_name | last_name |
119+
| 1 | Franz Allan | See |
120+
| 1 | Jerry | Schneider |
121+
122+
When you have the following assertions in your robot
123+
| Row Count Is Greater Than X | select id from person | 1 |
124+
| Row Count Is Greater Than X | select id from person where first_name = 'John' | 0 |
125+
126+
Then you will get the following:
127+
| Row Count Is Greater Than X | select id from person | 1 | # PASS |
128+
| Row Count Is Greater Than X | select id from person where first_name = 'John' | 0 | # FAIL |
129+
"""
130+
num_rows = self.row_count(selectStatement)
131+
if (num_rows <= int(numRows.encode('ascii'))):
132+
raise AssertionError("Expected more rows to be returned from '%s' "
133+
"than the returned rows of %s" % (selectStatement, num_rows))
134+
135+
def row_count_is_less_than_x(self,selectStatement,numRows):
136+
"""
137+
Check if the number of rows returned from `selectStatement` is less
138+
than the value submitted. If not, then this will throw an AssertionError.
139+
140+
For example, given we have a table `person` with the following data:
141+
| id | first_name | last_name |
142+
| 1 | Franz Allan | See |
143+
| 1 | Jerry | Schneider |
144+
145+
When you have the following assertions in your robot
146+
| Row Count Is Less Than X | select id from person | 3 |
147+
| Row Count Is Less Than X | select id from person where first_name = 'John' | 1 |
148+
149+
Then you will get the following:
150+
| Row Count Is Less Than X | select id from person | 3 | # PASS |
151+
| Row Count Is Less Than X | select id from person where first_name = 'John' | 1 | # FAIL |
152+
"""
153+
num_rows = self.row_count(selectStatement)
154+
if (num_rows >= int(numRows.encode('ascii'))):
155+
raise AssertionError("Expected less rows to be returned from '%s' "
156+
"than the returned rows of %s" % (selectStatement, num_rows))

0 commit comments

Comments
 (0)