51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# tests/test_init.py
|
|
import os
|
|
import unittest
|
|
from unittest.mock import patch
|
|
from argparse import Namespace # Import Namespace for creating args object
|
|
from tenant.commands import init
|
|
|
|
|
|
class TestInitCommand(unittest.TestCase):
|
|
def setUp(self):
|
|
# Set up any necessary configurations or resources
|
|
pass
|
|
|
|
def tearDown(self):
|
|
# Clean up after the test
|
|
pass
|
|
|
|
@patch("tenant.commands.init.get_secure_password", return_value="mocked_password")
|
|
def test_init_command(self, mock_input):
|
|
tenant_name = "test-tenant"
|
|
target_directory = "/tmp/test"
|
|
|
|
# Ensure the tenant directory doesn't exist before running the test
|
|
tenant_directory = os.path.join(target_directory, "tenants", tenant_name)
|
|
if os.path.exists(tenant_directory):
|
|
os.rmdir(tenant_directory)
|
|
|
|
# Create an args object
|
|
args = Namespace(
|
|
command="init", tenant_name=tenant_name, target=target_directory
|
|
)
|
|
|
|
# Call the init command with the args object
|
|
init.execute(args)
|
|
|
|
# Verify that the tenant directory has been created
|
|
self.assertTrue(os.path.exists(tenant_directory))
|
|
self.assertTrue(os.path.exists(os.path.join(tenant_directory, "terraform")))
|
|
self.assertTrue(os.path.exists(os.path.join(tenant_directory, "kubernetes")))
|
|
self.assertTrue(os.path.exists(os.path.join(tenant_directory, "certificates")))
|
|
|
|
# Clean up: Remove the created tenant directory
|
|
os.rmdir(os.path.join(tenant_directory, "terraform"))
|
|
os.rmdir(os.path.join(tenant_directory, "kubernetes"))
|
|
os.rmdir(os.path.join(tenant_directory, "certificates"))
|
|
os.rmdir(tenant_directory)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|