-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make required changes in README file and unit tests
- Loading branch information
taleksovska
committed
Apr 9, 2024
1 parent
db96a6c
commit 1582364
Showing
5 changed files
with
78 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,59 @@ | ||
import unittest | ||
import tempfile | ||
import shutil | ||
from click.testing import CliRunner | ||
from unittest.mock import MagicMock, patch | ||
from enabler.commands.cmd_platform import cli as CLI | ||
from unittest.mock import patch | ||
from git import Repo | ||
from enabler.cli import cli as CLI | ||
import os | ||
|
||
|
||
class TestPlatformCommands(unittest.TestCase): | ||
def setUp(self): | ||
self.runner = CliRunner() | ||
self.temp_dir = tempfile.mkdtemp() | ||
|
||
@patch('enabler.commands.cmd_platform.get_submodules') | ||
@patch('enabler.commands.cmd_platform.get_repo') | ||
def test_platform_init_command(self, mock_get_repo, mock_get_submodules): | ||
mock_repo = MagicMock() | ||
mock_get_repo.return_value = mock_repo | ||
mock_get_submodules.return_value = ['submodule1', 'submodule2'] | ||
with patch('enabler.commands.cmd_platform.click_spinner.spinner'): | ||
result = self.runner.invoke(CLI, ['platform', 'init', 'all']) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertIn('Platform initialized.', result.output) | ||
# Create a temporary Git repository | ||
self.repo = Repo.init(self.temp_dir) | ||
self.repo.git.config('--local', 'user.email', 'test@example.com') | ||
self.repo.git.config('--local', 'user.name', 'Test') | ||
|
||
def tearDown(self): | ||
# Clean up the temporary directory after the test | ||
shutil.rmtree(self.temp_dir) | ||
|
||
@patch('enabler.commands.cmd_platform.s') | ||
def test_platform_init(self, mock_s): | ||
mock_s.run.return_value.returncode = 0 | ||
result = self.runner.invoke(CLI, ['platform', 'init', 'all', self.temp_dir]) # noqa | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
@patch('enabler.commands.cmd_platform.s') | ||
def test_platform_info_command(self, mock_s): | ||
mock_s.run.side_effect = [ | ||
MagicMock(), | ||
MagicMock(), | ||
] | ||
result = self.runner.invoke(CLI, ['platform', 'info', '--kube-context', 'test-context']) # noqa | ||
def test_platform_info(self, mock_s): | ||
mock_s.run.return_value.returncode = 0 | ||
result = self.runner.invoke(CLI, ['platform', 'info', '--kube-context', '']) # noqa | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertIn('Platform can be accessed through the URL:', result.output) # noqa | ||
|
||
@patch('enabler.commands.cmd_platform.os.path.exists') | ||
@patch('enabler.commands.cmd_platform.rsa.generate_private_key') | ||
def test_platform_keys_command(self, mock_generate_private_key, mock_path_exists): # noqa | ||
mock_generate_private_key.return_value = MagicMock() | ||
mock_path_exists.return_value = False | ||
result = self.runner.invoke(CLI, ['platform', 'keys', '2048']) | ||
|
||
@patch('enabler.commands.cmd_platform.click.confirm') | ||
@patch('enabler.commands.cmd_platform.s') | ||
def test_platform_keys(self, mock_s, mock_confirm): | ||
mock_s.run.return_value.returncode = 1 | ||
mock_confirm.return_value = False | ||
result = self.runner.invoke(CLI, ['platform', 'keys']) | ||
self.assertEqual(result.exit_code, 1) | ||
|
||
@patch('enabler.commands.cmd_platform.s') | ||
def test_platform_release(self, mock_s): | ||
mock_s.run.return_value.returncode = 0 | ||
simulated_path = 'platform/microservice' | ||
# Create the simulated path if it doesn't exist | ||
if not os.path.exists(simulated_path): | ||
os.makedirs(simulated_path) | ||
result = self.runner.invoke(CLI, ['platform', 'release', '2.1.7', simulated_path]) # noqa | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
@patch('enabler.commands.cmd_platform.s') | ||
def test_platform_version(self, mock_s): | ||
mock_s.run.return_value.returncode = 0 | ||
result = self.runner.invoke(CLI, ['platform', 'version']) | ||
self.assertEqual(result.exit_code, 0) | ||
self.assertIn('Keys generated successfully.', result.output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters