forked from MarketSquare/Robotframework-Database-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Gestione multi db #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
00b7194
Modifica Multi Connection
7ce303d
first try error handling
54b1e01
error handling 2
4938883
remove handling error
dc6ac3d
handling error
505e1a5
handling error
3f156e4
next handling
df4b71e
Exception
fbbf269
remove all
3623e51
change query e rowcount return e error handling
fe644a2
error handling connect to db
a24efe5
add assertion change
917cc76
insert caching dbapimodule
4b3efce
remove last self.db_api_module_name
2f7e3f3
refactor
3ff0474
refactor logger
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ test/log.html | |
test/my_db_test.db | ||
test/output.xml | ||
test/report.html | ||
.vscode/settings.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"python.linting.pylintEnabled": true, | ||
"python.pythonPath": "/usr/bin/python3" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ class Assertion(object): | |
Assertion handles all the assertions of Database Library. | ||
""" | ||
|
||
def check_if_exists_in_database(self, selectStatement, sansTran=False): | ||
def check_if_exists_in_database(self, selectStatement, sansTran=False, alias=None): | ||
""" | ||
Check if any row would be returned by given the input `selectStatement`. If there are no results, then this will | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'd better have to document this change also because this is a breaking change that introduces a new mandatory field. |
||
throw an AssertionError. Set optional input `sansTran` to True to run command without an explicit transaction | ||
|
@@ -41,12 +41,13 @@ def check_if_exists_in_database(self, selectStatement, sansTran=False): | |
Using optional `sansTran` to run command without an explicit transaction commit or rollback: | ||
| Check If Exists In Database | SELECT id FROM person WHERE first_name = 'John' | True | | ||
""" | ||
logger.info ('Executing : Check If Exists In Database | %s ' % selectStatement) | ||
if not self.query(selectStatement, sansTran): | ||
logger.info('Executing : Check If Exists In Database | %s | %s ' % (selectStatement,alias)) | ||
|
||
if not self.query(selectStatement=selectStatement, sansTran=sansTran, alias=alias): | ||
raise AssertionError("Expected to have have at least one row from '%s' " | ||
"but got 0 rows." % selectStatement) | ||
|
||
def check_if_not_exists_in_database(self, selectStatement, sansTran=False): | ||
def check_if_not_exists_in_database(self, selectStatement, sansTran=False, alias=None): | ||
""" | ||
This is the negation of `check_if_exists_in_database`. | ||
|
||
|
@@ -69,13 +70,15 @@ def check_if_not_exists_in_database(self, selectStatement, sansTran=False): | |
Using optional `sansTran` to run command without an explicit transaction commit or rollback: | ||
| Check If Not Exists In Database | SELECT id FROM person WHERE first_name = 'John' | True | | ||
""" | ||
logger.info('Executing : Check If Not Exists In Database | %s ' % selectStatement) | ||
queryResults = self.query(selectStatement, sansTran) | ||
logger.info( | ||
'Executing : Check If Not Exists In Database | %s | %s ' % (selectStatement,alias)) | ||
queryResults = self.query( | ||
selectStatement=selectStatement, sansTran=sansTran, alias=alias) | ||
if queryResults: | ||
raise AssertionError("Expected to have have no rows from '%s' " | ||
"but got some rows : %s." % (selectStatement, queryResults)) | ||
|
||
def row_count_is_0(self, selectStatement, sansTran=False): | ||
def row_count_is_0(self, selectStatement, sansTran=False, alias=None): | ||
""" | ||
Check if any rows are returned from the submitted `selectStatement`. If there are, then this will throw an | ||
AssertionError. Set optional input `sansTran` to True to run command without an explicit transaction commit or | ||
|
@@ -96,13 +99,15 @@ def row_count_is_0(self, selectStatement, sansTran=False): | |
Using optional `sansTran` to run command without an explicit transaction commit or rollback: | ||
| Row Count is 0 | SELECT id FROM person WHERE first_name = 'John' | True | | ||
""" | ||
logger.info('Executing : Row Count Is 0 | %s ' % selectStatement) | ||
num_rows = self.row_count(selectStatement, sansTran) | ||
logger.info('Executing : Row Count Is 0 | %s | %s ' % (selectStatement,alias)) | ||
logger.info( | ||
'Connection: Row Count Is 0 | %s' % alias) | ||
num_rows = self.row_count(selectStatement, sansTran, alias) | ||
if num_rows > 0: | ||
raise AssertionError("Expected zero rows to be returned from '%s' " | ||
"but got rows back. Number of rows returned was %s" % (selectStatement, num_rows)) | ||
|
||
def row_count_is_equal_to_x(self, selectStatement, numRows, sansTran=False): | ||
def row_count_is_equal_to_x(self, selectStatement, numRows, sansTran=False, alias=None): | ||
""" | ||
Check if the number of rows returned from `selectStatement` is equal to the value submitted. If not, then this | ||
will throw an AssertionError. Set optional input `sansTran` to True to run command without an explicit | ||
|
@@ -124,13 +129,15 @@ def row_count_is_equal_to_x(self, selectStatement, numRows, sansTran=False): | |
Using optional `sansTran` to run command without an explicit transaction commit or rollback: | ||
| Row Count Is Equal To X | SELECT id FROM person WHERE first_name = 'John' | 0 | True | | ||
""" | ||
logger.info('Executing : Row Count Is Equal To X | %s | %s ' % (selectStatement, numRows)) | ||
num_rows = self.row_count(selectStatement, sansTran) | ||
logger.info('Executing : Row Count Is Equal To X | %s | %s | %s ' % | ||
(selectStatement, numRows,alias)) | ||
|
||
num_rows = self.row_count(selectStatement, sansTran, alias) | ||
if num_rows != int(numRows.encode('ascii')): | ||
raise AssertionError("Expected same number of rows to be returned from '%s' " | ||
"than the returned rows of %s" % (selectStatement, num_rows)) | ||
|
||
def row_count_is_greater_than_x(self, selectStatement, numRows, sansTran=False): | ||
def row_count_is_greater_than_x(self, selectStatement, numRows, sansTran=False, alias=None): | ||
""" | ||
Check if the number of rows returned from `selectStatement` is greater than the value submitted. If not, then | ||
this will throw an AssertionError. Set optional input `sansTran` to True to run command without an explicit | ||
|
@@ -152,13 +159,15 @@ def row_count_is_greater_than_x(self, selectStatement, numRows, sansTran=False): | |
Using optional `sansTran` to run command without an explicit transaction commit or rollback: | ||
| Row Count Is Greater Than X | SELECT id FROM person | 1 | True | | ||
""" | ||
logger.info('Executing : Row Count Is Greater Than X | %s | %s ' % (selectStatement, numRows)) | ||
num_rows = self.row_count(selectStatement, sansTran) | ||
logger.info('Executing : Row Count Is Greater Than X | %s | %s | %s ' % ( | ||
selectStatement, numRows,alias)) | ||
|
||
num_rows = self.row_count(selectStatement, sansTran, alias) | ||
if num_rows <= int(numRows.encode('ascii')): | ||
raise AssertionError("Expected more rows to be returned from '%s' " | ||
"than the returned rows of %s" % (selectStatement, num_rows)) | ||
|
||
def row_count_is_less_than_x(self, selectStatement, numRows, sansTran=False): | ||
def row_count_is_less_than_x(self, selectStatement, numRows, sansTran=False, alias=None): | ||
""" | ||
Check if the number of rows returned from `selectStatement` is less than the value submitted. If not, then this | ||
will throw an AssertionError. Set optional input `sansTran` to True to run command without an explicit | ||
|
@@ -180,13 +189,15 @@ def row_count_is_less_than_x(self, selectStatement, numRows, sansTran=False): | |
Using optional `sansTran` to run command without an explicit transaction commit or rollback: | ||
| Row Count Is Less Than X | SELECT id FROM person | 3 | True | | ||
""" | ||
logger.info('Executing : Row Count Is Less Than X | %s | %s ' % (selectStatement, numRows)) | ||
num_rows = self.row_count(selectStatement, sansTran) | ||
logger.info('Executing : Row Count Is Less Than X | %s | %s | %s ' % ( | ||
selectStatement, numRows,alias)) | ||
num_rows = self.row_count(selectStatement, sansTran, alias) | ||
logger.info('Row Num: %s ' % str(num_rows)) | ||
if num_rows >= int(numRows.encode('ascii')): | ||
raise AssertionError("Expected less rows to be returned from '%s' " | ||
"than the returned rows of %s" % (selectStatement, num_rows)) | ||
|
||
def table_must_exist(self, tableName, sansTran=False): | ||
def table_must_exist(self, tableName, sansTran=False, alias=None): | ||
""" | ||
Check if the table given exists in the database. Set optional input `sansTran` to True to run command without an | ||
explicit transaction commit or rollback. | ||
|
@@ -203,15 +214,24 @@ def table_must_exist(self, tableName, sansTran=False): | |
Using optional `sansTran` to run command without an explicit transaction commit or rollback: | ||
| Table Must Exist | person | True | | ||
""" | ||
logger.info('Executing : Table Must Exist | %s ' % tableName) | ||
if self.db_api_module_name in ["cx_Oracle"]: | ||
selectStatement = ("SELECT * FROM all_objects WHERE object_type IN ('TABLE','VIEW') AND owner = SYS_CONTEXT('USERENV', 'SESSION_USER') AND object_name = UPPER('%s')" % tableName) | ||
elif self.db_api_module_name in ["sqlite3"]: | ||
selectStatement = ("SELECT name FROM sqlite_master WHERE type='table' AND name='%s' COLLATE NOCASE" % tableName) | ||
elif self.db_api_module_name in ["ibm_db", "ibm_db_dbi"]: | ||
selectStatement = ("SELECT name FROM SYSIBM.SYSTABLES WHERE type='T' AND name=UPPER('%s')" % tableName) | ||
logger.info('Executing : Table Must Exist | %s | %s ' % (tableName,alias)) | ||
|
||
connection, module_api = self._get_cache(alias) | ||
|
||
if module_api in ["cx_Oracle"]: | ||
selectStatement = ("SELECT * FROM all_objects WHERE object_type IN ('TABLE','VIEW') AND owner = SYS_CONTEXT('USERENV', 'SESSION_USER') \ | ||
AND object_name = UPPER('%s')" % tableName) | ||
elif module_api in ["sqlite3"]: | ||
selectStatement = ( | ||
"SELECT name FROM sqlite_master WHERE type='table' AND name='%s' COLLATE NOCASE" % tableName) | ||
elif module_api in ["ibm_db", "ibm_db_dbi"]: | ||
selectStatement = ( | ||
"SELECT name FROM SYSIBM.SYSTABLES WHERE type='T' AND name=UPPER('%s')" % tableName) | ||
else: | ||
selectStatement = ("SELECT * FROM information_schema.tables WHERE table_name='%s'" % tableName) | ||
num_rows = self.row_count(selectStatement, sansTran) | ||
selectStatement = ( | ||
"SELECT * FROM information_schema.tables WHERE table_name='%s'" % tableName) | ||
num_rows = self.row_count(selectStatement, sansTran, alias) | ||
logger.info('Row Num: %s ' % str(num_rows)) | ||
if num_rows == 0: | ||
raise AssertionError("Table '%s' does not exist in the db" % tableName) | ||
raise AssertionError( | ||
"Table '%s' does not exist in the db" % tableName) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be in .gitignore