Exemplo n.º 1
0
    def test_invalid_project_name(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',
                        '-p' + self.project_dir, 'test'
                    ])
                    self.assertTrue(
                        str(error.exception).find(
                            'Project name "test" is not valid') > -1)

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

                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q', '--db=postgres://user:pwd@host/dbname',
                        '-p' + self.project_dir, 'values'
                    ])
                    self.assertTrue(
                        str(error.exception).find(
                            'Project name "assert" is not valid') > -1)
Exemplo n.º 2
0
    def test_check_install(self):
        try:
            import PIL
            self.skipTest('Virtualenv installed, cannot run this test')
        except ImportError:
            pass
        # discard the argparser errors
        with patch('sys.stdout', self.stdout):
            with patch('sys.stderr', self.stderr):
                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 error:
                    check_install(conf_data)
                self.assertTrue(
                    str(error.exception).find('Pillow is not installed') > -1)
                self.assertTrue(
                    str(error.exception).find(
                        'PostgreSQL driver is not installed') > -1)

                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 error:
                    check_install(conf_data)

                    self.assertTrue(
                        str(error.exception).find(
                            'MySQL  driver is not installed') > -1)
Exemplo n.º 3
0
    def test_invalid_project_name(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',
                        '-p'+self.project_dir,
                        'test'])
                    self.assertTrue(str(error.exception).find('Project name "test" is not valid') > -1)

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

                with self.assertRaises(SystemExit) as error:
                    conf_data = config.parse([
                        '-q',
                        '--db=postgres://user:pwd@host/dbname',
                        '-p'+self.project_dir,
                        'values'])
                    self.assertTrue(str(error.exception).find('Project name "assert" is not valid') > -1)
Exemplo n.º 4
0
    def test_requirements(self):
        self._remove_project_dir()
        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',
            '-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)
Exemplo n.º 5
0
    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', '-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)
Exemplo n.º 6
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'])
Exemplo n.º 7
0
 def test_create_project(self):
     config_data = config.parse(['--db=postgres://user:pwd@host/dbname',
                                 '--cms-version=develop',
                                 '-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')))
Exemplo n.º 8
0
    def test_cli_config(self):
        conf_data = config.parse([
            '-q',
            '--db=postgres://user:pwd@host/dbname',
            '--cms-version=develop',
            '--django-version=1.4',
            '--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')
Exemplo n.º 9
0
    def test_setup_database_filer(self):
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '-f', '-q', '-u',
            '--cms-version=develop', '-p' + self.project_dir, 'aldryn_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)
Exemplo n.º 10
0
 def test_create_project(self):
     config_data = config.parse([
         '--db=postgres://user:pwd@host/dbname', '--cms-version=develop',
         '-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')))
Exemplo n.º 11
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'])
Exemplo n.º 12
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(
                     str(error.exception).find(
                         '--cms-version/-v: invalid choice: "2.6"') > -1)
Exemplo n.º 13
0
 def test_whitespace_project_path(self):
     prj_dir = 'example_prj'
     existing_path = os.path.join(self.project_dir, prj_dir)
     os.makedirs(existing_path)
     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',
                     '-p' + self.project_dir, prj_dir
                 ])
                 self.assertEqual(conf_data.project_path, existing_path)
Exemplo n.º 14
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(str(error.exception).find('--cms-version/-v: invalid choice: "2.6"') > -1)
Exemplo n.º 15
0
 def test_whitespace_project_path(self):
     prj_dir = 'example_prj'
     existing_path = os.path.join(self.project_dir, prj_dir)
     os.makedirs(existing_path)
     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',
                     '-p'+self.project_dir,
                     prj_dir])
                 self.assertEqual(conf_data.project_path, existing_path)
Exemplo n.º 16
0
 def test_invalid_project_path(self):
     prj_dir = 'example_prj'
     existing_path = os.path.join(self.project_dir, prj_dir)
     os.makedirs(existing_path)
     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',
                     '-p'+self.project_dir,
                     prj_dir])
                 self.assertTrue(str(error.exception).find('Path "%s" already exists' % existing_path) > -1)
Exemplo n.º 17
0
 def test_invalid_project_path(self):
     prj_dir = 'example_prj'
     existing_path = os.path.join(self.project_dir, prj_dir)
     os.makedirs(existing_path)
     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',
                     '-p' + self.project_dir, prj_dir
                 ])
                 self.assertTrue(
                     str(error.exception).find('Path "%s" already exists' %
                                               existing_path) > -1)
Exemplo n.º 18
0
    def test_check_install(self):
        try:
            import PIL
            self.skipTest('Virtualenv installed, cannot run this test')
        except ImportError:
            pass
        # discard the argparser errors
        with patch('sys.stdout', self.stdout):
            with patch('sys.stderr', self.stderr):
                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 error:
                    check_install(conf_data)
                self.assertTrue(str(error.exception).find('Pillow is not installed') > -1)
                self.assertTrue(str(error.exception).find('PostgreSQL driver is not installed') > -1)

                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 error:
                    check_install(conf_data)

                    self.assertTrue(str(error.exception).find('MySQL  driver is not installed') > -1)
