Skip to content

Modification in the descriptions and actions along with tests. #30

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.2.0

* Added support for schema in insert, update and delete actions

## 1.1.1

* Resolve issue where query is sometimes missing
Expand Down
2 changes: 2 additions & 0 deletions actions/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ def run(self, **kwargs):

where_dict = self.get_del_arg('where', kwargs_dict)
table = self.get_del_arg('table', kwargs_dict)
schema = self.get_del_arg('schema', kwargs_dict)

with self.db_connection(kwargs_dict) as conn:
# Get the SQL table
sql_table = sqlalchemy.Table(table,
self.meta,
schema=schema,
autoload=True,
autoload_with=self.engine)

Expand Down
12 changes: 8 additions & 4 deletions actions/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@
description: >
Dictionary of data to be used to create a WHERE clause for the DELETE statement
{
'column_1': 'data_to_match_1',
'column_2': 'data_to_match_2',
'column_3': 'data_to_match_3',
'column_4': 'data_to_match_4',
"column_1": "data_to_match_1",
"column_2": "data_to_match_2",
"column_3": "data_to_match_3",
"column_4": "data_to_match_4",
}
required: false
default: {}
schema:
type: string
description: "Database schema under which the table is created."
required: false
6 changes: 4 additions & 2 deletions actions/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def run(self, **kwargs):

insert_data = self.get_del_arg('data', kwargs_dict)
insert_table = self.get_del_arg('table', kwargs_dict)
insert_schema = self.get_del_arg('schema', kwargs_dict)

if not isinstance(insert_data, list):
insert_data = [insert_data]
Expand All @@ -28,10 +29,11 @@ def run(self, **kwargs):
sql_table = sqlalchemy.Table(insert_table,
self.meta,
autoload=True,
schema=insert_schema,
autoload_with=self.engine)

# Execute the insert query
conn.execute(sql_table.insert(), # pylint: disable-msg=no-value-for-parameter
insert_data)
# pylint: disable=unexpected-keyword-arg
conn.execute(sql_table.insert(inline=True), insert_data)

return True
12 changes: 8 additions & 4 deletions actions/insert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@
description: >
Dictionary of data to be inserted where the key corresponds to the column of the table
{
'column_1': 'data_to_insert_1',
'column_2': 'data_to_insert_2',
'column_3': 'data_to_insert_3',
'column_4': 'data_to_insert_4',
"column_1": "data_to_insert_1",
"column_2": "data_to_insert_2",
"column_3": "data_to_insert_3",
"column_4": "data_to_insert_4",
}
required: true
schema:
type: string
description: "Database schema under which the table is created."
required: false
16 changes: 8 additions & 8 deletions actions/insert_bulk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
description: >
List of Dictionaries of data to be inserted where the key corresponds to the column of the table
[{
'column_1': 'data_to_insert_1',
'column_2': 'data_to_insert_2',
'column_3': 'data_to_insert_3',
'column_4': 'data_to_insert_4',
"column_1": "data_to_insert_1",
"column_2": "data_to_insert_2",
"column_3": "data_to_insert_3",
"column_4": "data_to_insert_4",
},{
'column_1': 'data_to_insert_1',
'column_2': 'data_to_insert_2',
'column_3': 'data_to_insert_3',
'column_4': 'data_to_insert_4',
"column_1": "data_to_insert_1",
"column_2": "data_to_insert_2",
"column_3": "data_to_insert_3",
"column_4": "data_to_insert_4",
}]
required: true
2 changes: 2 additions & 0 deletions actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ def run(self, **kwargs):
where_dict = self.get_del_arg('where', kwargs_dict)
update_dict = self.get_del_arg('update', kwargs_dict)
table = self.get_del_arg('table', kwargs_dict)
schema = self.get_del_arg('schema', kwargs_dict)

with self.db_connection(kwargs_dict) as conn:
# Get the SQL table
sql_table = sqlalchemy.Table(table,
self.meta,
schema=schema,
autoload=True,
autoload_with=self.engine)

