From efc1516244e25b21b01ec26d44f0bb453b36cef7 Mon Sep 17 00:00:00 2001 From: mabulgu Date: Sat, 31 Aug 2024 18:48:29 +0300 Subject: [PATCH] fix tests --- tests/test_acls_command.py | 36 ++++++++---- tests/test_clusters_command.py | 42 +++++++++----- tests/test_connect_connectors_command.py | 6 +- tests/test_users_command.py | 72 ++++++++++++++++-------- 4 files changed, 104 insertions(+), 52 deletions(-) diff --git a/tests/test_acls_command.py b/tests/test_acls_command.py index 906bb00..7921ac4 100644 --- a/tests/test_acls_command.py +++ b/tests/test_acls_command.py @@ -118,9 +118,9 @@ def test_add_acls_without_principal(self, mock_os): @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_add_topic_acl( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: user_yaml = file.read() @@ -152,11 +152,13 @@ def test_add_topic_acl( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_remove_topic_acl( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_one_topic_acl.yaml" @@ -188,11 +190,13 @@ def test_remove_topic_acl( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_add_topic_acl_to_one_acl( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_one_topic_acl.yaml" @@ -226,11 +230,13 @@ def test_add_topic_acl_to_one_acl( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_remove_topic_acl_from_two_acls( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_two_topic_acls.yaml" @@ -264,11 +270,13 @@ def test_remove_topic_acl_from_two_acls( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_add_topic_acl_with_two_operations( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_one_topic_acl.yaml" @@ -304,11 +312,13 @@ def test_add_topic_acl_with_two_operations( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_add_group_acl( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_one_topic_acl.yaml" @@ -342,3 +352,5 @@ def test_add_group_acl( expected_user_yaml = file.read() result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + + mock_replace_using_yaml.assert_called_once() diff --git a/tests/test_clusters_command.py b/tests/test_clusters_command.py index e303b7c..5802b0c 100644 --- a/tests/test_clusters_command.py +++ b/tests/test_clusters_command.py @@ -83,9 +83,9 @@ def test_alter_cluster_without_parameters(self, mock_os): @mock.patch("kfk.commands.clusters.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.clusters.os") + @mock.patch("kfk.commands.clusters.replace_using_yaml") def test_alter_cluster_with_one_additional_config( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/kafka-ephemeral.yaml") as file: kafka_yaml = file.read() @@ -112,11 +112,13 @@ def test_alter_cluster_with_one_additional_config( result_kafka_yaml = mock_create_temp_file.call_args[0][0] assert expected_kafka_yaml == result_kafka_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.clusters.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.clusters.os") + @mock.patch("kfk.commands.clusters.replace_using_yaml") def test_alter_cluster_with_two_additional_configs( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/kafka-ephemeral.yaml") as file: kafka_yaml = file.read() @@ -145,11 +147,13 @@ def test_alter_cluster_with_two_additional_configs( result_kafka_yaml = mock_create_temp_file.call_args[0][0] assert expected_kafka_yaml == result_kafka_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.clusters.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.clusters.os") + @mock.patch("kfk.commands.clusters.replace_using_yaml") def test_alter_cluster_with_two_additional_configs_delete_one_config( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/kafka-ephemeral_with_two_additional_configs.yaml" @@ -178,11 +182,13 @@ def test_alter_cluster_with_two_additional_configs_delete_one_config( result_kafka_yaml = mock_create_temp_file.call_args[0][0] assert expected_kafka_yaml == result_kafka_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.clusters.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.clusters.os") + @mock.patch("kfk.commands.clusters.replace_using_yaml") def test_alter_cluster_with_two_additional_configs_delete_two_configs( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/kafka-ephemeral_with_two_additional_configs.yaml" @@ -213,11 +219,13 @@ def test_alter_cluster_with_two_additional_configs_delete_two_configs( result_kafka_yaml = mock_create_temp_file.call_args[0][0] assert expected_kafka_yaml == result_kafka_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.clusters.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.clusters.os") + @mock.patch("kfk.commands.clusters.replace_using_yaml") def test_alter_cluster_with_one_replica( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/kafka-ephemeral_name_updated.yaml") as file: kafka_yaml = file.read() @@ -242,11 +250,13 @@ def test_alter_cluster_with_one_replica( result_kafka_yaml = mock_create_temp_file.call_args[0][0] assert expected_kafka_yaml == result_kafka_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.clusters.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.clusters.os") + @mock.patch("kfk.commands.clusters.replace_using_yaml") def test_alter_cluster_with_two_replicas( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/kafka-ephemeral_name_updated.yaml") as file: kafka_yaml = file.read() @@ -273,11 +283,13 @@ def test_alter_cluster_with_two_replicas( result_kafka_yaml = mock_create_temp_file.call_args[0][0] assert expected_kafka_yaml == result_kafka_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.clusters.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.clusters.os") + @mock.patch("kfk.commands.clusters.replace_using_yaml") def test_alter_cluster_with_one_replica_one_zk_replica( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/kafka-ephemeral_name_updated.yaml") as file: kafka_yaml = file.read() @@ -306,6 +318,8 @@ def test_alter_cluster_with_one_replica_one_zk_replica( result_kafka_yaml = mock_create_temp_file.call_args[0][0] assert expected_kafka_yaml == result_kafka_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.clusters.click.confirm") @mock.patch("kfk.commands.clusters.delete_using_yaml") def test_delete_cluster(self, mock_delete_using_yaml, mock_click_confirm): diff --git a/tests/test_connect_connectors_command.py b/tests/test_connect_connectors_command.py index cc29ded..2d86910 100644 --- a/tests/test_connect_connectors_command.py +++ b/tests/test_connect_connectors_command.py @@ -158,9 +158,9 @@ def test_alter_connector_without_config_file(self): @mock.patch("kfk.commands.connect.connectors.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.connect.connectors.os") + @mock.patch("kfk.commands.connect.connectors.replace_using_yaml") def test_alter_connector( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/kafka-connect-connector-twitter.yaml") as file: connector_yaml = file.read() @@ -188,3 +188,5 @@ def test_alter_connector( expected_connector_yaml = file.read() result_connector_yaml = mock_create_temp_file.call_args[0][0] assert expected_connector_yaml == result_connector_yaml + + mock_replace_using_yaml.assert_called_once() diff --git a/tests/test_users_command.py b/tests/test_users_command.py index 259b589..970829b 100644 --- a/tests/test_users_command.py +++ b/tests/test_users_command.py @@ -189,9 +189,9 @@ def test_delete_user(self, mock_delete_using_yaml): @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_with_no_params( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: expected_user_yaml = file.read() @@ -215,11 +215,13 @@ def test_alter_user_with_no_params( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_authentication( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: user_yaml = file.read() @@ -247,11 +249,13 @@ def test_alter_user_for_authentication( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_authorization( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: user_yaml = file.read() @@ -288,11 +292,13 @@ def test_alter_user_for_authorization( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_authorization_none( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: user_yaml = file.read() @@ -327,11 +333,13 @@ def test_alter_user_for_authorization_none( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_authorization_with_two_acl_operation( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: user_yaml = file.read() @@ -371,11 +379,13 @@ def test_alter_user_for_authorization_with_two_acl_operation( assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_authorization_none_with_two_acl_operation( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_two_topic_acls.yaml" @@ -415,11 +425,13 @@ def test_alter_user_for_authorization_none_with_two_acl_operation( assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_authorization_delete_acls_for_one_operation( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_three_topic_acls.yaml" @@ -459,11 +471,13 @@ def test_alter_user_for_authorization_delete_acls_for_one_operation( assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_authorization_delete_acls_for_two_operation( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open( "tests/files/yaml/user_with_authorization_with_three_topic_acls.yaml" @@ -505,11 +519,13 @@ def test_alter_user_for_authorization_delete_acls_for_two_operation( assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_quota( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: user_yaml = file.read() @@ -539,11 +555,13 @@ def test_alter_user_for_quota( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_for_two_quotas( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_authentication_tls.yaml") as file: user_yaml = file.read() @@ -575,11 +593,13 @@ def test_alter_user_for_two_quotas( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_with_two_quotas_delete_one_quota( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_two_quotas.yaml") as file: user_yaml = file.read() @@ -607,11 +627,13 @@ def test_alter_user_with_two_quotas_delete_one_quota( result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + mock_replace_using_yaml.assert_called_once() + @mock.patch("kfk.commands.users.create_temp_file") @mock.patch("kfk.commons.get_resource_yaml") - @mock.patch("kfk.commands.users.os") + @mock.patch("kfk.commands.users.replace_using_yaml") def test_alter_user_with_two_quotas_delete_two_quotas( - self, mock_os, mock_get_resource_yaml, mock_create_temp_file + self, mock_replace_using_yaml, mock_get_resource_yaml, mock_create_temp_file ): with open("tests/files/yaml/user_with_two_quotas.yaml") as file: user_yaml = file.read() @@ -640,3 +662,5 @@ def test_alter_user_with_two_quotas_delete_two_quotas( expected_user_yaml = file.read() result_user_yaml = mock_create_temp_file.call_args[0][0] assert expected_user_yaml == result_user_yaml + + mock_replace_using_yaml.assert_called_once()