Exemplo n.º 19
0
    def test_patch(self):
        config_data = config.parse([
            '--db=sqlite://localhost/test.db', '--lang=en',
            '--cms-version=develop', '-f', '-q', '-u', '-zno', '--i18n=no',
            '-p' + self.project_dir, 'example_patch'
        ])
        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.assertFalse(project.settings.USE_L10N)
        self.assertFalse(project.settings.USE_TZ)
        self.assertEqual(project.settings.LANGUAGE_CODE, 'en')
        #
        ## checking for standard CMS settings
        self.assertTrue('sekizai.context_processors.sekizai' in
                        project.settings.TEMPLATE_CONTEXT_PROCESSORS)
        self.assertTrue('cms.middleware.toolbar.ToolbarMiddleware' in
                        project.settings.MIDDLEWARE_CLASSES)
        self.assertTrue(
            project.settings.CMS_LANGUAGES['default']['redirect_on_fallback'])
        self.assertEqual(project.settings.CMS_LANGUAGES[1][0]['code'], 'en')

        ## checking for filer (optional) settings
        self.assertTrue('filer' in project.settings.INSTALLED_APPS)
        self.assertTrue('easy_thumbnails' in project.settings.INSTALLED_APPS)
        self.assertTrue(hasattr(project.settings, 'THUMBNAIL_PROCESSORS'))

        ## basic urlconf check
        self.assertTrue('cms.urls' in urlconf)
        self.assertTrue('staticfiles_urlpatterns' in urlconf)

        sys.path.remove(config_data.project_directory)
        del project
        del (sys.modules["%s.settings" % config_data.project_name])
Exemplo n.º 20
0
    def test_patch(self):
        self._remove_project_dir()
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '--lang=en',
                                    '--cms-version=develop',
                                    '-f', '-q', '-u', '-zno', '--i18n=no',
                                    '-p'+self.project_dir, 'example_patch'])
        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.assertFalse(project.settings.USE_L10N)
        self.assertFalse(project.settings.USE_TZ)
        self.assertEqual(project.settings.LANGUAGE_CODE, 'en')
        #
        ## checking for standard CMS settings
        self.assertTrue('sekizai.context_processors.sekizai' in project.settings.TEMPLATE_CONTEXT_PROCESSORS)
        self.assertTrue('cms.middleware.toolbar.ToolbarMiddleware' in project.settings.MIDDLEWARE_CLASSES)
        self.assertTrue(project.settings.CMS_LANGUAGES['default']['redirect_on_fallback'])
        self.assertEqual(project.settings.CMS_LANGUAGES[1][0]['code'], 'en')

        ## checking for filer (optional) settings
        self.assertTrue('filer' in project.settings.INSTALLED_APPS)
        self.assertTrue('easy_thumbnails' in project.settings.INSTALLED_APPS)
        self.assertTrue(hasattr(project.settings, 'THUMBNAIL_PROCESSORS'))

        ## basic urlconf check
        self.assertTrue('cms.urls' in urlconf)
        self.assertTrue('staticfiles_urlpatterns' in urlconf)

        sys.path.remove(config_data.project_directory)
        self._remove_project_dir()
        del project
        del(sys.modules["%s.settings" % config_data.project_name])
Exemplo n.º 21
0
    def test_default_config(self):
        conf_data = config.parse(['--db=postgres://user:pwd@host/dbname',
                                  '-q', '-p'+self.project_dir, 'example_prj'])

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

        self.assertEqual(conf_data.cms_version, 2.4)
        self.assertEqual(conf_data.django_version, 1.5)
        self.assertEqual(conf_data.i18n, 'yes')
        self.assertEqual(conf_data.reversion, 'yes')
        self.assertEqual(conf_data.permissions, 'yes')
        self.assertEqual(conf_data.use_timezone, 'yes')
        self.assertEqual(conf_data.db, 'postgres://*****:*****@host/dbname')

        self.assertEqual(conf_data.no_db_driver, False)
        self.assertEqual(conf_data.no_deps, False)
        self.assertEqual(conf_data.no_sync, False)
        self.assertEqual(conf_data.plugins, False)
        self.assertEqual(conf_data.requirements_file, None)
Exemplo n.º 22
0
    def test_setup_database(self):
        config_data = config.parse(['--db=sqlite://localhost/test.db',
                                    '-q', '-u', '--cms-version=develop',
                                    '-p'+self.project_dir, 'aldryn_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)
Exemplo n.º 23
0
    def test_default_config(self):
        conf_data = config.parse([
            '--db=postgres://user:pwd@host/dbname', '-q',
            '-p' + self.project_dir, 'example_prj'
        ])

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

        self.assertEqual(conf_data.cms_version, 2.4)
        self.assertEqual(conf_data.django_version, 1.5)
        self.assertEqual(conf_data.i18n, 'yes')
        self.assertEqual(conf_data.reversion, 'yes')
        self.assertEqual(conf_data.permissions, 'yes')
        self.assertEqual(conf_data.use_timezone, 'yes')
        self.assertEqual(conf_data.db, 'postgres://*****:*****@host/dbname')

        self.assertEqual(conf_data.no_db_driver, False)
        self.assertEqual(conf_data.no_deps, False)
        self.assertEqual(conf_data.no_sync, False)
        self.assertEqual(conf_data.plugins, False)
        self.assertEqual(conf_data.requirements_file, None)
Exemplo n.º 24
0
    def test_cli_config(self):
        conf_data = config.parse([
            '-q', '--db=postgres://user:pwd@host/dbname',
            '--cms-version=develop', '--django-version=1.4', '--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')