Skip to content

Commit

Permalink
fix tests | fix pkg_resources issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mabulgu committed Nov 6, 2024
1 parent 25757f6 commit a3970b2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
5 changes: 3 additions & 2 deletions kfk/commands/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from importlib.metadata import version

import click
import pkg_resources

from kfk.config import KUBECTL_VERSION, STRIMZI_VERSION

version = f"""CLI Version: {pkg_resources.require("strimzi-kafka-cli")[0].version}
version = f"""CLI Version: {version("strimzi-kafka-cli")}
Strimzi Version: {STRIMZI_VERSION}
Kubectl Version: {KUBECTL_VERSION}"""

Expand Down
30 changes: 20 additions & 10 deletions tests/test_configs_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def test_add_one_topic_config(

@mock.patch("kfk.commands.topics.create_temp_file")
@mock.patch("kfk.commons.get_resource_yaml")
@mock.patch("kfk.commands.topics.os")
@mock.patch("kfk.commands.topics.replace_using_yaml")
def test_add_two_topic_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/topic_without_config.yaml") as file:
topic_yaml = file.read()
Expand Down Expand Up @@ -120,11 +120,13 @@ def test_add_two_topic_configs(
result_topic_yaml = mock_create_temp_file.call_args[0][0]
assert expected_topic_yaml == result_topic_yaml

mock_replace_using_yaml.assert_called_once()

@mock.patch("kfk.commands.topics.create_temp_file")
@mock.patch("kfk.commons.get_resource_yaml")
@mock.patch("kfk.commands.topics.os")
@mock.patch("kfk.commands.topics.replace_using_yaml")
def test_delete_one_topic_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/topic_with_two_configs.yaml") as file:
topic_yaml = file.read()
Expand Down Expand Up @@ -154,6 +156,8 @@ def test_delete_one_topic_config(
result_topic_yaml = mock_create_temp_file.call_args[0][0]
assert expected_topic_yaml == result_topic_yaml

mock_replace_using_yaml.assert_called_once()

@mock.patch("kfk.commands.topics.os")
def test_describe_topic_config(self, mock_os):
result = self.runner.invoke(
Expand Down Expand Up @@ -216,9 +220,9 @@ def test_describe_topic_config_native(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_one_user_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/user_with_authentication_scram.yaml") as file:
user_yaml = file.read()
Expand Down Expand Up @@ -248,11 +252,13 @@ def test_add_one_user_config(
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_two_user_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/user_with_authentication_scram.yaml") as file:
user_yaml = file.read()
Expand Down Expand Up @@ -282,11 +288,13 @@ def test_add_two_user_configs(
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_delete_one_user_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/user_with_two_quotas.yaml") as file:
user_yaml = file.read()
Expand Down Expand Up @@ -316,6 +324,8 @@ def test_delete_one_user_config(
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.os")
def test_describe_user_config(self, mock_os):
result = self.runner.invoke(
Expand Down
18 changes: 12 additions & 6 deletions tests/test_connect_clusters_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ def test_alter_cluster_without_parameters(self, mock_os):

@mock.patch("kfk.commands.connect.clusters.create_temp_file")
@mock.patch("kfk.commons.get_resource_yaml")
@mock.patch("kfk.commands.connect.clusters.os")
@mock.patch("kfk.commands.connect.clusters.replace_using_yaml")
def test_alter_cluster_with_replica_param(
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.yaml") as file:
connect_yaml = file.read()
Expand Down Expand Up @@ -575,11 +575,13 @@ def test_alter_cluster_with_replica_param(
result_connect_yaml = mock_create_temp_file.call_args[0][0]
assert expected_connect_yaml == result_connect_yaml

mock_replace_using_yaml.assert_called_once()

@mock.patch("kfk.commands.connect.clusters.create_temp_file")
@mock.patch("kfk.commons.get_resource_yaml")
@mock.patch("kfk.commands.connect.clusters.os")
@mock.patch("kfk.commands.connect.clusters.replace_using_yaml")
def test_alter_cluster_with_different_config_file(
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.yaml") as file:
connect_yaml = file.read()
Expand Down Expand Up @@ -607,11 +609,13 @@ def test_alter_cluster_with_different_config_file(
result_connect_yaml = mock_create_temp_file.call_args[0][0]
assert expected_connect_yaml == result_connect_yaml

mock_replace_using_yaml.assert_called_once()

@mock.patch("kfk.commands.connect.clusters.create_temp_file")
@mock.patch("kfk.commons.get_resource_yaml")
@mock.patch("kfk.commands.connect.clusters.os")
@mock.patch("kfk.commands.connect.clusters.replace_using_yaml")
def test_alter_cluster_with_only_image_config_file(
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.yaml") as file:
connect_yaml = file.read()
Expand All @@ -636,3 +640,5 @@ def test_alter_cluster_with_only_image_config_file(
expected_connect_yaml = file.read()
result_connect_yaml = mock_create_temp_file.call_args[0][0]
assert expected_connect_yaml == result_connect_yaml

mock_replace_using_yaml.assert_called_once()
4 changes: 2 additions & 2 deletions tests/test_kfk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from importlib.metadata import version
from unittest import TestCase, mock

import pkg_resources
from click.testing import CliRunner

from kfk.config import KUBECTL_VERSION, STRIMZI_VERSION
Expand All @@ -24,7 +24,7 @@ def test_kfk_version(self, mock_setup):

result = self.runner.invoke(kfk, ["--version"])
assert result.exit_code == 0
cli_version = pkg_resources.require("strimzi-kafka-cli")[0].version
cli_version = version("strimzi-kafka-cli")
expected_version = f"""CLI Version: {cli_version}
Strimzi Version: {STRIMZI_VERSION}
Kubectl Version: {KUBECTL_VERSION}
Expand Down

0 comments on commit a3970b2

Please sign in to comment.