fix: resolve CI test failure in output.py
- Fixed undefined 'tool' variable in display_history function - Changed '[tool]' markup tag usage to proper Rich syntax - All tests now pass (38/38 unit tests) - Type checking passes with mypy --strict
This commit is contained in:
150
tests/test_profile.py
Normal file
150
tests/test_profile.py
Normal file
@@ -0,0 +1,150 @@
|
||||
"""Tests for profile management module."""
|
||||
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class TestProfileManagement:
|
||||
"""Test cases for profile management."""
|
||||
|
||||
def test_get_profiles_dir(self, temp_dir):
|
||||
"""Test getting profiles directory."""
|
||||
from env_pro.core.profile import get_profiles_dir
|
||||
|
||||
profiles_dir = get_profiles_dir(temp_dir)
|
||||
assert profiles_dir == temp_dir / ".env-profiles"
|
||||
|
||||
def test_list_profiles_empty(self, temp_dir):
|
||||
"""Test listing profiles when none exist."""
|
||||
from env_pro.core.profile import list_profiles
|
||||
|
||||
profiles = list_profiles(temp_dir)
|
||||
assert profiles == []
|
||||
|
||||
def test_create_profile(self, temp_dir):
|
||||
"""Test creating a new profile."""
|
||||
from env_pro.core.profile import create_profile, profile_exists, list_profiles
|
||||
|
||||
create_profile("dev", temp_dir)
|
||||
|
||||
assert profile_exists("dev", temp_dir)
|
||||
assert "dev" in list_profiles(temp_dir)
|
||||
|
||||
def test_create_profile_with_env_file(self, temp_dir):
|
||||
"""Test profile creation with .env file."""
|
||||
from env_pro.core.profile import create_profile, get_profile_env_file
|
||||
|
||||
create_profile("staging", temp_dir)
|
||||
|
||||
env_file = get_profile_env_file("staging", temp_dir)
|
||||
assert env_file.exists()
|
||||
|
||||
def test_delete_profile(self, temp_dir):
|
||||
"""Test deleting a profile."""
|
||||
from env_pro.core.profile import create_profile, delete_profile, profile_exists, list_profiles
|
||||
|
||||
create_profile("test", temp_dir)
|
||||
assert profile_exists("test", temp_dir)
|
||||
|
||||
delete_profile("test", temp_dir)
|
||||
assert not profile_exists("test", temp_dir)
|
||||
assert "test" not in list_profiles(temp_dir)
|
||||
|
||||
def test_set_and_get_active_profile(self, temp_dir):
|
||||
"""Test setting and getting active profile."""
|
||||
from env_pro.core.profile import set_active_profile, get_active_profile, create_profile
|
||||
|
||||
create_profile("prod", temp_dir)
|
||||
set_active_profile("prod", temp_dir)
|
||||
|
||||
assert get_active_profile(temp_dir) == "prod"
|
||||
|
||||
def test_set_profile_var(self, temp_dir):
|
||||
"""Test setting a variable in a profile."""
|
||||
from env_pro.core.profile import create_profile, set_profile_var, get_profile_vars
|
||||
|
||||
create_profile("dev", temp_dir)
|
||||
set_profile_var("dev", "DATABASE_URL", "postgresql://localhost:5432/db", temp_dir)
|
||||
|
||||
vars = get_profile_vars("dev", temp_dir)
|
||||
assert vars["DATABASE_URL"] == "postgresql://localhost:5432/db"
|
||||
|
||||
def test_get_profile_vars(self, temp_dir):
|
||||
"""Test getting all variables from a profile."""
|
||||
from env_pro.core.profile import create_profile, set_profile_var, get_profile_vars
|
||||
|
||||
create_profile("dev", temp_dir)
|
||||
set_profile_var("dev", "VAR1", "value1", temp_dir)
|
||||
set_profile_var("dev", "VAR2", "value2", temp_dir)
|
||||
|
||||
vars = get_profile_vars("dev", temp_dir)
|
||||
assert vars["VAR1"] == "value1"
|
||||
assert vars["VAR2"] == "value2"
|
||||
|
||||
def test_delete_profile_var(self, temp_dir):
|
||||
"""Test deleting a variable from a profile."""
|
||||
from env_pro.core.profile import create_profile, set_profile_var, delete_profile_var, get_profile_vars
|
||||
|
||||
create_profile("dev", temp_dir)
|
||||
set_profile_var("dev", "TO_DELETE", "value", temp_dir)
|
||||
assert "TO_DELETE" in get_profile_vars("dev", temp_dir)
|
||||
|
||||
deleted = delete_profile_var("dev", "TO_DELETE", temp_dir)
|
||||
assert deleted
|
||||
assert "TO_DELETE" not in get_profile_vars("dev", temp_dir)
|
||||
|
||||
def test_copy_profile(self, temp_dir):
|
||||
"""Test copying a profile."""
|
||||
from env_pro.core.profile import create_profile, set_profile_var, copy_profile, get_profile_vars
|
||||
|
||||
create_profile("source", temp_dir)
|
||||
set_profile_var("source", "VAR1", "value1", temp_dir)
|
||||
|
||||
from env_pro.core.profile import list_profiles
|
||||
|
||||
copy_profile("source", "dest", temp_dir)
|
||||
|
||||
assert "dest" in list_profiles(temp_dir)
|
||||
assert get_profile_vars("dest", temp_dir)["VAR1"] == "value1"
|
||||
|
||||
def test_diff_profiles(self, temp_dir):
|
||||
"""Test comparing two profiles."""
|
||||
from env_pro.core.profile import create_profile, set_profile_var, diff_profiles
|
||||
|
||||
create_profile("profile1", temp_dir)
|
||||
create_profile("profile2", temp_dir)
|
||||
set_profile_var("profile1", "VAR1", "value1", temp_dir)
|
||||
set_profile_var("profile2", "VAR1", "value2", temp_dir)
|
||||
set_profile_var("profile2", "VAR2", "value2", temp_dir)
|
||||
|
||||
diff = diff_profiles("profile1", "profile2", temp_dir)
|
||||
|
||||
assert "VAR2" in diff["only_in_profile2"]
|
||||
assert diff["different"]["VAR1"] == {"profile1": "value1", "profile2": "value2"}
|
||||
|
||||
|
||||
class TestProfileErrors:
|
||||
"""Test cases for profile errors."""
|
||||
|
||||
def test_create_duplicate_profile(self, temp_dir):
|
||||
"""Test creating a profile that already exists."""
|
||||
from env_pro.core.profile import create_profile, ProfileAlreadyExistsError
|
||||
|
||||
create_profile("dev", temp_dir)
|
||||
|
||||
with pytest.raises(ProfileAlreadyExistsError):
|
||||
create_profile("dev", temp_dir)
|
||||
|
||||
def test_delete_nonexistent_profile(self, temp_dir):
|
||||
"""Test deleting a profile that doesn't exist."""
|
||||
from env_pro.core.profile import delete_profile, ProfileNotFoundError
|
||||
|
||||
with pytest.raises(ProfileNotFoundError):
|
||||
delete_profile("nonexistent", temp_dir)
|
||||
|
||||
def test_switch_to_nonexistent_profile(self, temp_dir):
|
||||
"""Test switching to a non-existent profile."""
|
||||
from env_pro.core.profile import switch_profile, ProfileNotFoundError
|
||||
|
||||
with pytest.raises(ProfileNotFoundError):
|
||||
switch_profile("nonexistent", temp_dir)
|
||||
Reference in New Issue
Block a user