# -*- coding: utf-8 -*- """Tests for compositor.app model.""" from odoo.exceptions import ValidationError, AccessError from odoo.tests import common, tagged @tagged("post_install", "-at_install") class TestCompositorApp(common.TransactionCase): def setUp(self): super().setUp() self.App = self.env["compositor.app"] self.group_user = self.env.ref("base.group_user") self.group_manager = self.env.ref("one_os_compositor.compositor_group_manager") def test_create_app_minimal(self): app = self.App.create({ "name": "Test App", "app_id": "test-app", "executable": "/bin/true", }) self.assertEqual(app.memory_limit_mb, 1024) self.assertEqual(app.cpu_quota_percent, 200) self.assertEqual(app.tasks_max, 256) self.assertTrue(app.sandbox_gpu) self.assertFalse(app.sandbox_network) def test_app_id_unique(self): self.App.create({"name": "App 1", "app_id": "duplicate", "executable": "/bin/true"}) with self.assertRaises(ValidationError): self.App.create({"name": "App 2", "app_id": "duplicate", "executable": "/bin/true"}) def test_memory_limit_too_low(self): with self.assertRaises(ValidationError): self.App.create({ "name": "Bad App", "app_id": "bad-app", "executable": "/bin/true", "memory_limit_mb": 32, }) def test_get_launch_config(self): app = self.App.create({ "name": "Test", "app_id": "test", "executable": "/usr/bin/test", "args": "--foo --bar", "env_vars": "GDK_SCALE=1\n# comment\nGTK_DEBUG=all", "memory_limit_mb": 512, "cpu_quota_percent": 100, "tasks_max": 64, "sandbox_network": True, "sandbox_gpu": False, }) config = app.get_launch_config() self.assertEqual(config["app_id"], "test") self.assertEqual(config["executable"], "/usr/bin/test") self.assertEqual(config["args"], "--foo --bar") self.assertEqual(config["env"], {"GDK_SCALE": "1", "GTK_DEBUG": "all"}) self.assertEqual(config["memory_limit_mb"], 512) self.assertTrue(config["sandbox_network"]) self.assertFalse(config["sandbox_gpu"])