Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
    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))
Exemple #5
0
    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)
Exemple #6
0
    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))
Exemple #7
0
    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)
Exemple #8
0
    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))
Exemple #9
0
    def _build_hidden_submission(self, slug):
        now = str(datetime.datetime.now())

        s = Submission(title='Hidden submission 1' + now, slug=slug + now,
            description='This is a hidden demo', hidden=True,
            creator=self.other_user)
        s.save()

        return s
Exemple #10
0
def build_submission(creator):
    now = str(datetime.datetime.now())

    s = Submission(title='Hello world' + now, slug='hello-world' + now,
        description='This is a hello world demo', hidden=False,
        creator=creator)
    s.save()

    return s
Exemple #11
0
def build_hidden_submission(creator, slug='hidden-world'):
    now = str(datetime.datetime.now())

    s = Submission(title='Hidden submission 1' + now, slug=slug + now,
        description='This is a hidden demo', hidden=True,
        creator=creator)
    s.save()

    return s
Exemple #12
0
def save_valid_submission(title="hello world", desc="This is a hello world demo"):
    testuser = User.objects.get(username="******")
    s = Submission(title=title, slug=slugify(title), description=desc, summary=desc, creator=testuser)
    fout = StringIO()
    zf = zipfile.ZipFile(fout, "w")
    zf.writestr("index.html", """<html> </html>""")
    zf.close()
    s.demo_package.save("play_demo.zip", ContentFile(fout.getvalue()))
    s.screenshot_1.save(
        "screenshot_1.jpg", ContentFile(open("%s/fixtures/screenshot_1.png" % (dirname(dirname(__file__)),)).read())
    )
    s.save()
    return s
Exemple #13
0
def build_submission(creator):
    now = str(datetime.datetime.now())

    s = Submission(
        title="Hello world" + now,
        slug="hello-world" + now,
        description="This is a hello world demo",
        hidden=False,
        creator=creator,
    )
    s.save()

    return s
Exemple #14
0
def build_hidden_submission(creator, slug="hidden-world"):
    now = str(datetime.datetime.now())

    s = Submission(
        title="Hidden submission 1" + now,
        slug=slug + now,
        description="This is a hidden demo",
        hidden=True,
        creator=creator,
    )
    s.save()

    return s
Exemple #15
0
def save_valid_submission(title='hello world'):
    testuser = User.objects.get(username='******')
    s = Submission(title=title, slug=slugify(title),
        description='This is a hello world demo',
        creator=testuser)
    fout = StringIO()
    zf = zipfile.ZipFile(fout, 'w')
    zf.writestr('index.html', """<html> </html>""")
    zf.close()
    s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
    s.screenshot_1.save('screenshot_1.jpg', ContentFile(open(
        '%s/fixtures/screenshot_1.png' % ( dirname(dirname(__file__)), ) ).read()))
    s.save()
    return s
Exemple #16
0
    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)
Exemple #17
0
    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)
Exemple #18
0
    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)
Exemple #19
0
    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)
Exemple #20
0
    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))
Exemple #21
0
    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)