diff --git a/providers/oracle/tests/unit/oracle/hooks/test_oracle.py b/providers/oracle/tests/unit/oracle/hooks/test_oracle.py index ade144d8d3eea..11049b5f40f93 100644 --- a/providers/oracle/tests/unit/oracle/hooks/test_oracle.py +++ b/providers/oracle/tests/unit/oracle/hooks/test_oracle.py @@ -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): @@ -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 ) diff --git a/providers/postgres/tests/unit/postgres/assets/test_postgres.py b/providers/postgres/tests/unit/postgres/assets/test_postgres.py index 82c64759a290a..00e779b685b9a 100644 --- a/providers/postgres/tests/unit/postgres/assets/test_postgres.py +++ b/providers/postgres/tests/unit/postgres/assets/test_postgres.py @@ -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) diff --git a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py index f394c561c2c53..0607edc4405c0 100644 --- a/providers/postgres/tests/unit/postgres/hooks/test_postgres.py +++ b/providers/postgres/tests/unit/postgres/hooks/test_postgres.py @@ -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): @@ -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" @@ -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" @@ -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 = [ @@ -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 = [ diff --git a/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py b/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py index 9cb33157aee47..39e2e41fde6eb 100644 --- a/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py +++ b/providers/salesforce/tests/unit/salesforce/hooks/test_salesforce.py @@ -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( diff --git a/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py b/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py index 3ec701ecf41d1..f52e90a3238a7 100644 --- a/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py +++ b/providers/salesforce/tests/unit/salesforce/operators/test_bulk.py @@ -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", @@ -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",