Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mabulgu committed Aug 31, 2024
1 parent e189690 commit efc1516
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 52 deletions.
36 changes: 24 additions & 12 deletions tests/test_acls_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()
42 changes: 28 additions & 14 deletions tests/test_clusters_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_connect_connectors_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Loading

0 comments on commit efc1516

Please sign in to comment.