Skip to content

Commit

Permalink
Modification in the descriptions and actions along with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankita-orchestral committed Jan 8, 2024
1 parent 5813139 commit b135849
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 25 deletions.
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
4 changes: 3 additions & 1 deletion 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
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: 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

0 comments on commit b135849

Please sign in to comment.