Skip to content
Merged
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
9 changes: 6 additions & 3 deletions providers/oracle/tests/unit/oracle/hooks/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def test_bulk_insert_rows_without_fields(self):

def test_bulk_insert_rows_no_rows(self):
rows = []
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="parameter rows could not be None or empty iterable"):
self.db_hook.bulk_insert_rows("table", rows)

def test_bulk_insert_sequence_field(self):
Expand All @@ -436,18 +436,21 @@ def test_bulk_insert_sequence_field(self):
self.cur.executemany.assert_called_once_with(None, rows)

def test_bulk_insert_sequence_without_parameter(self):
SEQUENCE_COLUMN_OR_NAME_PROVIDED = (
"Parameters 'sequence_column' and 'sequence_name' must be provided together or not at all."
)
rows = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
target_fields = ["col1", "col2", "col3"]
sequence_column = "id"
sequence_name = None
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=SEQUENCE_COLUMN_OR_NAME_PROVIDED):
self.db_hook.bulk_insert_rows(
"table", rows, target_fields, sequence_column=sequence_column, sequence_name=sequence_name
)

sequence_column = None
sequence_name = "my_sequence"
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=SEQUENCE_COLUMN_OR_NAME_PROVIDED):
self.db_hook.bulk_insert_rows(
"table", rows, target_fields, sequence_column=sequence_column, sequence_name=sequence_name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ def test_sanitize_uri_pass(original: str, normalized: str) -> None:
pytest.param("postgres://", id="blank"),
pytest.param("postgres:///database/schema/table", id="no-host"),
pytest.param("postgres://example.com/database/table", id="missing-component"),
pytest.param("postgres://example.com:abcd/database/schema/table", id="non-port"),
pytest.param("postgres://example.com/database/schema/table/column", id="extra-component"),
],
)
def test_sanitize_uri_fail(value: str) -> None:
uri_i = urllib.parse.urlsplit(value)
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="URI format postgres:// must contain"):
sanitize_uri(uri_i)


def test_sanitize_uri_fail_non_port() -> None:
uri_i = urllib.parse.urlsplit("postgres://example.com:abcd/database/schema/table")
with pytest.raises(ValueError, match="Port could not be cast to integer value as 'abcd'"):
sanitize_uri(uri_i)
18 changes: 5 additions & 13 deletions providers/postgres/tests/unit/postgres/hooks/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_get_uri(self, mock_connect):
@pytest.mark.usefixtures("mock_connect")
def test_get_conn_with_invalid_cursor(self):
self.connection.extra = '{"cursor": "mycursor"}'
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Invalid cursor passed mycursor."):
self.db_hook.get_conn()

def test_get_conn_from_connection(self, mock_connect):
Expand Down Expand Up @@ -879,11 +879,9 @@ def test_insert_rows_replace_missing_target_field_arg(self, postgres_hook_setup)
),
]
fields = ("id", "value")
with pytest.raises(ValueError) as ctx:
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires column names"):
setup.db_hook.insert_rows(table, rows, replace=True, replace_index=fields[0])

assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires column names"

def test_insert_rows_replace_missing_replace_index_arg(self, postgres_hook_setup):
setup = postgres_hook_setup
table = "table"
Expand All @@ -898,11 +896,9 @@ def test_insert_rows_replace_missing_replace_index_arg(self, postgres_hook_setup
),
]
fields = ("id", "value")
with pytest.raises(ValueError) as ctx:
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires an unique index"):
setup.db_hook.insert_rows(table, rows, fields, replace=True)

assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires an unique index"

def test_insert_rows_replace_all_index(self, postgres_hook_setup):
setup = postgres_hook_setup
table = "table"
Expand Down Expand Up @@ -1145,11 +1141,9 @@ def test_insert_rows_replace_missing_target_field_arg(self):
),
]
fields = ("id", "value")
with pytest.raises(ValueError) as ctx:
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires column names"):
self.db_hook.insert_rows(table, rows, replace=True, replace_index=fields[0])

assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires column names"

def test_insert_rows_replace_missing_replace_index_arg(self):
table = "table"
rows = [
Expand All @@ -1163,11 +1157,9 @@ def test_insert_rows_replace_missing_replace_index_arg(self):
),
]
fields = ("id", "value")
with pytest.raises(ValueError) as ctx:
with pytest.raises(ValueError, match="PostgreSQL ON CONFLICT upsert syntax requires an unique index"):
self.db_hook.insert_rows(table, rows, fields, replace=True)

assert str(ctx.value) == "PostgreSQL ON CONFLICT upsert syntax requires an unique index"

def test_insert_rows_replace_all_index(self):
table = "table"
rows = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_get_object_from_salesforce(self, mock_make_query):
assert salesforce_objects == mock_make_query.return_value

def test_write_object_to_file_invalid_format(self):
with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Format value is not recognized: test"):
self.salesforce_hook.write_object_to_file(query_results=[], filename="test", fmt="test")

@patch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_execute_missing_operation(self):
payload=[],
)

with pytest.raises(ValueError):
with pytest.raises(ValueError, match="Operation 'operation' not found!"):
SalesforceBulkOperator(
task_id="missing_operation",
operation="operation",
Expand All @@ -59,7 +59,9 @@ def test_execute_missing_object_name(self):
payload=[],
)

with pytest.raises(ValueError):
with pytest.raises(
ValueError, match="The required parameter 'object_name' cannot have an empty value."
):
SalesforceBulkOperator(
task_id="missing_object_name",
operation="insert",
Expand Down