Beispiel #1
0
    def test_invalid_project_name(self):
        #with patch('sys.stdout', self.stdout):
            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'test'])
            self.assertTrue(stderr_tmp.getvalue().find("Project name 'test' is not valid") > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'assert'])
            self.assertTrue(stderr_tmp.getvalue().find("Project name 'assert' is not valid") > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'values'])
            self.assertTrue(stderr_tmp.getvalue().find("Project name 'values' is not valid") > -1)
    def test_invalid_project_name(self):
        with patch("sys.stdout", self.stdout):
            stderr_tmp = StringIO()
            with patch("sys.stderr", stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse(
                        ["-q", "--db=postgres://user:pwd@host/dbname", "-p" + self.project_dir, "test"]
                    )
            self.assertTrue(stderr_tmp.getvalue().find('Project name "test" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch("sys.stderr", stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse(
                        ["-q", "--db=postgres://user:pwd@host/dbname", "-p" + self.project_dir, "assert"]
                    )
            self.assertTrue(stderr_tmp.getvalue().find('Project name "assert" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch("sys.stderr", stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse(
                        ["-q", "--db=postgres://user:pwd@host/dbname", "-p" + self.project_dir, "values"]
                    )
            self.assertTrue(stderr_tmp.getvalue().find('Project name "values" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch("sys.stderr", stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse(
                        ["-q", "--db=postgres://user:pwd@host/dbname", "-p" + self.project_dir, "project-name"]
                    )
            self.assertTrue(stderr_tmp.getvalue().find('Project name "project-name" is not a valid app name') > -1)
    def test_requirements(self):
        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '--django-version=1.4',
            '--i18n=no',
            '-f',
            '-p'+self.project_dir,
            'example_prj'])

        self.assertTrue(conf_data.requirements.find('django-cms<2.5') > -1)
        self.assertTrue(conf_data.requirements.find('Django<1.5') > -1)
        self.assertTrue(conf_data.requirements.find('django-filer') > -1)
        self.assertTrue(conf_data.requirements.find('cmsplugin_filer') > -1)
        self.assertTrue(conf_data.requirements.find('django-reversion<1.7') > -1)
        self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor') == -1)

        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '--i18n=no',
            '--cms-version=stable',
            '--django-version=stable',
            '-f',
            '-p'+self.project_dir,
            'example_prj'])

        self.assertTrue(conf_data.requirements.find('django-cms<2.5') > -1)
        self.assertTrue(conf_data.requirements.find('Django<1.6') > -1)
        self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor') == -1)
        self.assertTrue(conf_data.requirements.find('djangocms-admin-style') == -1)
        self.assertTrue(conf_data.requirements.find('django-reversion>=1.7') > -1)

        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '--i18n=no',
            '--cms-version=beta',
            '-f',
            '-p'+self.project_dir,
            'example_prj'])

        self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_BETA) > -1)

        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '--i18n=no',
            '--cms-version=develop',
            '-f',
            '-z=yes',
            '-p'+self.project_dir,
            'example_prj'])

        self.assertTrue(conf_data.requirements.find(config.data.DJANGOCMS_DEVELOP) > -1)
        self.assertTrue(conf_data.requirements.find('djangocms-text-ckeditor') > -1)
        self.assertTrue(conf_data.requirements.find('djangocms-admin-style') > -1)
        self.assertTrue(conf_data.requirements.find('pytz') > -1)
Beispiel #4
0
    def test_cli_config(self):
        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '--cms-version=stable',
            '--django-version=1.7',
            '--i18n=no',
            '--reversion=no',
            '--permissions=no',
            '--use-tz=no',
            '-tEurope/Rome',
            '-len', '-lde', '-lit',
            '-p'+self.project_dir,
            'example_prj'])

        self.assertEqual(conf_data.project_name, 'example_prj')

        self.assertEqual(conf_data.cms_version, 3.1)
        self.assertEqual(conf_data.django_version, 1.7)
        self.assertEqual(conf_data.i18n, 'no')
        self.assertEqual(conf_data.reversion, 'no')
        self.assertEqual(conf_data.permissions, 'no')
        self.assertEqual(conf_data.use_timezone, 'no')
        self.assertEqual(conf_data.timezone, 'Europe/Rome')
        self.assertEqual(conf_data.languages, ['en', 'de', 'it'])
        self.assertEqual(conf_data.project_directory, self.project_dir)
        self.assertEqual(conf_data.db, 'postgres://*****:*****@host/dbname')
        self.assertEqual(conf_data.db_driver, 'psycopg2')

        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '--cms-version=stable',
            '--django-version=1.4',
            '--cms-version=3.0',
            '--i18n=no',
            '--reversion=no',
            '--permissions=no',
            '--use-tz=no',
            '-tEurope/Rome',
            '-len', '-lde', '-lit',
            '-p'+self.project_dir,
            'example_prj'])

        self.assertEqual(conf_data.project_name, 'example_prj')

        self.assertEqual(conf_data.cms_version, 3.0)
        self.assertEqual(conf_data.django_version, 1.4)
        self.assertEqual(conf_data.i18n, 'no')
        self.assertEqual(conf_data.reversion, 'no')
        self.assertEqual(conf_data.permissions, 'no')
        self.assertEqual(conf_data.use_timezone, 'no')
        self.assertEqual(conf_data.timezone, 'Europe/Rome')
        self.assertEqual(conf_data.languages, ['en', 'de', 'it'])
        self.assertEqual(conf_data.project_directory, self.project_dir)
        self.assertEqual(conf_data.db, 'postgres://*****:*****@host/dbname')
        self.assertEqual(conf_data.db_driver, 'psycopg2')
    def test_starting_page(self):
        """
        Verify handling of starting-page parameter
        """
        conf_data = config.parse(["-q", "-p" + self.project_dir, "example_prj"])
        self.assertFalse(conf_data.starting_page)

        conf_data = config.parse(["--starting-page=yes", "-q", "-p" + self.project_dir, "example_prj"])
        self.assertTrue(conf_data.starting_page)
    def test_boostrap(self):
        """
        Verify handling of bootstrap parameter
        """
        conf_data = config.parse(["-q", "-p" + self.project_dir, "example_prj"])
        self.assertFalse(conf_data.bootstrap)

        conf_data = config.parse(["--bootstrap=yes", "-q", "-p" + self.project_dir, "example_prj"])
        self.assertTrue(conf_data.bootstrap)
    def suspend_test_check_install(self):
        import pip

        # discard the argparser errors
        with patch("sys.stdout", self.stdout):
            with patch("sys.stderr", self.stderr):
                # clean the virtualenv
                try:
                    pip.main(["uninstall", "-y", "psycopg2"])
                except pip.exceptions.UninstallationError:
                    ## package not installed, all is fine
                    pass
                try:
                    pip.main(["uninstall", "-y", "pillow"])
                except pip.exceptions.UninstallationError:
                    ## package not installed, all is fine
                    pass
                try:
                    pip.main(["uninstall", "-y", "mysql-python"])
                except pip.exceptions.UninstallationError:
                    ## package not installed, all is fine
                    pass

                # Check postgres / pillow
                conf_data = config.parse(
                    [
                        "-q",
                        "--db=postgres://user:pwd@host/dbname",
                        "--django-version=1.4",
                        "--i18n=no",
                        "-f",
                        "-p" + self.project_dir,
                        "example_prj",
                    ]
                )
                with self.assertRaises(EnvironmentError) as context_error:
                    check_install(conf_data)
                self.assertTrue(str(context_error.exception).find("Pillow is not installed") > -1)
                self.assertTrue(str(context_error.exception).find("PostgreSQL driver is not installed") > -1)

                # Check mysql
                conf_data = config.parse(
                    [
                        "-q",
                        "--db=mysql://user:pwd@host/dbname",
                        "--django-version=1.4",
                        "--i18n=no",
                        "-f",
                        "-p" + self.project_dir,
                        "example_prj",
                    ]
                )
                with self.assertRaises(EnvironmentError) as context_error:
                    check_install(conf_data)
                self.assertTrue(str(context_error.exception).find("MySQL driver is not installed") > -1)
Beispiel #8
0
    def test_parse_config_file(self, *args):
        """Tests .config.__init__._parse_config_file function."""
        with self.assertRaises(SystemExit) as error:
            config.parse(self.args[0:1] + [self.conf('config-not-exists.ini')] + self.args[1:])
            self.assertEqual(7, error.exception.code)

        args = self.args[0:1] + [self.conf('config-01.ini')] + self.args[1:]
        config_data = config.parse(args)
        self.unused(config_data)
        self.assertEqual(self.config_fixture, config_data)

        test_data = [
            ('config-02.ini', 'db', 'postgres://*****:*****@host:54321/dbname'),
            ('config-03.ini', 'i18n', 'no'),
            ('config-04.ini', 'use_timezone', 'no'),
            ('config-05.ini', 'timezone', 'Europe/London'),
            ('config-06.ini', 'reversion', 'no'),
            ('config-07.ini', 'permissions', 'no'),
            ('config-08.ini', None, (('i18n', 'no'), ('languages', ['ru']))),
            ('config-09.ini', None, (('i18n', 'yes'), ('languages', ['en', 'ru']))),
            ('config-10.ini', 'django_version', 1.8),
            ('config-11.ini', 'project_directory', '/test/me'),
            ('config-12.ini', 'bootstrap', True),
            ('config-13.ini', 'templates', '.'),
            ('config-14.ini', 'starting_page', True),
            ('config-15.ini', 'plugins', True),
            ('config-16.ini', 'dump_reqs', True),
            ('config-17.ini', 'noinput', True),
            ('config-18.ini', 'filer', True),
            ('config-19.ini', 'requirements_file', '/test/reqs'),
            ('config-20.ini', 'no_deps', True),
            ('config-21.ini', 'no_db_driver', True),
            ('config-22.ini', 'no_sync', True),
            ('config-23.ini', 'no_user', True),
            ('config-24.ini', 'template', '/test/template'),
            ('config-25.ini', 'extra_settings', '/test/extra_settings'),
            ('config-26.ini', 'skip_project_dir_check', True),
            ('config-27.ini', 'utc', True),
            ('config-28.ini', 'no_plugins', True),
            ('config-29.ini', 'apphooks_reload', True),
            ('config-30.ini', 'verbose', True),
        ]
        fixture = copy.copy(self.config_fixture)
        if sys.version_info < (2, 7):
            test_data[8] = ('config-10b.ini', 'django_version', 1.6)
        for filename, key, val in test_data:
            if type(val) == tuple:
                for subkey, subval in val:
                    setattr(fixture, subkey, subval)  # Change value.
            else:
                setattr(fixture, key, val)  # Change value.
            args = self.args[0:1] + [self.conf(filename)] + self.args[1:]  # Load new config.
            config_data = config.parse(args)
            self.unused(config_data)
            self.assertEqual(fixture, config_data)  # Check if config value and changed value equals.
    def test_templates(self):
        """
        Verify handling of valid (existing) and invalid (non-existing) templates directory parameter
        """
        conf_data = config.parse(["--templates=/foo/bar", "-q", "-p" + self.project_dir, "example_prj"])
        self.assertFalse(conf_data.templates)

        tpl_path = os.path.join(os.path.dirname(__file__), "test_templates")

        conf_data = config.parse(["--templates=%s" % tpl_path, "-q", "-p" + self.project_dir, "example_prj"])
        self.assertEqual(conf_data.templates, tpl_path)
    def test_utc(self):
        """
        Verify handling UTC default
        """
        default_tz = get_localzone()

        conf_data = config.parse(["-q", "-p" + self.project_dir, "example_prj"])
        self.assertEqual(text_type(conf_data.timezone), default_tz.zone)

        conf_data = config.parse(["-q", "--utc", "-p" + self.project_dir, "example_prj"])
        self.assertEqual(conf_data.timezone, "UTC")
    def test_parse_config_file(self, *args):
        """Tests .config.__init__._parse_config_file function."""
        with self.assertRaises(SystemExit) as error:
            config.parse(self.args[0:1] + [self.conf("config-not-exists.ini")] + self.args[1:])
            self.assertEqual(7, error.exception.code)

        args = self.args[0:1] + [self.conf("config-01.ini")] + self.args[1:]
        config_data = config.parse(args)
        self.unused(config_data)
        self.assertEqual(self.config_fixture, config_data)

        fixture = copy.copy(self.config_fixture)
        test_data = [
            ("config-02.ini", "db", "postgres://*****:*****@host:54321/dbname"),
            ("config-03.ini", "i18n", "no"),
            ("config-04.ini", "use_timezone", "no"),
            ("config-05.ini", "timezone", "Europe/London"),
            ("config-06.ini", "reversion", "no"),
            ("config-07.ini", "permissions", "no"),
            ("config-08.ini", "languages", ["en", "ru"]),
            ("config-09.ini", "django_version", 1.8),
            ("config-10.ini", "i18n", "no"),
            ("config-11.ini", "project_directory", "/test/me"),
            ("config-12.ini", "bootstrap", True),
            ("config-13.ini", "templates", "."),
            ("config-14.ini", "starting_page", True),
            ("config-15.ini", "plugins", True),
            ("config-16.ini", "dump_reqs", True),
            ("config-17.ini", "noinput", True),
            ("config-18.ini", "filer", True),
            ("config-19.ini", "requirements_file", "/test/reqs"),
            ("config-20.ini", "no_deps", True),
            ("config-21.ini", "no_db_driver", True),
            ("config-22.ini", "no_sync", True),
            ("config-23.ini", "no_user", True),
            ("config-24.ini", "template", "/test/template"),
            ("config-25.ini", "extra_settings", "/test/extra_settings"),
            ("config-26.ini", "skip_project_dir_check", True),
            ("config-27.ini", "utc", True),
            ("config-28.ini", "no_plugins", True),
            ("config-29.ini", "apphooks_reload", True),
            ("config-30.ini", "verbose", True),
        ]
        if sys.version_info < (2, 7):
            test_data[7] = ("config-09b.ini", "django_version", 1.6)
        for filename, key, val in test_data:
            setattr(fixture, key, val)  # Change value.
            args = self.args[0:1] + [self.conf(filename)] + self.args[1:]  # Load new config.
            config_data = config.parse(args)
            self.unused(config_data)
            self.assertEqual(fixture, config_data)  # Check if config value and changed value equals.
Beispiel #12
0
    def test_starting_page(self):
        """
        Verify handling of starting-page parameter
        """
        conf_data = config.parse([
            '-q',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertFalse(conf_data.starting_page)

        conf_data = config.parse([
            '--starting-page=yes', '-q',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertTrue(conf_data.starting_page)
Beispiel #13
0
    def test_boostrap(self):
        """
        Verify handling of bootstrap parameter
        """
        conf_data = config.parse([
            '-q',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertFalse(conf_data.bootstrap)

        conf_data = config.parse([
            '--bootstrap=yes', '-q',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertTrue(conf_data.bootstrap)
Beispiel #14
0
    def suspend_test_check_install(self):
        import pip
        # discard the argparser errors
        with patch('sys.stdout', self.stdout):
            with patch('sys.stderr', self.stderr):
                # clean the virtualenv
                try:
                    pip.main(['uninstall', '-y', 'psycopg2'])
                except pip.exceptions.UninstallationError:
                    ## package not installed, all is fine
                    pass
                try:
                    pip.main(['uninstall', '-y', 'pillow'])
                except pip.exceptions.UninstallationError:
                    ## package not installed, all is fine
                    pass
                try:
                    pip.main(['uninstall', '-y', 'mysql-python'])
                except pip.exceptions.UninstallationError:
                    ## package not installed, all is fine
                    pass

                # Check postgres / pillow
                conf_data = config.parse([
                    '-q',
                    '--db=postgres://user:pwd@host/dbname',
                    '--django-version=1.4',
                    '--i18n=no',
                    '-f',
                    '-p'+self.project_dir,
                    'example_prj'])
                with self.assertRaises(EnvironmentError) as context_error:
                    check_install(conf_data)
                self.assertTrue(str(context_error.exception).find('Pillow is not installed') > -1)
                self.assertTrue(str(context_error.exception).find('PostgreSQL driver is not installed') > -1)

                # Check mysql
                conf_data = config.parse([
                    '-q',
                    '--db=mysql://user:pwd@host/dbname',
                    '--django-version=1.4',
                    '--i18n=no',
                    '-f',
                    '-p'+self.project_dir,
                    'example_prj'])
                with self.assertRaises(EnvironmentError) as context_error:
                    check_install(conf_data)
                self.assertTrue(str(context_error.exception).find('MySQL driver is not installed') > -1)
Beispiel #15
0
    def test_starting_page(self):
        dj_version, dj_match = get_stable_django()
        cms_stable, cms_match = get_stable_djangocms()

        config_data = config.parse([
            "--db=sqlite://localhost/test.db",
            "--cms-version=%s" % cms_stable,
            "-q",
            "-u",
            "--django-version=%s" % dj_version,
            "--starting-page=yes",
            "-p" + self.project_dir,
            "cms_project",
        ])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        django.setup_database(config_data)
        django.load_starting_page(config_data)
        project_db = sqlite3.connect(
            os.path.join(config_data.project_directory, "test.db"))

        # Check loaded data
        query = project_db.execute("SELECT * FROM cms_page")
        row = query.fetchone()
        self.assertTrue("fullwidth.html" in row)

        query = project_db.execute("SELECT * FROM cms_title")
        row = query.fetchone()
        self.assertTrue("Home" in row)

        query = project_db.execute("SELECT * FROM cms_cmsplugin")
        row = query.fetchone()
        self.assertTrue("TextPlugin" in row)
Beispiel #16
0
    def test_patch_django_30_develop(self):
        extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py')
        params = [
            '--db=sqlite://localhost/test.db', '--lang=en', '--extra-settings=%s' % extra_path,
            '--django-version=3.0', '-f', '--cms-version=develop', '--timezone=Europe/Moscow',
            '-q', '-u', '-zno', '--i18n=no', '-p' + self.project_dir,
            'test_patch_django_30_develop'
        ]
        config_data = config.parse(params)
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), [str('settings')])

        # checking for django options
        self.assertTrue(project.settings.TEMPLATES)
        self.assertFalse(getattr(project.settings, 'TEMPLATES_DIR', False))
        self.assertTrue(
            config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS in
            project.settings.MIDDLEWARE
        )
Beispiel #17
0
    def test_force_django(self):
        dj_version, dj_match = get_stable_django()
        cms_stable, cms_match = get_stable_djangocms()

        config_data = config.parse([
            "--db=sqlite://localhost/test.db",
            "-q",
            "-u",
            "--starting-page=yes",
            "--cms-version=%s" % cms_stable,
            "--django=%s" % dj_version,
            "-p" + self.project_dir,
            "cms_project",
        ])
        install.requirements(config_data.requirements)
        install.requirements("django<1.9")
        django.create_project(config_data)
        with patch("sys.stdout", self.stdout):
            with patch("sys.stderr", self.stderr):
                with self.assertRaises(SystemExit) as error:
                    django.patch_settings(config_data)
        self.assertEqual(error.exception.code, 9)
        self.assertTrue(self.stderr.getvalue().find(
            "Currently installed Django version 1.8.19 differs from the declared %s"
            % dj_version) > -1)
    def test_starting_page(self):
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '-q', '-u',
            '--django-version=1.8', '--cms-version=3.2', '--starting-page=yes',
            '-p' + self.project_dir, 'cms_project'
        ])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        django.setup_database(config_data)
        django.load_starting_page(config_data)
        project_db = sqlite3.connect(
            os.path.join(config_data.project_directory, 'test.db'))

        # Check loaded data
        query = project_db.execute('SELECT * FROM cms_page')
        row = query.fetchone()
        self.assertTrue('fullwidth.html' in row)

        query = project_db.execute('SELECT * FROM cms_title')
        row = query.fetchone()
        self.assertTrue('Home' in row)

        query = project_db.execute('SELECT * FROM cms_cmsplugin')
        row = query.fetchone()
        self.assertTrue('TextPlugin' in row)
Beispiel #19
0
    def test_patch_django_111_36(self):
        dj_version, dj_match = get_latest_django(latest_1_x=True)

        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '--lang=en', '--bootstrap=yes',
                                    '--django-version=%s' % dj_version,
                                    '--cms-version=3.6', '--timezone=Europe/Moscow',
                                    '-q', '-u', '-zno', '--i18n=no',
                                    '-p' + self.project_dir, 'test_patch_django_111_36'])

        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        settings = open(config_data.settings_path).read()
        urlconf = open(config_data.urlconf_path).read()

        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), [str('settings')])

        # checking for django options
        self.assertEqual(
            project.settings.MEDIA_ROOT, os.path.join(config_data.project_directory, 'media')
        )
        self.assertEqual(project.settings.MEDIA_URL, '/media/')

        self.assertEqual(project.settings.TIME_ZONE, 'Europe/Moscow')
        self.assertTrue('cmsplugin_filer_image' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_file' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_folder' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_link' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_teaser' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_utils' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_video' not in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_text_ckeditor' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_admin_style' in project.settings.INSTALLED_APPS)
        self.assertTrue('filer' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_bootstrap4' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_file' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_flash' not in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_googlemap' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_inherit' not in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_link' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_picture' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_style' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_teaser' not in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_video' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS in
            project.settings.MIDDLEWARE
        )
        self.assertEqual(set(project.settings.CMS_TEMPLATES), self.templates_bootstrap)

        self.assertTrue(project.settings.TEMPLATES)
        self.assertEqual(len(re.findall('BASE_DIR = ', settings)), 1)
        self.assertEqual(len(re.findall('STATIC_ROOT', settings)), 1)
        self.assertEqual(len(re.findall('MEDIA_ROOT =', settings)), 1)
        self.assertEqual(len(re.findall('STATICFILES_DIRS', settings)), 1)
Beispiel #20
0
 def test_create_project(self):
     config_data = config.parse(['--db=postgres://user:pwd@host/dbname',
                                 '--cms-version=stable', '--django=%s' % dj_ver,
                                 '-q', '-p' + self.project_dir, 'example_prj'])
     install.requirements(config_data.requirements)
     django.create_project(config_data)
     self.assertTrue(os.path.exists(os.path.join(self.project_dir, 'example_prj')))
Beispiel #21
0
    def test_patch_django_19_develop(self):
        # On django CMS 3.2 the reload apphooks middleware is enabled by default
        extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py')
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '--lang=en', '--extra-settings=%s' % extra_path,
                                    '--django-version=1.9', '-f',
                                    '--cms-version=develop', '--timezone=Europe/Moscow',
                                    '-q', '-u', '-zno', '--i18n=no',
                                    '-p' + self.project_dir, 'example_path_19_32_settings'])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), [str('settings')])

        # checking for django options
        self.assertTrue(project.settings.TEMPLATES)
        self.assertFalse(getattr(project.settings, 'TEMPLATES_DIR', False))
        self.assertTrue(
            config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS_OLD not in
            project.settings.MIDDLEWARE_CLASSES
        )
        self.assertTrue(
            config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS in
            project.settings.MIDDLEWARE_CLASSES
        )
Beispiel #22
0
    def test_cli_config_comma_languages_with_space(self):
        conf_data = config.parse([
            '-q', '--db=postgres://user:pwd@host/dbname', '-len , de , it',
            '-p' + self.project_dir, 'example_prj'
        ])

        self.assertEqual(conf_data.languages, ['en', 'de', 'it'])
Beispiel #23
0
    def test_build_settings(self):
        """Tests django.__init__._build_settings function."""
        dj_version, dj_match = get_stable_django()
        cms_stable, cms_match = get_stable_djangocms()

        config_data = config.parse([
            "--db=postgres://user:pwd@host:5432/dbname",
            "--cms-version=%s" % cms_stable,
            "--django=%s" % dj_version,
            "-q",
            "-p .",
            "example_prj",
        ])
        settings = django._build_settings(config_data)
        self.assertTrue(
            textwrap.dedent("""
            DATABASES = {
                'default': {
                    'CONN_MAX_AGE': 0,
                    'ENGINE': 'django.db.backends.postgresql_psycopg2',
                    'HOST': 'host',
                    'NAME': 'dbname',
                    'PASSWORD': '******',
                    'PORT': 5432,
                    'USER': '******'
                }
            }""").strip() in settings)
        self.assertTrue("X_FRAME_OPTIONS = 'SAMEORIGIN'" in settings)
Beispiel #24
0
    def test_patch_110_settings(self):
        extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py')
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '--lang=en', '--extra-settings=%s' % extra_path,
                                    '--django-version=1.10',
                                    '--cms-version=3.4', '--timezone=Europe/Moscow',
                                    '-q', '-u', '-zno', '--i18n=no',
                                    '-p' + self.project_dir, 'example_path_110_settings'])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), [str('settings')])

        # checking for django options
        self.assertEqual(project.settings.MEDIA_ROOT,
                         os.path.join(config_data.project_directory, 'media'))
        self.assertEqual(project.settings.MEDIA_URL, '/media/')

        # Data from external settings files
        self.assertIsNotNone(getattr(project.settings, 'MIDDLEWARE', None))
        self.assertIsNone(getattr(project.settings, 'MIDDLEWARE_CLASSES', None))
Beispiel #25
0
    def test_patch_django_17_31(self):
        extra_path = os.path.join(os.path.dirname(__file__), 'data',
                                  'extra_settings.py')
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '--lang=en',
            '--extra-settings=%s' % extra_path, '--django-version=1.7', '-f',
            '--cms-version=develop', '--timezone=Europe/Moscow', '-q', '-u',
            '-zno', '--i18n=no', '-p' + self.project_dir,
            'example_path_17_31_settings'
        ])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(),
                             ['settings'])

        ## checking for django options
        self.assertFalse('south' in project.settings.INSTALLED_APPS)
        for module in MIGRATION_MODULES_3_1_FILER:
            self.assertTrue(
                module[0] in project.settings.MIGRATION_MODULES.keys())
            self.assertTrue(
                module[1] in project.settings.MIGRATION_MODULES.values())
Beispiel #26
0
    def test_database_setup(self):
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '-q', '--cms-version=3.1', '--django=%s' % dj_ver,
                                    '-p'+self.project_dir, 'cms_project'])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        django.setup_database(config_data)
        project_db = sqlite3.connect(os.path.join(config_data.project_directory, 'test.db'))

        # Checking content type table to check for correct applications setup
        query = project_db.execute('SELECT * FROM django_content_type WHERE app_label="cms" AND model="page"')
        row = query.fetchone()
        self.assertTrue('page' in row)
        self.assertTrue('cms' in row)

        # No data in CMS tables at setup time, but if query succeed database
        # schema should be fine
        query = project_db.execute('SELECT * FROM cms_page')
        self.assertTrue(query)

        # No data in auth tables at setup time due to the no-input
        query = project_db.execute('SELECT * FROM auth_user')
        self.assertTrue(query)
Beispiel #27
0
    def test_patch_django_19_32(self):
        # On django CMS 3.2 the reload apphooks middleware is enabled by default
        extra_path = os.path.join(os.path.dirname(__file__), 'data',
                                  'extra_settings.py')
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '--lang=en',
            '--extra-settings=%s' % extra_path, '--django-version=1.9', '-f',
            '--cms-version=develop', '--timezone=Europe/Moscow', '-q', '-u',
            '-zno', '--i18n=no', '-p' + self.project_dir,
            'example_path_19_32_settings'
        ])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(),
                             [str('settings')])

        # checking for django options
        self.assertTrue(project.settings.TEMPLATES)
        self.assertFalse(getattr(project.settings, 'TEMPLATES_DIR', False))
        self.assertTrue(
            'aldryn_apphook_reload' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS_OLD not in
            project.settings.MIDDLEWARE_CLASSES)
        self.assertTrue(config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS
                        in project.settings.MIDDLEWARE_CLASSES)
    def test_patch_110_settings(self):
        extra_path = os.path.join(os.path.dirname(__file__), 'data',
                                  'extra_settings.py')
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '--lang=en',
            '--extra-settings=%s' % extra_path, '--django-version=1.10',
            '--cms-version=3.4', '--timezone=Europe/Moscow', '-q', '-u',
            '-zno', '--i18n=no', '-p' + self.project_dir,
            'example_path_110_settings'
        ])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(),
                             [str('settings')])

        # checking for django options
        self.assertEqual(project.settings.MEDIA_ROOT,
                         os.path.join(config_data.project_directory, 'media'))
        self.assertEqual(project.settings.MEDIA_URL, '/media/')

        # Data from external settings files
        self.assertIsNotNone(getattr(project.settings, 'MIDDLEWARE', None))
        self.assertIsNone(getattr(project.settings, 'MIDDLEWARE_CLASSES',
                                  None))
Beispiel #29
0
    def test_patch_django_30_develop(self):
        extra_path = os.path.join(os.path.dirname(__file__), "data",
                                  "extra_settings.py")
        params = [
            "--db=sqlite://localhost/test.db",
            "--lang=en",
            "--extra-settings=%s" % extra_path,
            "--django-version=3.0",
            "-f",
            "--cms-version=develop",
            "--timezone=Europe/Moscow",
            "-q",
            "-u",
            "-zno",
            "--i18n=no",
            "-p" + self.project_dir,
            "test_patch_django_30_develop",
        ]
        config_data = config.parse(params)
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(),
                             ["settings"])

        # checking for django options
        self.assertTrue(project.settings.TEMPLATES)
        self.assertFalse(getattr(project.settings, "TEMPLATES_DIR", False))
        self.assertTrue(config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS
                        in project.settings.MIDDLEWARE)
Beispiel #30
0
    def test_patch_24_filer(self):
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '--lang=en',
            '--django-version=1.5', '--cms-version=2.4', '-f', '-q', '-u',
            '-zno', '--i18n=no', '-p' + self.project_dir, 'example_path_24_f'
        ])
        reqs = config_data.requirements.replace('django-mptt>=0.5.1,<0.5.3',
                                                '')
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        settings = open(config_data.settings_path).read()
        urlconf = open(config_data.urlconf_path).read()

        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(),
                             ['settings'])

        ## checking for django options
        self.assertTrue(project.settings.MEDIA_ROOT,
                        os.path.join(config_data.project_directory, 'media'))
        self.assertEqual(project.settings.MEDIA_URL, '/media/')
        self.assertTrue(
            'djangocms_file' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_flash' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_googlemap' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_inherit' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_link' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_picture' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_teaser' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_video' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cmsplugin_filer_image' in project.settings.INSTALLED_APPS)
        self.assertTrue('cms.plugins.flash' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cms.plugins.googlemap' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cms.plugins.inherit' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cmsplugin_filer_file' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cmsplugin_filer_folder' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cmsplugin_filer_link' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cmsplugin_filer_teaser' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cmsplugin_filer_utils' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cmsplugin_filer_video' in project.settings.INSTALLED_APPS)
Beispiel #31
0
    def test_starting_page(self):
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '-q', '-u', '--django-version=1.8',
                                    '--cms-version=3.2', '--starting-page=yes',
                                    '-p' + self.project_dir, 'cms_project'])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        django.setup_database(config_data)
        django.load_starting_page(config_data)
        project_db = sqlite3.connect(os.path.join(config_data.project_directory, 'test.db'))

        # Check loaded data
        query = project_db.execute('SELECT * FROM cms_page')
        row = query.fetchone()
        self.assertTrue('fullwidth.html' in row)

        query = project_db.execute('SELECT * FROM cms_title')
        row = query.fetchone()
        self.assertTrue('Home' in row)

        query = project_db.execute('SELECT * FROM cms_cmsplugin')
        row = query.fetchone()
        self.assertTrue('TextPlugin' in row)
Beispiel #32
0
    def test_database_setup(self):
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '-q', '--cms-version=3.0',
            '-p' + self.project_dir, 'cms_project'
        ])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        django.setup_database(config_data)
        project_db = sqlite3.connect(
            os.path.join(config_data.project_directory, 'test.db'))

        # Checking content type table to check for correct applications setup
        query = project_db.execute(
            'SELECT * FROM django_content_type WHERE app_label="cms" AND model="page"'
        )
        self.assertEqual(query.fetchone()[1], 'page')

        # No data in CMS tables at setup time, but if query succeed database
        # schema should be fine
        query = project_db.execute('SELECT * FROM cms_page')
        self.assertTrue(query)

        # No data in auth tables at setup time due to the no-input
        query = project_db.execute('SELECT * FROM auth_user')
        self.assertTrue(query)
Beispiel #33
0
    def disabled_test_setup_database_filer(self):
        config_data = config.parse(
            [
                "--db=sqlite://localhost/test.db",
                "-f",
                "-q",
                "-u",
                "--cms-version=develop",
                "-p" + self.project_dir,
                "cms_project",
            ]
        )
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        django.setup_database(config_data)
        project_db = sqlite3.connect(os.path.join(config_data.project_directory, "test.db"))

        # Checking content type table to check for correct applications setup
        query = project_db.execute('SELECT * FROM django_content_type WHERE app_label="cms" AND model="page"')
        self.assertEqual(query.fetchone()[1], "page")
        query = project_db.execute('SELECT * FROM django_content_type WHERE app_label="filer" AND model="image"')
        self.assertEqual(query.fetchone()[1], "image")

        # No data in CMS tables at setup time, but if query succeed database
        # schema should be fine
        query = project_db.execute("SELECT * FROM cms_page")
        self.assertTrue(query)
Beispiel #34
0
    def test_patch_111_36_settings(self):
        dj_version, dj_match = get_latest_django(latest_1_x=True)

        extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py')
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '--lang=en', '--extra-settings=%s' % extra_path,
                                    '--django-version=%s' % dj_version,
                                    '--cms-version=3.6', '--timezone=Europe/Moscow',
                                    '-q', '-u', '-zno', '--i18n=no',
                                    '-p' + self.project_dir, 'test_patch_111_36_settings'])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), [str('settings')])

        # checking for django options
        self.assertEqual(project.settings.MEDIA_ROOT,
                         os.path.join(config_data.project_directory, 'media'))
        self.assertEqual(project.settings.MEDIA_URL, '/media/')

        # Data from external settings file
        self.assertEqual(project.settings.CUSTOM_SETTINGS_VAR, True)
        self.assertEqual(project.settings.CMS_PERMISSION, False)
        self.assertEqual(set(project.settings.CMS_TEMPLATES), self.templates_basic)
        self.assertIsNotNone(getattr(project.settings, 'MIDDLEWARE', None))
        self.assertIsNone(getattr(project.settings, 'MIDDLEWARE_CLASSES', None))