Expand Down
20 changes: 12 additions & 8 deletions actions/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
description: >
Dictionary of data to be used to create a WHERE clause for the UPDATE statement
{
'column_1': 'data_to_match_1',
'column_2': 'data_to_match_2',
'column_3': 'data_to_match_3',
'column_4': 'data_to_match_4',
"column_1": "data_to_match_1",
"column_2": "data_to_match_2",
"column_3": "data_to_match_3",
"column_4": "data_to_match_4",
}
required: false
default: {}
Expand All @@ -56,9 +56,13 @@
description: >
Dictionary of data to be used to as Values to update for the UPDATE statement
{
'column_1': 'data_to_update_1',
'column_2': 'data_to_update_2',
'column_3': 'data_to_update_3',
'column_4': 'data_to_update_4',
"column_1": "data_to_update_1",
"column_2": "data_to_update_2",
"column_3": "data_to_update_3",
"column_4": "data_to_update_4",
}
required: true
schema:
type: string
description: "Database schema under which the table is created."
required: false
2 changes: 1 addition & 1 deletion pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- Postgres
- MySQL
- MsSQL
version: 1.1.1
version: 1.2.0
author: Encore Technologies
email: [email protected]
python_versions:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_action_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_run_object(self, mock_sqlalchemy, mock_connect_to_db):
mock_connect_to_db.assert_called_once_with(test_dict)
mock_sqlalchemy.Table.assert_called_once_with(test_dict['table'],
action_meta,
schema=None,
autoload=True,
autoload_with=action_engine)
mock_connection.execute.assert_called_once_with(mock_where_return, execute_dict)
Expand Down Expand Up @@ -94,6 +95,7 @@ def test_run_array(self, mock_sqlalchemy, mock_connect_to_db):
mock_connect_to_db.assert_called_once_with(test_dict)
mock_sqlalchemy.Table.assert_called_once_with(test_dict['table'],
action_meta,
schema=None,
autoload=True,
autoload_with=action_engine)
mock_connection.execute.assert_called_once_with(mock_delete_return, None)
2 changes: 2 additions & 0 deletions tests/test_action_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_run_object(self, mock_sqlalchemy, mock_connect_to_db):
mock_connect_to_db.assert_called_once_with(test_dict)
mock_sqlalchemy.Table.assert_called_once_with(test_dict['table'],
action_meta,
schema=None,
autoload=True,
autoload_with=action_engine)
mock_connection.execute.assert_called_once_with(insert_return, [test_dict['data']])
Expand Down Expand Up @@ -95,6 +96,7 @@ def test_run_array(self, mock_sqlalchemy, mock_connect_to_db):
mock_connect_to_db.assert_called_once_with(test_dict)
mock_sqlalchemy.Table.assert_called_once_with(test_dict['table'],
action_meta,
schema=None,
autoload=True,
autoload_with=action_engine)
mock_connection.execute.assert_called_once_with(insert_return, test_dict['data'])
2 changes: 2 additions & 0 deletions tests/test_action_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_run_object(self, mock_sqlalchemy, mock_connect_to_db):
mock_connect_to_db.assert_called_once_with(test_dict)
mock_sqlalchemy.Table.assert_called_once_with(test_dict['table'],
action_meta,
schema=None,
autoload=True,
autoload_with=action_engine)
mock_connection.execute.assert_called_once_with(mock_values_return, execute_dict)
Expand Down Expand Up @@ -106,6 +107,7 @@ def test_run_array(self, mock_sqlalchemy, mock_connect_to_db):
mock_connect_to_db.assert_called_once_with(test_dict)
mock_sqlalchemy.Table.assert_called_once_with(test_dict['table'],
action_meta,
schema=None,
autoload=True,
autoload_with=action_engine)
mock_connection.execute.assert_called_once_with(mock_values_return,
Expand Down