<NME> test_extensions.py
<BEF> ADDFILE
<MSG> Merge pull request #950 from tonioo/tests/extensions

Tests: Extensions
<DFF> @@ -0,0 +1,73 @@
+"""Extensions management related test cases."""
+
+import os
+import sys
+
+from testfixtures import compare
+
+from django.core import management
+from django.test import TestCase, override_settings
+
+from .. import extensions
+
+sys.path.append(os.path.dirname(__file__))
+
+CUSTOM_APPS = (
+    "modoboa",
+    "modoboa.core",
+    "modoboa.lib",
+    "modoboa.admin",
+    "modoboa.limits",
+    "modoboa.relaydomains",
+    "stupid_extension_1",
+    "stupid_extension_2",
+)
+
+
+class ExtensionTestCase(TestCase):
+    """Extensions related tests."""
+
+    @classmethod
+    def setUpClass(cls):
+        """Initiate test context."""
+        cls.pool = extensions.exts_pool
+        with override_settings(MODOBOA_APPS=CUSTOM_APPS):
+            cls.pool.load_all()
+
+    @classmethod
+    def tearDownClass(cls):
+        """Reset context."""
+        del cls.pool.extensions["stupid_extension_1"]
+        del cls.pool.extensions["stupid_extension_2"]
+
+    def test_register(self):
+        """Test if registering works."""
+        self.assertIn("stupid_extension_1", self.pool.extensions)
+
+    def test_get_extension(self):
+        """Check getter method."""
+        self.assertIsNone(self.pool.get_extension("toto"))
+        instance = self.pool.get_extension("stupid_extension_1")
+        self.assertEqual(instance.__class__.__name__, "StupidExtension1")
+
+    def test_get_extension_infos(self):
+        """Check getter method."""
+        self.assertIsNone(self.pool.get_extension_infos("toto"))
+        infos = self.pool.get_extension_infos("stupid_extension_1")
+        compare(infos, {
+            "name": "stupid_extension_1", "label": "Stupid extension",
+            "version": "1.0.0", "description": "A stupid extension",
+            "url": None, "always_active": False
+        })
+
+    def test_list_all(self):
+        """Check list_all method."""
+        result = self.pool.list_all()
+        self.assertEqual(len(result), 1)
+        ext = result[0]
+        self.assertEqual(ext["id"], "stupid_extension_1")
+
+    def test_load_initial_data(self):
+        """Check if method is called."""
+        with self.assertRaises(RuntimeError):
+            management.call_command("load_initial_data")

Merge pull request #950 from tonioo/tests/extensions