Beispiel #35
0
    def test_patch_19_32_settings(self):
        extra_path = os.path.join(os.path.dirname(__file__), 'data', 'extra_settings.py')
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '--lang=en', '--extra-settings=%s' % extra_path,
                                    '--django-version=1.9',
                                    '--cms-version=3.2', '--timezone=Europe/Moscow',
                                    '-q', '-u', '-zno', '--i18n=no',
                                    '-p' + self.project_dir, 'example_path_16_settigns'])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), [str('settings')])

        # checking for django options
        self.assertEqual(project.settings.MEDIA_ROOT,
                         os.path.join(config_data.project_directory, 'media'))
        self.assertEqual(project.settings.MEDIA_URL, '/media/')

        # Data from external settings file
        self.assertEqual(project.settings.CUSTOM_SETTINGS_VAR, True)
        self.assertEqual(project.settings.CMS_PERMISSION, False)
        self.assertEqual(set(project.settings.CMS_TEMPLATES), self.templates_basic)
    def test_patch_django_18_32(self):
        extra_path = os.path.join(os.path.dirname(__file__), 'data',
                                  'extra_settings.py')
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '--lang=en',
            '--extra-settings=%s' % extra_path, '--django-version=1.8',
            '--cms-version=3.2', '--timezone=Europe/Moscow', '-q', '-u',
            '-zno', '--i18n=no', '-p' + self.project_dir,
            'example_path_17_settings'
        ])
        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(),
                             [str('settings')])

        # checking for django options
        self.assertFalse('south' in project.settings.INSTALLED_APPS)
        self.assertFalse('cms' in project.settings.MIGRATION_MODULES)
        self.assertFalse(
            'djangocms_text_ckeditor' in project.settings.MIGRATION_MODULES)
Beispiel #37
0
    def test_patch_cms_24_standard(self):
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '--lang=en',
            '--django-version=1.5', '--cms-version=2.4', '-q', '-u', '-zno',
            '--i18n=no', '-p' + self.project_dir, 'example_path_24_s'
        ])

        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        settings = open(config_data.settings_path).read()
        urlconf = open(config_data.urlconf_path).read()

        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(),
                             [str('settings')])

        # checking for django options
        self.assertTrue(project.settings.MEDIA_ROOT,
                        os.path.join(config_data.project_directory, 'media'))
        self.assertEqual(project.settings.MEDIA_URL, '/media/')
        self.assertTrue('cms.context_processors.cms_settings' not in
                        project.settings.TEMPLATE_CONTEXT_PROCESSORS)
        self.assertTrue('cms.context_processors.media' in
                        project.settings.TEMPLATE_CONTEXT_PROCESSORS)
        self.assertTrue(
            'djangocms_file' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_flash' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_googlemap' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_inherit' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_link' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_picture' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_teaser' not in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'djangocms_video' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cms.plugins.file' in project.settings.INSTALLED_APPS)
        self.assertTrue('cms.plugins.flash' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cms.plugins.googlemap' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cms.plugins.inherit' in project.settings.INSTALLED_APPS)
        self.assertTrue('cms.plugins.link' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cms.plugins.picture' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cms.plugins.teaser' in project.settings.INSTALLED_APPS)
        self.assertTrue('cms.plugins.text' in project.settings.INSTALLED_APPS)
        self.assertTrue(
            'cms.plugins.twitter' in project.settings.INSTALLED_APPS)
        self.assertTrue('cms.plugins.video' in project.settings.INSTALLED_APPS)
Beispiel #38
0
 def test_create_project(self):
     dj_version, dj_match = get_latest_django(latest_stable=True)
     config_data = config.parse(['--db=postgres://user:pwd@host/dbname',
                                 '--cms-version=develop', '--django=%s' % dj_version,
                                 '-q', '-p' + self.project_dir, 'example_prj'])
     install.requirements(config_data.requirements)
     django.create_project(config_data)
     self.assertTrue(os.path.exists(os.path.join(self.project_dir, 'example_prj')))
    def test_utc(self):
        """
        Verify handling UTC default
        """
        default_tz = get_localzone()

        conf_data = config.parse([
            '-q',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertEqual(text_type(conf_data.timezone), default_tz.zone)

        conf_data = config.parse([
            '-q', '--utc',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertEqual(conf_data.timezone, 'UTC')
Beispiel #40
0
    def test_templates(self):
        """
        Verify handling of valid (existing) and invalid (non-existing) templates directory parameter
        """
        conf_data = config.parse([
            '--templates=/foo/bar', '-q',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertFalse(conf_data.templates)

        tpl_path = os.path.join(os.path.dirname(__file__), 'test_templates')

        conf_data = config.parse([
            '--templates=%s' % tpl_path, '-q',
            '-p'+self.project_dir,
            'example_prj'])
        self.assertEqual(conf_data.templates, tpl_path)
Beispiel #41
0
 def test_timezone(self, mock_get_localzone):
     """
     Verify handling problem with detecting timezone
     """
     mock_get_localzone.return_value = 'local'
     conf_data = config.parse(
         ['-q', '-p' + self.project_dir, 'example_prj'])
     self.assertEqual(text_type(conf_data.timezone), 'UTC')
    def test_parse_config_file(self, *args):
        """Tests .config.__init__._parse_config_file function."""
        with self.assertRaises(SystemExit) as error:
            config_data = config.parse(self.args[0:1] + [self.conf('config-not-exists.ini')] + self.args[1:])
            self.assertEqual(7, error.exception.code)

        args = self.args[0:1] + [self.conf('config-01.ini')] + self.args[1:]
        config_data = config.parse(args)
        self.unused(config_data)
        self.assertEqual(self.config_fixture, config_data)

        fixture = copy.copy(self.config_fixture)
        test_data = (
            ('config-02.ini', 'db', 'postgres://*****:*****@host:54321/dbname'),
            ('config-03.ini', 'i18n', 'no'),
            ('config-04.ini', 'use_timezone', 'no'),
            ('config-05.ini', 'timezone', 'Europe/London'),
            ('config-06.ini', 'reversion', 'no'),
            ('config-07.ini', 'permissions', 'no'),
            ('config-08.ini', 'languages', ['en', 'ru']),
            ('config-09.ini', 'django_version', 1.8),
            ('config-10.ini', 'i18n', 'no'),
            ('config-11.ini', 'project_directory', '/test/me'),
            ('config-12.ini', 'bootstrap', True),
            ('config-13.ini', 'templates', '.'),
            ('config-14.ini', 'starting_page', True),
            ('config-15.ini', 'plugins', True),
            ('config-16.ini', 'dump_reqs', True),
            ('config-17.ini', 'noinput', True),
            ('config-18.ini', 'filer', True),
            ('config-19.ini', 'requirements_file', '/test/reqs'),
            ('config-20.ini', 'no_deps', True),
            ('config-21.ini', 'no_db_driver', True),
            ('config-22.ini', 'no_sync', True),
            ('config-23.ini', 'no_user', True),
            ('config-24.ini', 'template', '/test/template'),
            ('config-25.ini', 'extra_settings', '/test/extra_settings'),
            ('config-26.ini', 'skip_project_dir_check', True),
            ('config-27.ini', 'utc', True),
        )
        for filename, key, val in test_data:
            setattr(fixture, key, val)  # Change value.
            args = self.args[0:1] + [self.conf(filename)] + self.args[1:]  # Load new config.
            config_data = config.parse(args)
            self.unused(config_data)
            self.assertEqual(fixture, config_data)  # Check if config value and changed value equals.
Beispiel #43
0
    def test_templates(self):
        """
        Verify handling of valid (existing) and invalid (non-existing) templates directory parameter
        """
        conf_data = config.parse([
            '--templates=/foo/bar', '-q', '-p' + self.project_dir,
            'example_prj'
        ])
        self.assertFalse(conf_data.templates)

        tpl_path = os.path.join(os.path.dirname(__file__), 'test_templates')

        conf_data = config.parse([
            '--templates=%s' % tpl_path, '-q', '-p' + self.project_dir,
            'example_prj'
        ])
        self.assertEqual(conf_data.templates, tpl_path)
Beispiel #44
0
    def test_invalid_project_name(self):
        with patch('sys.stdout', self.stdout):
            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'test'])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find('Project name "test" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'assert'])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find('Project name "assert" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'values'])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find('Project name "values" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'project-name'])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find('Project name "project-name" is not a valid app name') > -1)
Beispiel #45
0
    def test_invalid_project_name(self):
        with patch('sys.stdout', self.stdout):
            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q', '--db=postgres://user:pwd@host/dbname',
                        '-p' + self.project_dir, 'test'
                    ])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find(
                'Project name "test" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q', '--db=postgres://user:pwd@host/dbname',
                        '-p' + self.project_dir, 'assert'
                    ])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find(
                'Project name "assert" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q', '--db=postgres://user:pwd@host/dbname',
                        '-p' + self.project_dir, 'values'
                    ])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find(
                'Project name "values" is not a valid app name') > -1)

            stderr_tmp = StringIO()
            with patch('sys.stderr', stderr_tmp):
                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q', '--db=postgres://user:pwd@host/dbname',
                        '-p' + self.project_dir, 'project-name'
                    ])
            self.assertEqual(error.exception.code, 3)
            self.assertTrue(stderr_tmp.getvalue().find(
                'Project name "project-name" is not a valid app name') > -1)
