Skip to content

Commit d4ba70a

Browse files
authored
Merge PR #222 from dev (V2.0 Release)
2 parents b916815 + 60debcd commit d4ba70a

File tree

67 files changed

+2206
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2206
-625
lines changed

.github/workflows/unit_tests.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
include:
15-
- os: 'ubuntu-latest'
16-
python-version: '3.7'
17-
rf-version: '3.2.2'
1815
- os: 'ubuntu-latest'
1916
python-version: '3.8'
20-
rf-version: '4.1.3'
17+
rf-version: '5.0.1'
2118
- os: 'ubuntu-latest'
2219
python-version: '3.9'
2320
rf-version: '5.0.1'
@@ -29,7 +26,7 @@ jobs:
2926
rf-version: '6.1.1'
3027
- os: 'ubuntu-latest'
3128
python-version: '3.12'
32-
rf-version: '7.0a1'
29+
rf-version: '7.0.1'
3330
runs-on: ${{ matrix.os }}
3431

3532
steps:

README.md

+168-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It requires an appropriate **Python module to be installed separately** - depend
66
The library consists of some keywords designed to perform different checks on your database.
77
Here you can find the [keyword docs](http://marketsquare.github.io/Robotframework-Database-Library/).
88

9-
Wath the [talk at Robocon 2024 about the Database Library update](https://youtu.be/A96NTUps8sU)
9+
Wath the [talk at Robocon 2024 about the Database Library update](https://youtu.be/A96NTUps8sU).
1010

1111
[![Talk at Robocon 2024 about the Database Library update](http://img.youtube.com/vi/A96NTUps8sU/0.jpg)](https://youtu.be/A96NTUps8sU)
1212

@@ -18,8 +18,7 @@ Wath the [talk at Robocon 2024 about the Database Library update](https://youtu.
1818
```
1919
pip install robotframework-databaselibrary
2020
```
21-
# Usage examples
22-
## Basic usage
21+
# Basic usage examples
2322
```RobotFramework
2423
*** Settings ***
2524
Library DatabaseLibrary
@@ -29,25 +28,40 @@ Test Setup Connect To My Oracle DB
2928
Connect To My Oracle DB
3029
Connect To Database
3130
... oracledb
32-
... dbName=db
33-
... dbUsername=my_user
34-
... dbPassword=my_pass
35-
... dbHost=127.0.0.1
36-
... dbPort=1521
31+
... db_name=db
32+
... db_user=my_user
33+
... db_password=my_pass
34+
... db_host=127.0.0.1
35+
... db_port=1521
3736
3837
*** Test Cases ***
38+
Get All Names
39+
${Rows}= Query select FIRST_NAME, LAST_NAME from person
40+
Should Be Equal ${Rows}[0][0] Franz Allan
41+
Should Be Equal ${Rows}[0][1] See
42+
Should Be Equal ${Rows}[1][0] Jerry
43+
Should Be Equal ${Rows}[1][1] Schneider
44+
3945
Person Table Contains Expected Records
40-
${output}= Query select LAST_NAME from person
41-
Length Should Be ${output} 2
42-
Should Be Equal ${output}[0][0] See
43-
Should Be Equal ${output}[1][0] Schneider
46+
${sql}= Catenate select LAST_NAME from person
47+
Check Query Result ${sql} contains See
48+
Check Query Result ${sql} equals Schneider row=1
49+
50+
Wait Until Table Gets New Record
51+
${sql}= Catenate select LAST_NAME from person
52+
Check Row Count ${sql} > 2 retry_timeout=5s
4453
4554
Person Table Contains No Joe
4655
${sql}= Catenate SELECT id FROM person
47-
... WHERE FIRST_NAME= 'Joe'
48-
Check If Not Exists In Database ${sql}
56+
... WHERE FIRST_NAME= 'Joe'
57+
Check Row Count ${sql} == 0
4958
```
50-
## Handling multiple database connections
59+
See more examples in the folder `tests`.
60+
61+
# Handling multiple database connections
62+
The library can handle multiple connections to different databases using *aliases*.
63+
An alias is set while creating a connection and can be passed to library keywords in a corresponding argument.
64+
## Example
5165
```RobotFramework
5266
*** Settings ***
5367
Library DatabaseLibrary
@@ -56,9 +70,21 @@ Test Teardown Disconnect From All Databases
5670
5771
*** Keywords ***
5872
Connect To All Databases
59-
Connect To Database psycopg2 db db_user pass 127.0.0.1 5432
73+
Connect To Database
74+
... psycopg2
75+
... db_name=db
76+
... db_user=db_user
77+
... db_password=pass
78+
... db_host=127.0.0.1
79+
... db_port=5432
6080
... alias=postgres
61-
Connect To Database pymysql db db_user pass 127.0.0.1 3306
81+
Connect To Database
82+
... pymysql
83+
... db_name=db
84+
... db_user=db_user
85+
... db_password=pass
86+
... db_host=127.0.0.1
87+
... db_port=3306
6288
... alias=mysql
6389
6490
*** Test Cases ***
@@ -73,7 +99,130 @@ Switching Default Alias
7399
Execute Sql String drop table XYZ
74100
```
75101

76-
See more examples in the folder `tests`.
102+
103+
104+
# Using configuration file
105+
The `Connect To Database` keyword allows providing the connection parameters in two ways:
106+
- As keyword arguments
107+
- In a configuration file - a simple list of _key=value_ pairs, set inside an _alias_ section.
108+
109+
You can use only one way or you can combine them:
110+
- The keyword arguments are taken by default
111+
- If no keyword argument is provided, a parameter value is searched in the config file
112+
113+
Along with commonly used connection parameters, named exactly as keyword arguments, a config file
114+
can contain any other DB module specific parameters as key/value pairs.
115+
If same custom parameter is provided both as a keyword argument *and* in config file,
116+
the *keyword argument value takes precedence*.
117+
118+
The path to the config file is set by default to `./resources/db.cfg`.
119+
You can change it using an according parameter in the `Connect To Database` keyword.
120+
121+
A config file *must* contain at least one section name -
122+
the connection alias, if used (see [Handling multiple database connections](#handling-multiple-database-connections)), or
123+
`[default]` if no aliases are used.
124+
125+
## Config file examples
126+
### Config file with default alias (equal to using no aliases at all)
127+
```
128+
[default]
129+
db_module=psycopg2
130+
db_name=yourdbname
131+
db_user=yourusername
132+
db_password=yourpassword
133+
db_host=yourhost
134+
db_port=yourport
135+
```
136+
### Config file with a specific alias
137+
```
138+
[myoracle]
139+
db_module=oracledb
140+
db_name=yourdbname
141+
db_user=yourusername
142+
db_password=yourpassword
143+
db_host=yourhost
144+
db_port=yourport
145+
```
146+
147+
### Config file with some params only
148+
```
149+
[default]
150+
db_password=mysecret
151+
```
152+
### Config file with some custom DB module specific params
153+
```
154+
[default]
155+
my_custom_param=value
156+
```
157+
158+
# Inline assertions
159+
Keywords, that accept arguments ``assertion_operator`` and ``expected_value``,
160+
perform a check according to the specified condition - using the [Assertion Engine](https://github.com/MarketSquare/AssertionEngine).
161+
162+
## Examples
163+
```RobotFramework
164+
Check Row Count SELECT id FROM person == 2
165+
Check Query Result SELECT first_name FROM person contains Allan
166+
```
167+
168+
# Retry mechanism
169+
Assertion keywords, that accept arguments ``retry_timeout`` and ``retry_pause``, support waiting for assertion to pass.
170+
171+
Setting the ``retry_timeout`` argument enables the mechanism -
172+
in this case the SQL request and the assertion are executed in a loop,
173+
until the assertion is passed or the ``retry_timeout`` is reached.
174+
The pause between the loop iterations is set using the ``retry_pause`` argument.
175+
176+
The argument values are set in [Robot Framework time format](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#time-format) - e.g. ``5 seconds``.
177+
178+
The retry mechanism is disabled by default - ``retry_timeout`` is set to ``0``.
179+
180+
## Examples
181+
```RobotFramework
182+
${sql}= Catenate SELECT first_name FROM person
183+
Check Row Count ${sql} == 2 retry_timeout=10 seconds
184+
Check Query Result ${sql} contains Allan retry_timeout=5s retry_pause=1s
185+
````
186+
187+
# Logging query results
188+
Keywords, that fetch results of a SQL query, print the result rows as a table in RF log.
189+
- A log head limit of *50 rows* is applied, other table rows are truncated in the log message.
190+
- The limit and the logging in general can be adjusted any time in your tests using the Keyword `Set Logging Query Results`.
191+
192+
You can also setup the limit or disable the logging during the library import.
193+
## Examples
194+
```RobotFramework
195+
*** Settings ***
196+
# Default behavior - logging of query results is enabled, log head is 50 rows.
197+
Library DatabaseLibrary
198+
199+
# Logging of query results is disabled, log head is 50 rows (default).
200+
Library DatabaseLibrary log_query_results=False
201+
202+
# Logging of query results is enabled (default), log head is 10 rows.
203+
Library DatabaseLibrary log_query_results_head=10
204+
205+
# Logging of query results is enabled (default), log head limit is disabled (log all rows).
206+
Library DatabaseLibrary log_query_results_head=0
207+
````
208+
209+
# Commit behavior
210+
While creating a database connection, the library doesn't explicitly set the _autocommit_ behavior -
211+
so the default value of the Python DB module is used.
212+
According to Python DB API specification it should be disabled by default -
213+
which means each SQL transaction must contain a dedicated commit statement, if necessary.
214+
215+
The library manages it for you:
216+
- Keywords like `Execute SQL String` perform automatically a commit after running the query - or a rollback in case of error
217+
- Keywords like `Query` don't perform a commit, but also do a rollback in case of error
218+
219+
You can turn off this automatic commit/rollback behavior using the ``no_transaction`` parameter.
220+
See docs of a particular keyword.
221+
222+
It's also possible to explicitly set the _autocommit_ behavior on the Python DB module level -
223+
using the `Set Auto Commit` keyword.
224+
This has no impact on the automatic commit/rollback behavior in library keywords (described above).
225+
77226
# Database modules compatibility
78227
The library is basically compatible with any [Python Database API Specification 2.0](https://peps.python.org/pep-0249/) module.
79228
@@ -83,7 +232,7 @@ Therefore there are some modules, which are "natively" supported in the library
83232
## Python modules currently "natively" supported
84233
### Oracle
85234
- [oracledb](https://oracle.github.io/python-oracledb/)
86-
- Both thick and thin client modes are supported - you can select one using the `driverMode` parameter.
235+
- Both thick and thin client modes are supported - you can select one using the `oracle_driver_mode` parameter.
87236
- However, due to current limitations of the oracledb module, **it's not possible to switch between thick and thin modes during a test execution session** - even in different suites.
88237
- [cx_Oracle](https://oracle.github.io/python-cx_Oracle/)
89238
### MySQL

doc/index.html

+36-15
Large diffs are not rendered by default.

pyproject.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[build-system]
22
requires = [
33
"setuptools>=61.0",
4-
"robotframework"
4+
"robotframework>=5.0.1",
5+
"robotframework-assertion-engine"
56
]
67
build-backend = "setuptools.build_meta"
78

@@ -11,10 +12,11 @@ authors = [{name="Franz Allan Valencia See", email="[email protected]"},
1112
]
1213
description = "Database Library for Robot Framework"
1314
readme = "README.md"
14-
requires-python = ">=3.7"
15+
requires-python = ">=3.8.1"
1516
dependencies = [
16-
"robotframework",
17-
"robotframework-excellib"
17+
"robotframework>=5.0.1",
18+
"robotframework-excellib",
19+
"robotframework-assertion-engine"
1820
]
1921
classifiers = [
2022
"Programming Language :: Python :: 3",

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
robotframework
22
robotframework-excellib
3+
robotframework-assertion-engine
4+
psycopg2-binary
35
pre-commit
46
build
57
twine

0 commit comments

Comments
 (0)