コード例 #1
0
    def test_custom_templates_and_themes(self):
        """Users can define their own templates with themes"""
        new_templates_dir = os.path.join(self.temp_usable_dir, 'templates')
        manage_tmpl_file = os.path.join(new_templates_dir,
                                        'manage/custom.py_tmpl')
        repository_tmpl_file = os.path.join(new_templates_dir,
                                            'repository/custom/README')
        script_tmpl_file = os.path.join(new_templates_dir,
                                        'script/custom.py_tmpl')
        sql_script_tmpl_file = os.path.join(new_templates_dir,
                                            'sql_script/custom.py_tmpl')

        MANAGE_CONTENTS = 'print "manage.py"'
        README_CONTENTS = 'MIGRATE README!'
        SCRIPT_FILE_CONTENTS = 'print "script.py"'
        new_repo_dest = self.tmp_repos()
        new_manage_dest = self.tmp_py()

        # make new templates dir
        shutil.copytree(migrate.versioning.templates.__path__[0],
                        new_templates_dir)
        shutil.copytree(os.path.join(new_templates_dir, 'repository/default'),
                        os.path.join(new_templates_dir, 'repository/custom'))

        # edit templates
        f = open(manage_tmpl_file, 'w').write(MANAGE_CONTENTS)
        f = open(repository_tmpl_file, 'w').write(README_CONTENTS)
        f = open(script_tmpl_file, 'w').write(SCRIPT_FILE_CONTENTS)
        f = open(sql_script_tmpl_file, 'w').write(SCRIPT_FILE_CONTENTS)

        # create repository, manage file and python script
        kw = {}
        kw['templates_path'] = new_templates_dir
        kw['templates_theme'] = 'custom'
        api.create(new_repo_dest, 'repo_name', **kw)
        api.script('test', new_repo_dest, **kw)
        api.script_sql('postgres', new_repo_dest, **kw)
        api.manage(new_manage_dest, **kw)

        # assert changes
        self.assertEqual(open(new_manage_dest).read(), MANAGE_CONTENTS)
        self.assertEqual(
            open(os.path.join(new_repo_dest, 'manage.py')).read(),
            MANAGE_CONTENTS)
        self.assertEqual(
            open(os.path.join(new_repo_dest, 'README')).read(),
            README_CONTENTS)
        self.assertEqual(
            open(os.path.join(new_repo_dest, 'versions/001_test.py')).read(),
            SCRIPT_FILE_CONTENTS)
        self.assertEqual(
            open(
                os.path.join(new_repo_dest,
                             'versions/002_postgres_downgrade.sql')).read(),
            SCRIPT_FILE_CONTENTS)
        self.assertEqual(
            open(
                os.path.join(new_repo_dest,
                             'versions/002_postgres_upgrade.sql')).read(),
            SCRIPT_FILE_CONTENTS)
コード例 #2
0
def migrate(engine, meta, repo):
    if not isinstance(repo, basestring):
        repo = abspath(join(*repo))

    try:
        repo_version = v.version(repo)
    except InvalidRepositoryError:
        v.create(repo, 'magic_migrate')
        v.manage(join(repo, 'manage.py'),
                url=str(engine.url),
                repository=repo)
        repo_version = -1

    meta.create_all(bind=engine)
コード例 #3
0
    def test_custom_templates_and_themes(self):
        """Users can define their own templates with themes"""
        new_templates_dir = os.path.join(self.temp_usable_dir, 'templates')
        manage_tmpl_file = os.path.join(new_templates_dir, 'manage/custom.py_tmpl')
        repository_tmpl_file = os.path.join(new_templates_dir, 'repository/custom/README')
        script_tmpl_file = os.path.join(new_templates_dir, 'script/custom.py_tmpl')
        sql_script_tmpl_file = os.path.join(new_templates_dir, 'sql_script/custom.py_tmpl')

        MANAGE_CONTENTS = 'print "manage.py"'
        README_CONTENTS = 'MIGRATE README!'
        SCRIPT_FILE_CONTENTS = 'print "script.py"'
        new_repo_dest = self.tmp_repos()
        new_manage_dest = self.tmp_py()

        # make new templates dir
        shutil.copytree(migrate.versioning.templates.__path__[0], new_templates_dir)
        shutil.copytree(os.path.join(new_templates_dir, 'repository/default'),
            os.path.join(new_templates_dir, 'repository/custom'))

        # edit templates
        f = open(manage_tmpl_file, 'w').write(MANAGE_CONTENTS)
        f = open(repository_tmpl_file, 'w').write(README_CONTENTS)
        f = open(script_tmpl_file, 'w').write(SCRIPT_FILE_CONTENTS)
        f = open(sql_script_tmpl_file, 'w').write(SCRIPT_FILE_CONTENTS)

        # create repository, manage file and python script
        kw = {}
        kw['templates_path'] = new_templates_dir
        kw['templates_theme'] = 'custom'
        api.create(new_repo_dest, 'repo_name', **kw)
        api.script('test', new_repo_dest, **kw)
        api.script_sql('postgres', new_repo_dest, **kw)
        api.manage(new_manage_dest, **kw)

        # assert changes
        self.assertEqual(open(new_manage_dest).read(), MANAGE_CONTENTS)
        self.assertEqual(open(os.path.join(new_repo_dest, 'manage.py')).read(), MANAGE_CONTENTS)
        self.assertEqual(open(os.path.join(new_repo_dest, 'README')).read(), README_CONTENTS)
        self.assertEqual(open(os.path.join(new_repo_dest, 'versions/001_test.py')).read(), SCRIPT_FILE_CONTENTS)
        self.assertEqual(open(os.path.join(new_repo_dest, 'versions/002_postgres_downgrade.sql')).read(), SCRIPT_FILE_CONTENTS)
        self.assertEqual(open(os.path.join(new_repo_dest, 'versions/002_postgres_upgrade.sql')).read(), SCRIPT_FILE_CONTENTS)
コード例 #4
0
ファイル: test_api.py プロジェクト: hgroll/yocto-autobuilder
 def test_manage(self):
     output = api.manage(os.path.join(self.temp_usable_dir, 'manage.py'))
コード例 #5
0
 def test_manage(self):
     output = api.manage(os.path.join(self.temp_usable_dir, 'manage.py'))