Beispiel #46
0
 def test_create_project(self):
     config_data = config.parse([
         '--db=postgres://user:pwd@host/dbname', '--cms-version=stable',
         '-q', '-p' + self.project_dir, 'example_prj'
     ])
     install.requirements(config_data.requirements)
     django.create_project(config_data)
     self.assertTrue(
         os.path.exists(os.path.join(self.project_dir, 'example_prj')))
Beispiel #47
0
 def test_auto_i18n(self):
     """
     Verify setting automatic i18n support if multiple languages
     """
     conf_data = config.parse([
         '-q', '-len,de'
         '--i18n=no', '-p' + self.project_dir, 'example_prj'
     ])
     self.assertTrue(conf_data.i18n)
Beispiel #48
0
 def test_version_misdj_match(self):
     with self.assertRaises(SystemExit):
         conf_data = config.parse([
             '-q', '--db=postgres://user:pwd@host/dbname',
             '--cms-version=stable', '--django-version=1.4', '--i18n=no',
             '--reversion=no', '--permissions=no', '--use-tz=no',
             '-tEurope/Rome', '-len', '-lde', '-lit',
             '-p' + self.project_dir, 'example_prj'
         ])
Beispiel #49
0
    def test_patch_16(self):
        config_data = config.parse(
            [
                "--db=sqlite://localhost/test.db",
                "--lang=en",
                "--django-version=1.6",
                "--cms-version=3.0",
                "-q",
                "-u",
                "-zno",
                "--i18n=no",
                "-p" + self.project_dir,
                "example_path_16",
            ]
        )

        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        settings = open(config_data.settings_path).read()
        urlconf = open(config_data.urlconf_path).read()

        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), ["settings"])

        ## checking for django options
        self.assertTrue(project.settings.MEDIA_ROOT, os.path.join(config_data.project_directory, "media"))
        self.assertEqual(project.settings.MEDIA_URL, "/media/")

        self.assertTrue("cmsplugin_filer_image" not in project.settings.INSTALLED_APPS)
        self.assertTrue("cmsplugin_filer_file" not in project.settings.INSTALLED_APPS)
        self.assertTrue("cmsplugin_filer_folder" not in project.settings.INSTALLED_APPS)
        self.assertTrue("cmsplugin_filer_link" not in project.settings.INSTALLED_APPS)
        self.assertTrue("cmsplugin_filer_teaser" not in project.settings.INSTALLED_APPS)
        self.assertTrue("cmsplugin_filer_utils" not in project.settings.INSTALLED_APPS)
        self.assertTrue("cmsplugin_filer_video" not in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_text_ckeditor" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_admin_style" in project.settings.INSTALLED_APPS)
        self.assertTrue("filer" not in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_column" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_file" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_flash" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_googlemap" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_inherit" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_link" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_picture" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_style" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_teaser" in project.settings.INSTALLED_APPS)
        self.assertTrue("djangocms_video" in project.settings.INSTALLED_APPS)

        self.assertEqual(len(re.findall("BASE_DIR = ", settings)), 1)
        self.assertEqual(len(re.findall("STATIC_ROOT", settings)), 1)
        self.assertEqual(len(re.findall("MEDIA_ROOT =", settings)), 1)
        self.assertEqual(len(re.findall("STATICFILES_DIRS", settings)), 2)
Beispiel #50
0
    def test_patch_django_16(self):
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '--lang=en', '--bootstrap=yes',
                                    '--django-version=1.6', '--apphooks-reload',
                                    '--cms-version=3.0', '--timezone=Europe/Moscow',
                                    '-q', '-u', '-zno', '--i18n=no',
                                    '-p'+self.project_dir, 'example_path_16'])

        install.requirements(config_data.requirements)
        django.create_project(config_data)
        django.patch_settings(config_data)
        django.copy_files(config_data)
        settings = open(config_data.settings_path).read()
        urlconf = open(config_data.urlconf_path).read()

        # settings is importable even in non django environment
        sys.path.append(config_data.project_directory)

        project = __import__(config_data.project_name, globals(), locals(), [str('settings')])

        # checking for django options
        self.assertEqual(project.settings.MEDIA_ROOT, os.path.join(config_data.project_directory, 'media'))
        self.assertEqual(project.settings.MEDIA_URL, '/media/')

        self.assertEqual(project.settings.TIME_ZONE, 'Europe/Moscow')
        self.assertTrue('cmsplugin_filer_image' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_file' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_folder' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_link' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_teaser' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_utils' not in project.settings.INSTALLED_APPS)
        self.assertTrue('cmsplugin_filer_video' not in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_text_ckeditor' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_admin_style' in project.settings.INSTALLED_APPS)
        self.assertTrue('filer' not in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_column' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_file' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_flash' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_googlemap' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_inherit' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_link' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_picture' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_style' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_teaser' in project.settings.INSTALLED_APPS)
        self.assertTrue('djangocms_video' in project.settings.INSTALLED_APPS)
        self.assertTrue('aldryn_apphook_reload' in project.settings.INSTALLED_APPS)
        self.assertTrue(config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS_OLD in project.settings.MIDDLEWARE_CLASSES)
        self.assertTrue(config.get_settings().APPHOOK_RELOAD_MIDDLEWARE_CLASS not in project.settings.MIDDLEWARE_CLASSES)
        self.assertTrue('cms.context_processors.cms_settings' in project.settings.TEMPLATE_CONTEXT_PROCESSORS)
        self.assertTrue('cms.context_processors.media' not in project.settings.TEMPLATE_CONTEXT_PROCESSORS)

        self.assertEqual(set(project.settings.CMS_TEMPLATES), self.templates_bootstrap)

        self.assertEqual(len(re.findall('BASE_DIR = ', settings)), 1)
        self.assertEqual(len(re.findall('STATIC_ROOT', settings)), 1)
        self.assertEqual(len(re.findall('MEDIA_ROOT =', settings)), 1)
        self.assertEqual(len(re.findall('STATICFILES_DIRS', settings)), 1)
    def test_dump_config_file(self, *args):
        """Tests .config.ini.dump_config_file function."""
        config_exists = self.conf('config-01.ini')

        with self.assertRaises(SystemExit) as error:
            config_data = config.parse(['--config-dump', config_exists] + self.args[1:] + ['-p', '.'])
            self.assertEqual(8, error.exception.code)

        config_data = config.parse(['--config-dump', self.config_not_exists] + self.args[1:] + ['-p', '.'])
        self.assertTrue(os.path.isfile(self.config_not_exists))

        fixture = copy.copy(self.config_fixture)
        setattr(fixture, 'timezone', get_localzone().zone)
        # Load dumped config.
        args = self.args[0:1] + [self.config_not_exists] + self.args[1:]
        config_data = config.parse(args)
        self.unused(config_data)
        self.assertEqual(fixture, config_data)
Beispiel #52
0
    def test_cli_config(self):
        conf_data = config.parse([
            '-q', '--db=postgres://user:pwd@host/dbname',
            '--cms-version=stable', '--django-version=1.7', '--i18n=no',
            '--reversion=no', '--permissions=no', '--use-tz=no',
            '-tEurope/Rome', '-len', '-lde', '-lit', '-p' + self.project_dir,
            'example_prj'
        ])

        self.assertEqual(conf_data.project_name, 'example_prj')

        self.assertEqual(conf_data.cms_version, 3.1)
        self.assertEqual(conf_data.django_version, 1.7)
        self.assertEqual(conf_data.i18n, 'no')
        self.assertEqual(conf_data.reversion, 'no')
        self.assertEqual(conf_data.permissions, 'no')
        self.assertEqual(conf_data.use_timezone, 'no')
        self.assertEqual(conf_data.timezone, 'Europe/Rome')
        self.assertEqual(conf_data.languages, ['en', 'de', 'it'])
        self.assertEqual(conf_data.project_directory, self.project_dir)
        self.assertEqual(conf_data.db, 'postgres://*****:*****@host/dbname')
        self.assertEqual(conf_data.db_driver, 'psycopg2')

        conf_data = config.parse([
            '-q', '--db=postgres://user:pwd@host/dbname',
            '--cms-version=stable', '--django-version=1.4',
            '--cms-version=3.0', '--i18n=no', '--reversion=no',
            '--permissions=no', '--use-tz=no', '-tEurope/Rome', '-len', '-lde',
            '-lit', '-p' + self.project_dir, 'example_prj'
        ])

        self.assertEqual(conf_data.project_name, 'example_prj')

        self.assertEqual(conf_data.cms_version, 3.0)
        self.assertEqual(conf_data.django_version, 1.4)
        self.assertEqual(conf_data.i18n, 'no')
        self.assertEqual(conf_data.reversion, 'no')
        self.assertEqual(conf_data.permissions, 'no')
        self.assertEqual(conf_data.use_timezone, 'no')
        self.assertEqual(conf_data.timezone, 'Europe/Rome')
        self.assertEqual(conf_data.languages, ['en', 'de', 'it'])
        self.assertEqual(conf_data.project_directory, self.project_dir)
        self.assertEqual(conf_data.db, 'postgres://*****:*****@host/dbname')
        self.assertEqual(conf_data.db_driver, 'psycopg2')
Beispiel #53
0
 def test_django_admin_errors(self):
     dj_version, dj_match = get_latest_django(latest_stable=True)
     config_data = config.parse(['--db=postgres://user:pwd@host/dbname',
                                 '--cms-version=develop', '--django=%s' % dj_version,
                                 '-q', '-p' + self.project_dir, 'example_prj'])
     install.requirements(config_data.requirements)
     config_data.project_name = 'example.prj'
     with self.assertRaises(RuntimeError) as e:
         django.create_project(config_data)
     self.assertTrue('\'example.prj\' is not a valid project name.' in str(e.exception))
Beispiel #54
0
 def test_timezone(self, mock_get_localzone):
     """
     Verify handling problem with detecting timezone
     """
     mock_get_localzone.return_value = 'local'
     conf_data = config.parse([
         '-q',
         '-p'+self.project_dir,
         'example_prj'])
     self.assertEqual(text_type(conf_data.timezone), 'UTC')
Beispiel #55
0
 def test_auto_i18n(self):
     """
     Verify setting automatic i18n support if multiple languages
     """
     conf_data = config.parse([
         '-q', '-len,de'
         '--i18n=no',
         '-p' + self.project_dir,
         'example_prj'])
     self.assertTrue(conf_data.i18n)
Beispiel #56
0
 def cleanup_skip(self):
     with patch('sys.stdout', self.stdout):
         with patch('sys.stderr', self.stderr):
             conf_data = config.parse([
                 '-q', '-s', '--db=postgres://user:pwd@host/dbname',
                 '--i18n=no', '--django-version=1.11', '-f',
                 '-p' + self.project_dir, 'example_prj'
             ])
             install.cleanup_directory(conf_data)
             self.assertTrue(os.path.exists(self.project_dir))
Beispiel #57
0
    def test_cli_config_comma_languages_with_space(self):
        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '-len , de , it',
            '-p'+self.project_dir,
            'example_prj'
        ])

        self.assertEqual(conf_data.languages, ['en', 'de', 'it'])
Beispiel #58
0
 def test_invalid_choices(self):
     with patch('sys.stdout', self.stdout):
         with patch('sys.stderr', self.stderr):
             with self.assertRaises(SystemExit) as error:
                 conf_data = config.parse([
                     '-q', '--db=postgres://user:pwd@host/dbname',
                     '--cms-version=2.6', '--django-version=1.1',
                     '--i18n=no', '-p' + self.project_dir, 'example_prj'
                 ])
     self.assertTrue(self.stderr.getvalue().find(
         "--cms-version/-v: invalid choice: '2.6'") > -1)