import json import os import tempfile import unittest from linux_backuper.core.profiles import ProfileManager from linux_backuper.models import ProfileConfig class TestProfileManager(unittest.TestCase): def setUp(self): self.temp_dir = tempfile.mkdtemp(prefix="test_profiles_") def tearDown(self): import shutil shutil.rmtree(self.temp_dir, ignore_errors=True) def test_builtin_profiles_exist(self): mgr = ProfileManager() profiles = mgr.list_profiles() names = [p.name for p in profiles] self.assertIn("quick", names) self.assertIn("system", names) self.assertIn("full", names) def test_quick_profile_paths(self): mgr = ProfileManager() quick = mgr.get_profile("quick") self.assertEqual(quick.name, "quick") self.assertIn("/etc", quick.included_paths) self.assertNotIn("/boot", quick.included_paths) def test_system_profile_paths(self): mgr = ProfileManager() system = mgr.get_profile("system") self.assertIn("/etc", system.included_paths) self.assertIn("/boot", system.included_paths) def test_full_profile_paths(self): mgr = ProfileManager() full = mgr.get_profile("full") self.assertIn("/etc", full.included_paths) self.assertIn("/boot", full.included_paths) self.assertIn("/var/spool/cron", full.included_paths) self.assertIn("/var/lib/systemd", full.included_paths) def test_custom_profile_from_config(self): config_path = os.path.join(self.temp_dir, "linux-backuper.json") custom_data = { "profiles": { "custom_web": { "description": "Web server custom profile", "included_paths": ["/etc", "/var/www/html"], "exclude_patterns": ["*.log", "*.tmp"], "collect_packages": True } } } with open(config_path, "w") as f: json.dump(custom_data, f) mgr = ProfileManager(config_path=config_path) p = mgr.get_profile("custom_web") self.assertEqual(p.name, "custom_web") self.assertIn("/var/www/html", p.included_paths) self.assertIn("*.log", p.exclude_patterns) def test_unknown_profile_raises_key_error(self): mgr = ProfileManager() with self.assertRaises(KeyError): mgr.get_profile("non_existent_profile_xyz") if __name__ == "__main__": unittest.main()