From 3fecabcaca2d7974ea226d364a226b2c91df56b5 Mon Sep 17 00:00:00 2001 From: Christoph Kuhnke Date: Tue, 5 Nov 2024 11:59:10 +0100 Subject: [PATCH] #188 renamed global pytest fixtures (#207) * #188: Renamed global pytest fixtures to avoid name clashes --- doc/changes/changes_0.1.1.md | 6 + .../fixtures/setup_database_fixture.py | 10 +- tests/unit_tests/query_handler/fixtures.py | 44 +-- .../test_scope_query_handler_context.py | 253 +++++++++--------- .../test_top_level_query_handler_context.py | 82 +++--- .../test_python_query_handler_runner.py | 109 ++++---- .../test_json_udf_query_handler.py | 16 +- .../test_json_udf_query_handler_factory.py | 4 +- 8 files changed, 261 insertions(+), 263 deletions(-) diff --git a/doc/changes/changes_0.1.1.md b/doc/changes/changes_0.1.1.md index c553b0a7..4ab6d0fd 100644 --- a/doc/changes/changes_0.1.1.md +++ b/doc/changes/changes_0.1.1.md @@ -4,4 +4,10 @@ Code name: ## Summary +## Bugfixes + * #206: Fixed download URL of SLC from GitHub releases + +## Refactorings + +* #188: Renamed global pytest fixtures to avoid name clashes diff --git a/tests/integration_tests/with_db/fixtures/setup_database_fixture.py b/tests/integration_tests/with_db/fixtures/setup_database_fixture.py index bf2902c7..4e6d692c 100644 --- a/tests/integration_tests/with_db/fixtures/setup_database_fixture.py +++ b/tests/integration_tests/with_db/fixtures/setup_database_fixture.py @@ -10,7 +10,7 @@ @pytest.fixture(scope="session") -def db_schema_name() -> str: +def itest_db_schema() -> str: """ Overrides default fixture from pytest-exasol-extension. """ @@ -18,11 +18,11 @@ def db_schema_name() -> str: @pytest.fixture(scope="module") -def deployed_scripts(pyexasol_connection, db_schema_name, language_alias) -> None: +def deployed_scripts(pyexasol_connection, itest_db_schema, language_alias) -> None: save_aaf_query_loop_lua_script() ScriptsDeployer( language_alias, - db_schema_name, + itest_db_schema, pyexasol_connection, ).deploy_scripts() @@ -30,9 +30,9 @@ def deployed_scripts(pyexasol_connection, db_schema_name, language_alias) -> Non @pytest.fixture(scope="module") def database_with_slc( deployed_scripts, - db_schema_name, + itest_db_schema, bucketfs_connection_factory, deployed_slc, ) -> Tuple[str, str]: bucketfs_connection_factory(BUCKETFS_CONNECTION_NAME, "my-folder") - return BUCKETFS_CONNECTION_NAME, db_schema_name + return BUCKETFS_CONNECTION_NAME, itest_db_schema diff --git a/tests/unit_tests/query_handler/fixtures.py b/tests/unit_tests/query_handler/fixtures.py index 53250c47..85337058 100644 --- a/tests/unit_tests/query_handler/fixtures.py +++ b/tests/unit_tests/query_handler/fixtures.py @@ -12,16 +12,16 @@ @pytest.fixture -def prefix() -> str: +def tmp_db_obj_prefix() -> str: return PREFIX @pytest.fixture -def schema() -> str: +def aaf_pytest_db_schema() -> str: return SCHEMA -class TestConnection(Connection): +class ConnectionMock(Connection): @property def name(self) -> str: @@ -41,15 +41,15 @@ def password(self) -> str: @pytest.fixture -def test_connection() -> Connection: - return TestConnection() +def connection_mock() -> Connection: + return ConnectionMock() @pytest.fixture -def test_connection_lookup(test_connection) -> ConnectionLookup: +def connection_lookup_mock(connection_mock) -> ConnectionLookup: def lookup(name: str) -> Connection: - if name == test_connection.name: - return test_connection + if name == connection_mock.name: + return connection_mock else: raise KeyError() @@ -62,7 +62,7 @@ def sample_mounted_bucket(tmp_path): @pytest.fixture -def bucketfs_location(sample_mounted_bucket): +def sample_bucketfs_location(sample_mounted_bucket): return bfs.path.BucketPath("a/b", sample_mounted_bucket) @@ -73,25 +73,25 @@ def mocked_temporary_bucketfs_location(tmp_path): @pytest.fixture -def top_level_query_handler_context( - bucketfs_location: bfs.path.PathLike, - prefix: str, - schema: str, - test_connection_lookup: ConnectionLookup) -> TopLevelQueryHandlerContext: +def top_level_query_handler_context_mock( + sample_bucketfs_location: bfs.path.PathLike, + tmp_db_obj_prefix: str, + aaf_pytest_db_schema: str, + connection_lookup_mock: ConnectionLookup) -> TopLevelQueryHandlerContext: query_handler_context = TopLevelQueryHandlerContext( - temporary_bucketfs_location=bucketfs_location, - temporary_db_object_name_prefix=prefix, - connection_lookup=test_connection_lookup, - temporary_schema_name=schema + temporary_bucketfs_location=sample_bucketfs_location, + temporary_db_object_name_prefix=tmp_db_obj_prefix, + connection_lookup=connection_lookup_mock, + temporary_schema_name=aaf_pytest_db_schema, ) return query_handler_context @pytest.fixture(params=["top", "child"]) -def scope_query_handler_context( - top_level_query_handler_context: TopLevelQueryHandlerContext, +def scope_query_handler_context_mock( + top_level_query_handler_context_mock: TopLevelQueryHandlerContext, request) -> ScopeQueryHandlerContext: if request.param == "top": - return top_level_query_handler_context + return top_level_query_handler_context_mock else: - return top_level_query_handler_context.get_child_query_handler_context() + return top_level_query_handler_context_mock.get_child_query_handler_context() diff --git a/tests/unit_tests/query_handler/test_scope_query_handler_context.py b/tests/unit_tests/query_handler/test_scope_query_handler_context.py index b2c5d91a..c66b367d 100644 --- a/tests/unit_tests/query_handler/test_scope_query_handler_context.py +++ b/tests/unit_tests/query_handler/test_scope_query_handler_context.py @@ -17,156 +17,161 @@ ChildContextNotReleasedError -def test_temporary_table_prefix_in_name(scope_query_handler_context: ScopeQueryHandlerContext, - prefix: str): - proxy = scope_query_handler_context.get_temporary_table_name() +@pytest.fixture +def context_mock(scope_query_handler_context_mock) -> ScopeQueryHandlerContext: + return scope_query_handler_context_mock + + +@pytest.fixture +def prefix(tmp_db_obj_prefix: str) -> str: + return tmp_db_obj_prefix + + +def test_temporary_table_prefix_in_name(context_mock, prefix): + proxy = context_mock.get_temporary_table_name() assert proxy.name.startswith(prefix) -def test_temporary_table_temporary_schema(scope_query_handler_context: ScopeQueryHandlerContext, - schema: str): - proxy = scope_query_handler_context.get_temporary_table_name() - assert proxy.schema_name.name == schema +def test_temporary_table_temporary_schema(context_mock, aaf_pytest_db_schema: str): + proxy = context_mock.get_temporary_table_name() + assert proxy.schema_name.name == aaf_pytest_db_schema -def test_temporary_view_prefix_in_name(scope_query_handler_context: ScopeQueryHandlerContext, - prefix: str): - proxy = scope_query_handler_context.get_temporary_view_name() +def test_temporary_view_prefix_in_name(context_mock,prefix): + proxy = context_mock.get_temporary_view_name() assert proxy.name.startswith(prefix) -def test_temporary_view_temporary_schema(scope_query_handler_context: ScopeQueryHandlerContext, - schema: str): - proxy = scope_query_handler_context.get_temporary_view_name() - assert proxy.schema_name.name == schema +def test_temporary_view_temporary_schema(context_mock, aaf_pytest_db_schema: str): + proxy = context_mock.get_temporary_view_name() + assert proxy.schema_name.name == aaf_pytest_db_schema -def test_temporary_connection_temporary(scope_query_handler_context: ScopeQueryHandlerContext, - schema: str): - proxy = scope_query_handler_context.get_temporary_connection_name() +def test_temporary_connection_temporary(context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_connection_name() assert isinstance(proxy, ConnectionName) def test_temporary_udf_temporary( - scope_query_handler_context: ScopeQueryHandlerContext, - schema: str): - proxy = scope_query_handler_context.get_temporary_udf_name() + context_mock: ScopeQueryHandlerContext, + aaf_pytest_db_schema: str): + proxy = context_mock.get_temporary_udf_name() assert isinstance(proxy, UDFName) and \ - proxy.schema_name == SchemaName(schema) + proxy.schema_name == SchemaName(aaf_pytest_db_schema) -def test_temporary_bucketfs_file_prefix_in_name(bucketfs_location: bfs.path.PathLike, - scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_bucketfs_location() +def test_temporary_bucketfs_file_prefix_in_name(sample_bucketfs_location: bfs.path.PathLike, + context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_bucketfs_location() actual_path = proxy.bucketfs_location().as_udf_path() - expected_prefix_path = bucketfs_location.as_udf_path() + expected_prefix_path = sample_bucketfs_location.as_udf_path() assert actual_path.startswith(expected_prefix_path) -def test_two_temporary_table_are_not_equal(scope_query_handler_context: ScopeQueryHandlerContext): - proxy1 = scope_query_handler_context.get_temporary_table_name() - proxy2 = scope_query_handler_context.get_temporary_table_name() +def test_two_temporary_table_are_not_equal(context_mock: ScopeQueryHandlerContext): + proxy1 = context_mock.get_temporary_table_name() + proxy2 = context_mock.get_temporary_table_name() assert proxy1.name != proxy2.name -def test_two_temporary_view_are_not_equal(scope_query_handler_context: ScopeQueryHandlerContext): - proxy1 = scope_query_handler_context.get_temporary_view_name() - proxy2 = scope_query_handler_context.get_temporary_view_name() +def test_two_temporary_view_are_not_equal(context_mock: ScopeQueryHandlerContext): + proxy1 = context_mock.get_temporary_view_name() + proxy2 = context_mock.get_temporary_view_name() assert proxy1.name != proxy2.name -def test_two_temporary_bucketfs_files_are_not_equal(scope_query_handler_context: ScopeQueryHandlerContext): - proxy1 = scope_query_handler_context.get_temporary_bucketfs_location() - proxy2 = scope_query_handler_context.get_temporary_bucketfs_location() +def test_two_temporary_bucketfs_files_are_not_equal(context_mock: ScopeQueryHandlerContext): + proxy1 = context_mock.get_temporary_bucketfs_location() + proxy2 = context_mock.get_temporary_bucketfs_location() path1 = proxy1.bucketfs_location().as_udf_path() path2 = proxy2.bucketfs_location().as_udf_path() assert path1 != path2 -def test_temporary_table_name_proxy_use_name_after_release_fails(scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_table_name() - scope_query_handler_context.release() +def test_temporary_table_name_proxy_use_name_after_release_fails(context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_table_name() + context_mock.release() with pytest.raises(RuntimeError, match="TableNameProxy.* already released."): proxy_name = proxy.name -def test_temporary_view_name_proxy_use_name_after_release_fails(scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_view_name() - scope_query_handler_context.release() +def test_temporary_view_name_proxy_use_name_after_release_fails(context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_view_name() + context_mock.release() with pytest.raises(RuntimeError, match="ViewNameProxy.* already released."): proxy_name = proxy.name def test_temporary_table_name_proxy_use_schema_after_release_fails( - scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_table_name() - scope_query_handler_context.release() + context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_table_name() + context_mock.release() with pytest.raises(RuntimeError, match="TableNameProxy.* already released."): proxy_name = proxy.schema_name def test_temporary_view_name_proxy_use_schema_after_release_fails( - scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_view_name() - scope_query_handler_context.release() + context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_view_name() + context_mock.release() with pytest.raises(RuntimeError, match="ViewNameProxy.* already released."): proxy_name = proxy.schema_name def test_temporary_table_name_proxy_use_quoted_name_after_release_fails( - scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_table_name() - scope_query_handler_context.release() + context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_table_name() + context_mock.release() with pytest.raises(RuntimeError, match="TableNameProxy.* already released."): proxy_name = proxy.quoted_name def test_temporary_view_name_proxy_use_quoted_name_after_release_fails( - scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_view_name() - scope_query_handler_context.release() + context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_view_name() + context_mock.release() with pytest.raises(RuntimeError, match="ViewNameProxy.* already released."): proxy_name = proxy.quoted_name def test_temporary_table_name_proxy_use_fully_qualified_after_release_fails( - scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_table_name() - scope_query_handler_context.release() + context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_table_name() + context_mock.release() with pytest.raises(RuntimeError, match="TableNameProxy.* already released."): proxy_name = proxy.fully_qualified def test_temporary_view_name_proxy_use_fully_qualified_after_release_fails( - scope_query_handler_context: ScopeQueryHandlerContext): - proxy = scope_query_handler_context.get_temporary_view_name() - scope_query_handler_context.release() + context_mock: ScopeQueryHandlerContext): + proxy = context_mock.get_temporary_view_name() + context_mock.release() with pytest.raises(RuntimeError, match="ViewNameProxy.* already released."): proxy_name = proxy.fully_qualified -def test_get_temporary_view_after_release_fails(scope_query_handler_context: ScopeQueryHandlerContext): - scope_query_handler_context.release() +def test_get_temporary_view_after_release_fails(context_mock: ScopeQueryHandlerContext): + context_mock.release() with pytest.raises(RuntimeError, match="Context already released."): - proxy = scope_query_handler_context.get_temporary_view_name() + proxy = context_mock.get_temporary_view_name() -def test_get_temporary_table_after_release_fails(scope_query_handler_context: ScopeQueryHandlerContext): - scope_query_handler_context.release() +def test_get_temporary_table_after_release_fails(context_mock: ScopeQueryHandlerContext): + context_mock.release() with pytest.raises(RuntimeError, match="Context already released."): - proxy = scope_query_handler_context.get_temporary_table_name() + proxy = context_mock.get_temporary_table_name() -def test_get_temporary_bucketfs_file_after_release_fails(scope_query_handler_context: ScopeQueryHandlerContext): - scope_query_handler_context.release() +def test_get_temporary_bucketfs_file_after_release_fails(context_mock: ScopeQueryHandlerContext): + context_mock.release() with pytest.raises(RuntimeError, match="Context already released."): - proxy = scope_query_handler_context.get_temporary_bucketfs_location() + proxy = context_mock.get_temporary_bucketfs_location() -def test_use_child_context_after_release_fails(scope_query_handler_context: ScopeQueryHandlerContext): - child = scope_query_handler_context.get_child_query_handler_context() +def test_use_child_context_after_release_fails(context_mock: ScopeQueryHandlerContext): + child = context_mock.get_child_query_handler_context() try: - scope_query_handler_context.release() + context_mock.release() except: pass with pytest.raises(RuntimeError, match="Context already released."): @@ -181,9 +186,9 @@ def not_raises(exception): raise pytest.fail("DID RAISE {0}".format(exception)) -def test_transfer_between_siblings(scope_query_handler_context: ScopeQueryHandlerContext): - child1 = scope_query_handler_context.get_child_query_handler_context() - child2 = scope_query_handler_context.get_child_query_handler_context() +def test_transfer_between_siblings(context_mock: ScopeQueryHandlerContext): + child1 = context_mock.get_child_query_handler_context() + child2 = context_mock.get_child_query_handler_context() object_proxy1 = child1.get_temporary_table_name() object_proxy2 = child1.get_temporary_table_name() child1.transfer_object_to(object_proxy1, child2) @@ -195,9 +200,9 @@ def test_transfer_between_siblings(scope_query_handler_context: ScopeQueryHandle _ = object_proxy2.name -def test_transfer_siblings_check_ownership_transfer_to_target(scope_query_handler_context: ScopeQueryHandlerContext): - child1 = scope_query_handler_context.get_child_query_handler_context() - child2 = scope_query_handler_context.get_child_query_handler_context() +def test_transfer_siblings_check_ownership_transfer_to_target(context_mock: ScopeQueryHandlerContext): + child1 = context_mock.get_child_query_handler_context() + child2 = context_mock.get_child_query_handler_context() object_proxy1 = child1.get_temporary_table_name() object_proxy2 = child2.get_temporary_table_name() child1.transfer_object_to(object_proxy1, child2) @@ -211,8 +216,8 @@ def test_transfer_siblings_check_ownership_transfer_to_target(scope_query_handle def test_transfer_child_parent_check_ownership_transfer_to_target( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context + context_mock: ScopeQueryHandlerContext): + parent = context_mock child1 = parent.get_child_query_handler_context() child2 = parent.get_child_query_handler_context() object_proxy1 = child1.get_temporary_table_name() @@ -222,8 +227,8 @@ def test_transfer_child_parent_check_ownership_transfer_to_target( def test_transfer_parent_child_check_ownership_transfer_to_target( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context + context_mock: ScopeQueryHandlerContext): + parent = context_mock child1 = parent.get_child_query_handler_context() child2 = parent.get_child_query_handler_context() object_proxy1 = parent.get_temporary_table_name() @@ -232,10 +237,10 @@ def test_transfer_parent_child_check_ownership_transfer_to_target( parent.transfer_object_to(object_proxy1, child2) -def test_transfer_siblings_checK_losing_ownership(scope_query_handler_context: ScopeQueryHandlerContext): - child1 = scope_query_handler_context.get_child_query_handler_context() - child2 = scope_query_handler_context.get_child_query_handler_context() - child3 = scope_query_handler_context.get_child_query_handler_context() +def test_transfer_siblings_checK_losing_ownership(context_mock: ScopeQueryHandlerContext): + child1 = context_mock.get_child_query_handler_context() + child2 = context_mock.get_child_query_handler_context() + child3 = context_mock.get_child_query_handler_context() object_proxy1 = child1.get_temporary_table_name() child1.transfer_object_to(object_proxy1, child2) @@ -244,9 +249,9 @@ def test_transfer_siblings_checK_losing_ownership(scope_query_handler_context: S def test_transfer_between_siblings_object_from_different_context( - scope_query_handler_context: ScopeQueryHandlerContext): - child1 = scope_query_handler_context.get_child_query_handler_context() - child2 = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + child1 = context_mock.get_child_query_handler_context() + child2 = context_mock.get_child_query_handler_context() grand_child1 = child1.get_child_query_handler_context() object_proxy = grand_child1.get_temporary_table_name() with pytest.raises(RuntimeError, @@ -254,9 +259,9 @@ def test_transfer_between_siblings_object_from_different_context( child1.transfer_object_to(object_proxy, child2) -def test_transfer_between_child_and_parent(scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - child = scope_query_handler_context.get_child_query_handler_context() +def test_transfer_between_child_and_parent(context_mock: ScopeQueryHandlerContext): + parent = context_mock + child = context_mock.get_child_query_handler_context() object_proxy1 = child.get_temporary_table_name() object_proxy2 = child.get_temporary_table_name() child.transfer_object_to(object_proxy1, parent) @@ -268,9 +273,9 @@ def test_transfer_between_child_and_parent(scope_query_handler_context: ScopeQue _ = object_proxy2.name -def test_transfer_between_parent_and_child(scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - child = scope_query_handler_context.get_child_query_handler_context() +def test_transfer_between_parent_and_child(context_mock: ScopeQueryHandlerContext): + parent = context_mock + child = context_mock.get_child_query_handler_context() object_proxy = parent.get_temporary_table_name() parent.transfer_object_to(object_proxy, child) child.release() @@ -280,9 +285,9 @@ def test_transfer_between_parent_and_child(scope_query_handler_context: ScopeQue def test_illegal_transfer_between_grand_child_and_parent( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - child = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + parent = context_mock + child = context_mock.get_child_query_handler_context() grand_child = child.get_child_query_handler_context() object_proxy = grand_child.get_temporary_table_name() with pytest.raises(RuntimeError, match="Given ScopeQueryHandlerContext not a child, parent or sibling."): @@ -290,9 +295,9 @@ def test_illegal_transfer_between_grand_child_and_parent( def test_illegal_transfer_between_parent_and_grand_child( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - child = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + parent = context_mock + child = context_mock.get_child_query_handler_context() grand_child = child.get_child_query_handler_context() object_proxy = parent.get_temporary_table_name() with pytest.raises(RuntimeError, @@ -302,26 +307,26 @@ def test_illegal_transfer_between_parent_and_grand_child( def test_release_parent_before_child_with_temporary_object_expect_exception( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - child = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + parent = context_mock + child = context_mock.get_child_query_handler_context() _ = child.get_temporary_table_name() with pytest.raises(ChildContextNotReleasedError): parent.release() def test_release_parent_before_child_without_temporary_object_expect_exception( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - _ = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + parent = context_mock + _ = context_mock.get_child_query_handler_context() with pytest.raises(ChildContextNotReleasedError): parent.release() def test_release_parent_before_grand_child_with_temporary_object_expect_exception( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - child = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + parent = context_mock + child = context_mock.get_child_query_handler_context() grand_child = child.get_child_query_handler_context() _ = grand_child.get_temporary_table_name() with pytest.raises(ChildContextNotReleasedError): @@ -329,32 +334,32 @@ def test_release_parent_before_grand_child_with_temporary_object_expect_exceptio def test_release_parent_before_grand_child_without_temporary_object_expect_exception( - scope_query_handler_context: ScopeQueryHandlerContext): - parent = scope_query_handler_context - child = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + parent = context_mock + child = context_mock.get_child_query_handler_context() _ = child.get_child_query_handler_context() with pytest.raises(ChildContextNotReleasedError): parent.release() def test_cleanup_parent_before_grand_child_without_temporary_objects( - scope_query_handler_context: ScopeQueryHandlerContext): - child1 = scope_query_handler_context.get_child_query_handler_context() - child2 = scope_query_handler_context.get_child_query_handler_context() + context_mock: ScopeQueryHandlerContext): + child1 = context_mock.get_child_query_handler_context() + child2 = context_mock.get_child_query_handler_context() _ = child1.get_child_query_handler_context() _ = child2.get_child_query_handler_context() _ = child1.get_child_query_handler_context() _ = child2.get_child_query_handler_context() with pytest.raises(ChildContextNotReleasedError) as e: - scope_query_handler_context.release() + context_mock.release() not_released_contexts = e.value.get_all_not_released_contexts() f = "f" assert len(not_released_contexts) == 6 -def test_using_table_name_proxy_in_table(scope_query_handler_context: ScopeQueryHandlerContext): - table_name = scope_query_handler_context.get_temporary_table_name() +def test_using_table_name_proxy_in_table(context_mock: ScopeQueryHandlerContext): + table_name = context_mock.get_temporary_table_name() table = Table(table_name, columns=[ ( @@ -367,8 +372,8 @@ def test_using_table_name_proxy_in_table(scope_query_handler_context: ScopeQuery assert table.name is not None -def test_using_view_name_proxy_in_view(scope_query_handler_context: ScopeQueryHandlerContext): - view_name = scope_query_handler_context.get_temporary_view_name() +def test_using_view_name_proxy_in_view(context_mock: ScopeQueryHandlerContext): + view_name = context_mock.get_temporary_view_name() view = View(view_name, columns=[ ( ColumnBuilder(). @@ -380,14 +385,14 @@ def test_using_view_name_proxy_in_view(scope_query_handler_context: ScopeQueryHa def test_get_connection_existing_connection( - scope_query_handler_context: ScopeQueryHandlerContext, - test_connection: Connection + context_mock: ScopeQueryHandlerContext, + connection_mock: Connection ): - connection = scope_query_handler_context.get_connection("existing") + connection = context_mock.get_connection("existing") assert connection == connection def test_get_connection_not_existing_connection( - scope_query_handler_context: ScopeQueryHandlerContext): + context_mock: ScopeQueryHandlerContext): with pytest.raises(KeyError): - scope_query_handler_context.get_connection("not_existing") + context_mock.get_connection("not_existing") diff --git a/tests/unit_tests/query_handler/test_top_level_query_handler_context.py b/tests/unit_tests/query_handler/test_top_level_query_handler_context.py index 84d281c2..311d9ddd 100644 --- a/tests/unit_tests/query_handler/test_top_level_query_handler_context.py +++ b/tests/unit_tests/query_handler/test_top_level_query_handler_context.py @@ -7,74 +7,73 @@ from exasol_advanced_analytics_framework.query_handler.query.drop_view_query import DropViewQuery -def test_cleanup_released_temporary_table_proxies( - top_level_query_handler_context: TopLevelQueryHandlerContext): - proxy = top_level_query_handler_context.get_temporary_table_name() +@pytest.fixture +def context_mock(top_level_query_handler_context_mock) -> TopLevelQueryHandlerContext: + return top_level_query_handler_context_mock + + +def test_cleanup_released_temporary_table_proxies(context_mock): + proxy = context_mock.get_temporary_table_name() proxy_fully_qualified = proxy.fully_qualified - top_level_query_handler_context.release() - queries = top_level_query_handler_context.cleanup_released_object_proxies() + context_mock.release() + queries = context_mock.cleanup_released_object_proxies() assert len(queries) == 1 and isinstance(queries[0], DropTableQuery) \ and queries[0].query_string == f"DROP TABLE IF EXISTS {proxy_fully_qualified};" -def test_cleanup_released_temporary_view_proxies( - top_level_query_handler_context: TopLevelQueryHandlerContext): - proxy = top_level_query_handler_context.get_temporary_view_name() +def test_cleanup_released_temporary_view_proxies(context_mock): + proxy = context_mock.get_temporary_view_name() proxy_fully_qualified = proxy.fully_qualified - top_level_query_handler_context.release() - queries = top_level_query_handler_context.cleanup_released_object_proxies() + context_mock.release() + queries = context_mock.cleanup_released_object_proxies() assert len(queries) == 1 and isinstance(queries[0], DropViewQuery) \ and queries[0].query_string == f"DROP VIEW IF EXISTS {proxy_fully_qualified};" -def test_cleanup_released_bucketfs_object_with_uploaded_file_proxies( - top_level_query_handler_context: TopLevelQueryHandlerContext, - bucketfs_location: bfs.path.PathLike): - proxy = top_level_query_handler_context.get_temporary_bucketfs_location() +def test_cleanup_released_bucketfs_object_with_uploaded_file_proxies(context_mock, + sample_bucketfs_location: bfs.path.PathLike): + proxy = context_mock.get_temporary_bucketfs_location() # create dummy file with content "test" (proxy.bucketfs_location() / "test_file.txt").write(b"test") - top_level_query_handler_context.release() - top_level_query_handler_context.cleanup_released_object_proxies() - assert not bucketfs_location.is_dir() + context_mock.release() + context_mock.cleanup_released_object_proxies() + assert not sample_bucketfs_location.is_dir() -def test_cleanup_released_bucketfs_object_without_uploaded_file_proxies_after_release( - top_level_query_handler_context: TopLevelQueryHandlerContext): - _ = top_level_query_handler_context.get_temporary_bucketfs_location() - top_level_query_handler_context.release() - top_level_query_handler_context.cleanup_released_object_proxies() +def test_cleanup_released_bucketfs_object_without_uploaded_file_proxies_after_release(context_mock): + _ = context_mock.get_temporary_bucketfs_location() + context_mock.release() + context_mock.cleanup_released_object_proxies() -def test_cleanup_release_in_reverse_order_at_top_level( - top_level_query_handler_context: TopLevelQueryHandlerContext): - proxies = [top_level_query_handler_context.get_temporary_table_name() for _ in range(10)] +def test_cleanup_release_in_reverse_order_at_top_level(context_mock): + proxies = [context_mock.get_temporary_table_name() for _ in range(10)] table_names = [proxy.fully_qualified for proxy in proxies] - top_level_query_handler_context.release() - query_objects = top_level_query_handler_context.cleanup_released_object_proxies() + context_mock.release() + query_objects = context_mock.cleanup_released_object_proxies() actual_queries = [query.query_string for query in query_objects] expected_queries = [f"DROP TABLE IF EXISTS {table_name};" for table_name in reversed(table_names)] assert expected_queries == actual_queries -def test_cleanup_release_in_reverse_order_at_child( - top_level_query_handler_context: TopLevelQueryHandlerContext): - parent_proxies = [top_level_query_handler_context.get_temporary_table_name() for _ in range(10)] +def test_cleanup_release_in_reverse_order_at_child(context_mock): + parent_proxies = [context_mock.get_temporary_table_name() for _ in range(10)] - child = top_level_query_handler_context.get_child_query_handler_context() + child = context_mock.get_child_query_handler_context() child_proxies = [child.get_temporary_table_name() for _ in range(10)] child_table_names = [proxy.fully_qualified for proxy in child_proxies] child.release() - child_query_objects = top_level_query_handler_context.cleanup_released_object_proxies() + child_query_objects = context_mock.cleanup_released_object_proxies() child_actual_queries = [query.query_string for query in child_query_objects] child_expected_queries = [f"DROP TABLE IF EXISTS {table_name};" for table_name in reversed(child_table_names)] - parent_proxies.extend([top_level_query_handler_context.get_temporary_table_name() for _ in range(10)]) + parent_proxies.extend([context_mock.get_temporary_table_name() for _ in range(10)]) parent_table_names = [proxy.fully_qualified for proxy in parent_proxies] - top_level_query_handler_context.release() - parent_query_objects = top_level_query_handler_context.cleanup_released_object_proxies() + context_mock.release() + parent_query_objects = context_mock.cleanup_released_object_proxies() parent_actual_queries = [query.query_string for query in parent_query_objects] parent_expected_queries = [f"DROP TABLE IF EXISTS {table_name};" for table_name in reversed(parent_table_names)] @@ -82,12 +81,11 @@ def test_cleanup_release_in_reverse_order_at_child( parent_expected_queries == parent_actual_queries -def test_cleanup_parent_before_grand_child_with_temporary_objects( - top_level_query_handler_context: TopLevelQueryHandlerContext): - _ = top_level_query_handler_context.get_temporary_table_name() - child1 = top_level_query_handler_context.get_child_query_handler_context() +def test_cleanup_parent_before_grand_child_with_temporary_objects(context_mock): + _ = context_mock.get_temporary_table_name() + child1 = context_mock.get_child_query_handler_context() _ = child1.get_temporary_table_name() - child2 = top_level_query_handler_context.get_child_query_handler_context() + child2 = context_mock.get_child_query_handler_context() _ = child2.get_temporary_table_name() grand_child11 = child1.get_child_query_handler_context() _ = grand_child11.get_temporary_table_name() @@ -99,6 +97,6 @@ def test_cleanup_parent_before_grand_child_with_temporary_objects( _ = grand_child22.get_temporary_table_name() with pytest.raises(ChildContextNotReleasedError): - top_level_query_handler_context.release() - cleanup_queries = top_level_query_handler_context.cleanup_released_object_proxies() + context_mock.release() + cleanup_queries = context_mock.cleanup_released_object_proxies() assert len(cleanup_queries) == 7 diff --git a/tests/unit_tests/query_handler_runner/test_python_query_handler_runner.py b/tests/unit_tests/query_handler_runner/test_python_query_handler_runner.py index 6dcd99f0..b2d20926 100644 --- a/tests/unit_tests/query_handler_runner/test_python_query_handler_runner.py +++ b/tests/unit_tests/query_handler_runner/test_python_query_handler_runner.py @@ -25,21 +25,13 @@ @pytest.fixture() -def temporary_schema_name(): - return "temp_schema_name" +def prefix(tmp_db_obj_prefix): + return tmp_db_obj_prefix @pytest.fixture -def top_level_query_handler_context(mocked_temporary_bucketfs_location, - temporary_schema_name, - test_connection_lookup): - top_level_query_handler_context = TopLevelQueryHandlerContext( - temporary_bucketfs_location=mocked_temporary_bucketfs_location, - temporary_db_object_name_prefix="temp_db_object", - connection_lookup=test_connection_lookup, - temporary_schema_name=temporary_schema_name, - ) - return top_level_query_handler_context +def context_mock(top_level_query_handler_context_mock) -> TopLevelQueryHandlerContext: + return top_level_query_handler_context_mock class TestInput: @@ -64,7 +56,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini pass -def test_start_finish(top_level_query_handler_context): +def test_start_finish(context_mock): """ This tests runs a query handler which returns a Finish result from the start method. We expect no queries to be executed and result of the Finish object returned. @@ -73,7 +65,7 @@ def test_start_finish(top_level_query_handler_context): test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=StartFinishTestQueryHandler ) @@ -95,7 +87,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini pass -def test_start_finish_cleanup_queries(temporary_schema_name, top_level_query_handler_context): +def test_start_finish_cleanup_queries(aaf_pytest_db_schema, prefix, context_mock): """ This tests runs a query handler which registers a temporary table in the start method and then directly returns a Finish result. We expect a cleanup query for the temporary @@ -105,13 +97,13 @@ def test_start_finish_cleanup_queries(temporary_schema_name, top_level_query_han test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=StartFinishCleanupQueriesTestQueryHandler ) test_output = query_handler_runner.run() assert test_output.test_input == test_input and \ - sql_executor.queries == [f"""DROP TABLE IF EXISTS "{temporary_schema_name}"."temp_db_object_1";"""] + sql_executor.queries == [f"""DROP TABLE IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_1";"""] class StartErrorCleanupQueriesTestQueryHandler(QueryHandler[TestInput, TestOutput]): @@ -127,7 +119,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini pass -def test_start_error_cleanup_queries(temporary_schema_name, top_level_query_handler_context): +def test_start_error_cleanup_queries(aaf_pytest_db_schema, prefix, context_mock): """ This tests runs a query handler which registers a temporary table in the start method and then directly raise an exception. We expect a cleanup query for the temporary @@ -137,13 +129,13 @@ def test_start_error_cleanup_queries(temporary_schema_name, top_level_query_hand test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=StartErrorCleanupQueriesTestQueryHandler ) with pytest.raises(Exception, match="Execution of query handler .* failed.") as ex: test_output = query_handler_runner.run() - assert sql_executor.queries == [f"""DROP TABLE IF EXISTS "{temporary_schema_name}"."temp_db_object_1";"""] and \ + assert sql_executor.queries == [f"""DROP TABLE IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_1";"""] and \ ex.value.__cause__.args[0] == "Start failed" @@ -167,7 +159,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini return Finish[TestOutput](TestOutput(self._parameter)) -def test_continue_finish(temporary_schema_name, top_level_query_handler_context): +def test_continue_finish(aaf_pytest_db_schema, prefix, context_mock): """ This tests runs a query handler which returns Continue result from the start method and expect handle_query_result to be called. Further, it expects that @@ -190,7 +182,7 @@ def test_continue_finish(temporary_schema_name, top_level_query_handler_context) test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=ContinueFinishTestQueryHandler ) @@ -199,7 +191,7 @@ def test_continue_finish(temporary_schema_name, top_level_query_handler_context) sql_executor.queries == [ cleandoc( f""" - CREATE OR REPLACE VIEW "{temporary_schema_name}"."temp_db_object_2_1" AS + CREATE OR REPLACE VIEW "{aaf_pytest_db_schema}"."{prefix}_2_1" AS SELECT 1 as "a"; """ ), @@ -207,9 +199,9 @@ def test_continue_finish(temporary_schema_name, top_level_query_handler_context) f""" SELECT "a" - FROM "{temporary_schema_name}"."temp_db_object_2_1"; + FROM "{aaf_pytest_db_schema}"."{prefix}_2_1"; """), - f"""DROP VIEW IF EXISTS "{temporary_schema_name}"."temp_db_object_2_1";""", + f"""DROP VIEW IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_2_1";""", ] @@ -227,7 +219,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini raise AssertionError("handle_query_result shouldn't be called") -def test_continue_wrong_columns(temporary_schema_name, top_level_query_handler_context): +def test_continue_wrong_columns(aaf_pytest_db_schema, context_mock): """ This tests runs a query handler which returns Continue result with mismatching column definition between the input query and its column definition. We expect the query handler runner to raise @@ -248,7 +240,7 @@ def test_continue_wrong_columns(temporary_schema_name, top_level_query_handler_c test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=ContinueWrongColumnsTestQueryHandler ) @@ -276,7 +268,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini return Finish[TestOutput](TestOutput(self._parameter)) -def test_continue_query_list(temporary_schema_name, top_level_query_handler_context): +def test_continue_query_list(aaf_pytest_db_schema, prefix, context_mock): """ This tests runs a query handler which returns Continue result from the start method which contains a query list. We expect to be handle_query_result to be called and @@ -304,7 +296,7 @@ def test_continue_query_list(temporary_schema_name, top_level_query_handler_cont test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=ContinueQueryListTestQueryHandler ) @@ -314,16 +306,16 @@ def test_continue_query_list(temporary_schema_name, top_level_query_handler_cont f"""SELECT 1""", cleandoc( f""" - CREATE OR REPLACE VIEW "{temporary_schema_name}"."temp_db_object_2_1" AS + CREATE OR REPLACE VIEW "{aaf_pytest_db_schema}"."{prefix}_2_1" AS SELECT 1 as "a"; """), cleandoc( f""" SELECT "a" - FROM "{temporary_schema_name}"."temp_db_object_2_1"; + FROM "{aaf_pytest_db_schema}"."{prefix}_2_1"; """), - f"""DROP VIEW IF EXISTS "{temporary_schema_name}"."temp_db_object_2_1";""", + f"""DROP VIEW IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_2_1";""", ] @@ -346,7 +338,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini raise Exception("Start failed") -def test_continue_error_cleanup_queries(temporary_schema_name, top_level_query_handler_context): +def test_continue_error_cleanup_queries(aaf_pytest_db_schema, prefix, context_mock): """ This tests runs a query handler which registers a temporary table in the handle_query_result method and then directly raise an exception. We expect a cleanup query for the temporary @@ -369,7 +361,7 @@ def test_continue_error_cleanup_queries(temporary_schema_name, top_level_query_h test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=ContinueErrorCleanupQueriesTestQueryHandler ) @@ -378,17 +370,17 @@ def test_continue_error_cleanup_queries(temporary_schema_name, top_level_query_h assert sql_executor.queries == [ cleandoc( f""" - CREATE OR REPLACE VIEW "{temporary_schema_name}"."temp_db_object_2_1" AS + CREATE OR REPLACE VIEW "{aaf_pytest_db_schema}"."{prefix}_2_1" AS SELECT 1 as "a"; """), cleandoc( f""" SELECT "a" - FROM "{temporary_schema_name}"."temp_db_object_2_1"; + FROM "{aaf_pytest_db_schema}"."{prefix}_2_1"; """), - f"""DROP TABLE IF EXISTS "{temporary_schema_name}"."temp_db_object_3";""", - f"""DROP VIEW IF EXISTS "{temporary_schema_name}"."temp_db_object_2_1";""", + f"""DROP TABLE IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_3";""", + f"""DROP VIEW IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_2_1";""", ] @@ -424,7 +416,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini return Finish[TestOutput](TestOutput(self._parameter)) -def test_continue_continue_finish(temporary_schema_name, top_level_query_handler_context): +def test_continue_continue_finish(aaf_pytest_db_schema, prefix, context_mock): """ This tests runs a query handler which returns Continue from the first call to handle_query_result method and the second time it returns Finish. We expect two input queries to be executed; one per Continue and @@ -451,11 +443,10 @@ def test_continue_continue_finish(temporary_schema_name, top_level_query_handler input_query_result_set2, drop_input_query_view_result_set, ]) - temporary_schema_name = "temp_schema_name" test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=ContinueContinueFinishTestQueryHandler ) @@ -464,28 +455,28 @@ def test_continue_continue_finish(temporary_schema_name, top_level_query_handler sql_executor.queries == [ cleandoc( f""" - CREATE OR REPLACE VIEW "{temporary_schema_name}"."temp_db_object_2_1" AS + CREATE OR REPLACE VIEW "{aaf_pytest_db_schema}"."{prefix}_2_1" AS SELECT 1 as "a"; """), cleandoc( f""" SELECT "a" - FROM "{temporary_schema_name}"."temp_db_object_2_1"; + FROM "{aaf_pytest_db_schema}"."{prefix}_2_1"; """), - f"""DROP VIEW IF EXISTS "{temporary_schema_name}"."temp_db_object_2_1";""", + f"""DROP VIEW IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_2_1";""", cleandoc( f""" - CREATE OR REPLACE VIEW "{temporary_schema_name}"."temp_db_object_4_1" AS + CREATE OR REPLACE VIEW "{aaf_pytest_db_schema}"."{prefix}_4_1" AS SELECT 1 as "b"; """), cleandoc( f""" SELECT "b" - FROM "{temporary_schema_name}"."temp_db_object_4_1"; + FROM "{aaf_pytest_db_schema}"."{prefix}_4_1"; """), - f"""DROP VIEW IF EXISTS "{temporary_schema_name}"."temp_db_object_4_1";""", + f"""DROP VIEW IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_4_1";""", ] @@ -521,7 +512,7 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini return Finish[TestOutput](TestOutput(self._parameter)) -def test_continue_cleanup_continue_finish(temporary_schema_name, top_level_query_handler_context): +def test_continue_cleanup_continue_finish(aaf_pytest_db_schema, prefix, context_mock): """ This tests runs a query handler which creates the temporary table of a child query context manager. Then it returns a Continue result, such that handle_query_result will be called. During the call to @@ -550,11 +541,10 @@ def test_continue_cleanup_continue_finish(temporary_schema_name, top_level_query input_query_result_set2, drop_input_query_view_result_set, ]) - temporary_schema_name = "temp_schema_name" test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=ContinueContinueCleanupFinishTestQueryHandler ) @@ -563,29 +553,29 @@ def test_continue_cleanup_continue_finish(temporary_schema_name, top_level_query sql_executor.queries == [ cleandoc( f""" - CREATE OR REPLACE VIEW "{temporary_schema_name}"."temp_db_object_4_1" AS + CREATE OR REPLACE VIEW "{aaf_pytest_db_schema}"."{prefix}_4_1" AS SELECT 1 as "a"; """), cleandoc( f""" SELECT "a" - FROM "{temporary_schema_name}"."temp_db_object_4_1"; + FROM "{aaf_pytest_db_schema}"."{prefix}_4_1"; """), - f"""DROP VIEW IF EXISTS "{temporary_schema_name}"."temp_db_object_4_1";""", - f"""DROP TABLE IF EXISTS "{temporary_schema_name}"."temp_db_object_2_1";""", + f"""DROP VIEW IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_4_1";""", + f"""DROP TABLE IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_2_1";""", cleandoc( f""" - CREATE OR REPLACE VIEW "{temporary_schema_name}"."temp_db_object_6_1" AS + CREATE OR REPLACE VIEW "{aaf_pytest_db_schema}"."{prefix}_6_1" AS SELECT 1 as "b"; """), cleandoc( f""" SELECT "b" - FROM "{temporary_schema_name}"."temp_db_object_6_1"; + FROM "{aaf_pytest_db_schema}"."{prefix}_6_1"; """), - f"""DROP VIEW IF EXISTS "{temporary_schema_name}"."temp_db_object_6_1";""", + f"""DROP VIEW IF EXISTS "{aaf_pytest_db_schema}"."{prefix}_6_1";""", ] @@ -603,13 +593,12 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini pass -def test_fail_in_cleanup(temporary_schema_name, top_level_query_handler_context): +def test_fail_in_cleanup(aaf_pytest_db_schema, context_mock): sql_executor = MockSQLExecutor() - temporary_schema_name = "temp_schema_name" test_input = TestInput() query_handler_runner = PythonQueryHandlerRunner[TestInput, TestOutput]( sql_executor=sql_executor, - top_level_query_handler_context=top_level_query_handler_context, + top_level_query_handler_context=context_mock, parameter=test_input, query_handler_factory=FailInCleanupAfterException ) diff --git a/tests/unit_tests/udf_framework/test_json_udf_query_handler.py b/tests/unit_tests/udf_framework/test_json_udf_query_handler.py index 1db33709..2dfd6f94 100644 --- a/tests/unit_tests/udf_framework/test_json_udf_query_handler.py +++ b/tests/unit_tests/udf_framework/test_json_udf_query_handler.py @@ -29,23 +29,23 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini raise AssertionError("Should not be called") -def test_constructor_valid_json(top_level_query_handler_context): +def test_constructor_valid_json(top_level_query_handler_context_mock): parameter = { "test_key": "test_value" } json_str_parameter = json.dumps(parameter) query_handler = JsonUDFQueryHandler( parameter=json_str_parameter, - query_handler_context=top_level_query_handler_context, + query_handler_context=top_level_query_handler_context_mock, wrapped_json_query_handler_class=ConstructorTestJSONQueryHandler ) -def test_constructor_invalid_json(top_level_query_handler_context): +def test_constructor_invalid_json(top_level_query_handler_context_mock): with pytest.raises(JSONDecodeError): query_handler = JsonUDFQueryHandler( parameter="'abc'='ced'", - query_handler_context=top_level_query_handler_context, + query_handler_context=top_level_query_handler_context_mock, wrapped_json_query_handler_class=ConstructorTestJSONQueryHandler ) @@ -63,14 +63,14 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini raise AssertionError("Should not be called") -def test_start_return_parameter(top_level_query_handler_context): +def test_start_return_parameter(top_level_query_handler_context_mock): parameter = { "test_key": "test_value" } json_str_parameter = json.dumps(parameter) query_handler = JsonUDFQueryHandler( parameter=json_str_parameter, - query_handler_context=top_level_query_handler_context, + query_handler_context=top_level_query_handler_context_mock, wrapped_json_query_handler_class=StartReturnParameterTestJSONQueryHandler ) result = query_handler.start() @@ -91,14 +91,14 @@ def handle_query_result(self, query_result: QueryResult) -> Union[Continue, Fini return Finish[JSONType]({"a": a}) -def test_handle_query_result_check_query_result(top_level_query_handler_context): +def test_handle_query_result_check_query_result(top_level_query_handler_context_mock): parameter = { "test_key": "test_value" } json_str_parameter = json.dumps(parameter) query_handler = JsonUDFQueryHandler( parameter=json_str_parameter, - query_handler_context=top_level_query_handler_context, + query_handler_context=top_level_query_handler_context_mock, wrapped_json_query_handler_class=HandleQueryResultCheckQueryResultTestJSONQueryHandler ) result = query_handler.handle_query_result( diff --git a/tests/unit_tests/udf_framework/test_json_udf_query_handler_factory.py b/tests/unit_tests/udf_framework/test_json_udf_query_handler_factory.py index ded827f2..5e4f2ac4 100644 --- a/tests/unit_tests/udf_framework/test_json_udf_query_handler_factory.py +++ b/tests/unit_tests/udf_framework/test_json_udf_query_handler_factory.py @@ -35,10 +35,10 @@ def __init__(self): super().__init__(TestJSONQueryHandler) -def test(top_level_query_handler_context): +def test(top_level_query_handler_context_mock): test_input = {"a": 1} json_str = json.dumps(test_input) - query_handler = TestJsonUDFQueryHandlerFactory().create(json_str, top_level_query_handler_context) + query_handler = TestJsonUDFQueryHandlerFactory().create(json_str, top_level_query_handler_context_mock) start_result = query_handler.start() handle_query_result = query_handler.handle_query_result( PythonQueryResult(data=[(1,)],