当前位置: 首页>>代码示例>>Python>>正文


Python Submission.process_demo_package方法代码示例

本文整理汇总了Python中demos.models.Submission.process_demo_package方法的典型用法代码示例。如果您正苦于以下问题:Python Submission.process_demo_package方法的具体用法?Python Submission.process_demo_package怎么用?Python Submission.process_demo_package使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在demos.models.Submission的用法示例。


在下文中一共展示了Submission.process_demo_package方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_demo_html_normalized

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_demo_html_normalized(self):
        """Ensure a demo.html in zip file is normalized to index.html when unpacked"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/main.css', 'h1 { color: red }')
        zf.writestr('js/main.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile('%s/index.html' % path))
        ok_(isfile('%s/css/main.css' % path))
        ok_(isfile('%s/js/main.js' % path))

        rmtree(path)
开发者ID:LucianU,项目名称:kuma,代码行数:31,代码来源:test_models.py

示例2: test_demo_deletion

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_demo_deletion(self):
        """Ensure that demo files are deleted along with submission record"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/main.css', 'h1 { color: red }')
        zf.writestr('js/main.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile('%s/index.html' % path))
        ok_(isfile('%s/css/main.css' % path))
        ok_(isfile('%s/js/main.js' % path))

        s.delete()

        ok_(not isfile('%s/index.html' % path))
        ok_(not isfile('%s/css/main.css' % path))
        ok_(not isfile('%s/js/main.js' % path))
        ok_(not isdir(path))
开发者ID:AprilMorone,项目名称:kuma,代码行数:36,代码来源:test_models.py

示例3: test_censored_demo_files_are_deleted

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_censored_demo_files_are_deleted(self):
        """Demo files should be deleted when the demo is censored."""
        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/main.css', 'h1 { color: red }')
        zf.writestr('js/main.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile(s.demo_package.path))
        ok_(isfile('%s/index.html' % path))
        ok_(isfile('%s/css/main.css' % path))
        ok_(isfile('%s/js/main.js' % path))

        s.censor(url="http://example.com/censored-explanation")

        ok_(not isfile(s.demo_package.path))
        ok_(not isfile('%s/index.html' % path))
        ok_(not isfile('%s/css/main.css' % path))
        ok_(not isfile('%s/js/main.js' % path))
        ok_(not isdir(path))
开发者ID:AprilMorone,项目名称:kuma,代码行数:37,代码来源:test_models.py

示例4: test_demo_unicode_filenames

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_demo_unicode_filenames(self):
        """Bug 741660: Demo package containing filenames with non-ASCII
        characters works"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')
        zf.writestr('demo.html', """<html></html""")
        zf.writestr('css/예제.css', 'h1 { color: red }')
        zf.writestr('js/示例.js', 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile((u'%s/index.html' % path).encode('utf-8')))
        ok_(isfile((u'%s/css/예제.css' % path).encode('utf-8')))
        ok_(isfile((u'%s/js/示例.js' % path).encode('utf-8')))

        rmtree(path)
开发者ID:AprilMorone,项目名称:kuma,代码行数:32,代码来源:test_models.py

示例5: test_demo_html_normalized

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_demo_html_normalized(self):
        """Ensure a demo.html in zip file is normalized to index.html when unpacked"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, "w")
        zf.writestr("demo.html", """<html></html""")
        zf.writestr("css/main.css", "h1 { color: red }")
        zf.writestr("js/main.js", 'alert("HELLO WORLD");')
        zf.close()

        s = Submission(
            title="Hello world",
            slug="hello-world",
            description="This is a hello world demo",
            tags="hello,world,demo,play",
            creator=self.user,
        )

        s.demo_package.save("play_demo.zip", ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace(".zip", "")

        ok_(isdir(path))
        ok_(isfile("%s/index.html" % path))
        ok_(isfile("%s/css/main.css" % path))
        ok_(isfile("%s/js/main.js" % path))

        rmtree(path)
开发者ID:fwenzel,项目名称:mdn,代码行数:35,代码来源:tests.py

示例6: test_process_demo_package

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_process_demo_package(self):
        """Calling process_demo_package() should result in a directory of demo files"""

        fout = StringIO()
        zf = zipfile.ZipFile(fout, "w")

        zf.writestr(
            "index.html",
            """<html>
                <head>
                    <link rel="stylesheet" href="css/main.css" type="text/css" />
                </head>
                <body>
                    <h1>Hello world</h1>
                    <script type="text/javascript" src="js/main.js"></script>
                </body>
            </html>""",
        )

        zf.writestr("css/main.css", "h1 { color: red }")

        zf.writestr("js/main.js", 'alert("HELLO WORLD");')

        zf.close()

        s = Submission(
            title="Hello world",
            slug="hello-world",
            description="This is a hello world demo",
            tags="hello,world,demo,play",
            creator=self.user,
        )

        s.demo_package.save("play_demo.zip", ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace(".zip", "")

        ok_(isdir(path))
        ok_(isfile("%s/index.html" % path))
        ok_(isfile("%s/css/main.css" % path))
        ok_(isfile("%s/js/main.js" % path))

        rmtree(path)
开发者ID:fwenzel,项目名称:mdn,代码行数:50,代码来源:tests.py

示例7: test_process_demo_package

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_process_demo_package(self):
        """
        Calling process_demo_package() should result in a directory of demo
        files
        """

        fout = StringIO()
        zf = zipfile.ZipFile(fout, 'w')

        zf.writestr('index.html',
            """<html>
                <head>
                  <link rel="stylesheet" href="css/main.css" type="text/css" />
                </head>
                <body>
                    <h1>Hello world</h1>
                    <script type="text/javascript" src="js/main.js"></script>
                </body>
            </html>""")

        zf.writestr('css/main.css',
            'h1 { color: red }')

        zf.writestr('js/main.js',
            'alert("HELLO WORLD");')

        zf.close()

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile('%s/index.html' % path))
        ok_(isfile('%s/css/main.css' % path))
        ok_(isfile('%s/js/main.js' % path))

        rmtree(path)
开发者ID:AprilMorone,项目名称:kuma,代码行数:49,代码来源:test_models.py

示例8: test_demo_unicode_filenames_2

# 需要导入模块: from demos.models import Submission [as 别名]
# 或者: from demos.models.Submission import process_demo_package [as 别名]
    def test_demo_unicode_filenames_2(self):
        """Bug 741660: Try testing a real .zip with non-ASCII filenames"""
        zip_fn = '%s/fixtures/css3_clock.zip' % dirname(dirname(__file__))

        zf = zipfile.ZipFile(zip_fn)

        s = Submission(title='Hello world', slug='hello-world',
            description='This is a hello world demo',
            creator=self.user)

        s.demo_package.save('play_demo.zip', ContentFile(open(zip_fn).read()))
        s.demo_package.close()
        s.clean()
        s.save()

        s.process_demo_package()

        path = s.demo_package.path.replace('.zip', '')

        ok_(isdir(path))
        ok_(isfile((u'%s/stylé.css' % path).encode('utf-8')))

        rmtree(path)
开发者ID:AprilMorone,项目名称:kuma,代码行数:25,代码来源:test_models.py


注:本文中的demos.models.Submission.process_demo_package方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。