Beispiel #1
0
def test_video_view(db_session):

    root = get_root()
    video = root['video'] = Video()

    view = VideoView(video, DummyRequest()).element()

    assert ('mp4_url' in view)  # and (view['mp4_url'] is None)
    assert ('ogv_url' in view)  # and (view['ogv_url'] is None)
    assert ('webm_url' in view)  # and (view['webm_url'] is None)
    assert ('subtitles_url' in view)  # and (view['subtitles_url'] is None)
    assert ('chapters_url' in view)  # and (view['chapters_url'] is None)
    assert ('poster_url' in view)  # and (view['poster_url'] is None)

    video['mp4'] = Mp4File()
    video['ogv'] = OgvFile()
    video['webm'] = WebmFile()
    video['subs'] = SubtitlesFile()
    video['chapters'] = ChaptersFile()
    video['poster'] = Image()

    view = VideoView(video, DummyRequest()).element()

    assert ('mp4_url' in view)  # and (view['mp4_url'] is None)
    assert ('ogv_url' in view)  # and (view['ogv_url'] is None)
    assert ('webm_url' in view)  # and (view['webm_url'] is None)
    assert ('subtitles_url' in view)  # and (view['subtitles_url'] is None)
    assert ('chapters_url' in view)  # and (view['chapters_url'] is None)
    assert ('poster_url' in view)  # and (view['poster_url'] is None)

    video['mp4'].data = open(os.path.join(here, "distortion.m4v")).read()
    video['ogv'].data = open(os.path.join(here, "distortion.ogv")).read()
    video['webm'].data = open(os.path.join(here, "distortion.webm")).read()
    video['subs'].data = open(os.path.join(here, "distortion.srt")).read()
    video['chapters'].data = open(os.path.join(here, "distortion.srt")).read()
    video['poster'].data = open(os.path.join(here, "distortion.png")).read()

    view = VideoView(video, DummyRequest()).element()

    assert ('mp4_url' in view) and (
        view['mp4_url'] ==
        'http://example.com/video/mp4/@@attachment-view')
    assert ('ogv_url' in view) and (
        view['ogv_url'] ==
        'http://example.com/video/ogv/@@attachment-view')
    assert ('webm_url' in view) and (
        view['webm_url'] ==
        'http://example.com/video/webm/@@attachment-view')
    assert ('subtitles_url' in view) and (
        view['subtitles_url'] ==
        'http://example.com/video/subs/@@attachment-view')
    assert ('chapters_url' in view) and (
        view['chapters_url'] ==
        'http://example.com/video/chapters/@@attachment-view')
    assert ('poster_url' in view) and (
        view['poster_url'] ==
        'http://example.com/video/poster/image')
Beispiel #2
0
def test_audio_view(db_session):

    root = get_root()
    audio = root['audio'] = Audio()

    view = AudioView(audio, DummyRequest()).element()

    assert ('m4a_url' in view) and (view['m4a_url'] is None)
    assert ('mp3_url' in view) and (view['mp3_url'] is None)
    assert ('oga_url' in view) and (view['oga_url'] is None)
    assert ('wav_url' in view) and (view['wav_url'] is None)
    assert ('poster_url' in view) and (view['poster_url'] is None)

    audio['m4a'] = M4aFile()
    audio['mp3'] = Mp3File()
    audio['oga'] = OgaFile()
    audio['wav'] = WavFile()
    audio['poster'] = Image()

    view = AudioView(audio, DummyRequest()).element()
    # import pdb; pdb.set_trace()
    assert ('m4a_url' in view)  # and (view['m4a_url'] is None)
    assert ('mp3_url' in view)  # and (view['mp3_url'] is None)
    assert ('oga_url' in view)  # and (view['oga_url'] is None)
    assert ('wav_url' in view)  # and (view['wav_url'] is None)
    assert ('poster_url' in view)  # and (view['poster_url'] is None)

    audio['m4a'].data = open(os.path.join(here, "distortion.m4a")).read()
    audio['mp3'].data = open(os.path.join(here, "distortion.mp3")).read()
    audio['oga'].data = open(os.path.join(here, "distortion.oga")).read()
    audio['wav'].data = open(os.path.join(here, "distortion.wav")).read()
    audio['poster'].data = open(os.path.join(here, "distortion.png")).read()

    view = AudioView(audio, DummyRequest()).element()

    assert ('m4a_url' in view) and (
        view['m4a_url'] == 'http://example.com/audio/m4a/@@attachment-view')
    assert ('mp3_url' in view) and (
        view['mp3_url'] == 'http://example.com/audio/mp3/@@attachment-view')
    assert ('oga_url' in view) and (
        view['oga_url'] == 'http://example.com/audio/oga/@@attachment-view')
    assert ('wav_url' in view) and (
        view['wav_url'] == 'http://example.com/audio/wav/@@attachment-view')
    assert ('poster_url' in view) and (
        view['poster_url'] == 'http://example.com/audio/poster/image')
Beispiel #3
0
    def add(self, **appstruct):

        buf = appstruct['file']['fp'].read()

        return Image(
            title=appstruct['title'],
            description=appstruct['description'],
            data=buf,
            filename=appstruct['file']['filename'],
            mimetype=appstruct['file']['mimetype'],
            size=len(buf), )
Beispiel #4
0
def test_external_image_list(db_session, dummy_request):
    root = get_root()
    kt = KottiTinyMCE(root, dummy_request)

    res = kt.external_image_list()
    assert res.status_code == 200
    assert res.body == 'var tinyMCEImageList = [];'

    root['image1'] = Image(title=u"Image 1")
    res = kt.external_image_list()
    assert res.status_code == 200
    assert res.body == 'var tinyMCEImageList = ' + \
        '[["/image1/ (Image 1)", "http://example.com/image1/image"]];'

    root['doc'] = Document(title=u"Doc")
    root['image2'] = Image(title=u"Image 2")
    res = kt.external_image_list()
    assert res.status_code == 200
    assert '"/image1/ (Image 1)"' in res.body
    assert '"/image2/ (Image 2)"' in res.body
    assert '"/doc/ (Doc)"' not in res.body
Beispiel #5
0
    def setUp(self):
        from kotti_site_gallery.resources import Site
        self.site = Site('www.frankfurt.de',
                         title=u"Frankfurt",
                         body=u"<b>Foo! The bar.</b>")

        from kotti.resources import Image
        for name in ['foo', 'bar', 'cruz']:
            self.site[name] = Image(name=name, mimetype=u'image/jpeg')

        self.emty_site = Site('www.frankfurt.de',
                              title=u"Frankfurt",
                              body=u"<b>Heyho.</b>")
Beispiel #6
0
def test_external_link_list(db_session, dummy_request):
    root = get_root()
    kt = KottiTinyMCE(root, dummy_request)

    res = kt.external_link_list()
    assert res.status_code == 200
    assert res.body == 'var tinyMCELinkList = [];'

    root['doc'] = Document(title=u"Doc")
    res = kt.external_link_list().body
    assert res == 'var tinyMCELinkList = ' + \
        '[["/doc/ (Doc)", "http://example.com/doc/"]];'

    root['image'] = Image(title=u"Image")
    res = kt.external_link_list()
    assert res.status_code == 200
    assert '["/doc/ (Doc)", "http://example.com/doc/"]' in res.body
    assert '["/image/ (Image)", "http://example.com/image/"]' in res.body
Beispiel #7
0
    def _create_content(self, db_session, root, image1, image2):
        data = [
            ('f1...', u'file1.jpg', 'image/jpeg'),
            ('f2...', u'file2.png', 'image/png'),
        ]
        for row in data:
            f = File(data=row[0], filename=row[1], mimetype=row[2])
            root[row[1]] = f

        data = [
            (image2, u'image1.jpg', 'image/jpeg'),
            (image1, u'image2.png', 'image/png'),
        ]
        for row in data:
            f = Image(data=row[0], filename=row[1], mimetype=row[2])
            root[row[1]] = f

        db_session.flush()
Beispiel #8
0
def test_kottibrowser(db_session, dummy_request):
    root = get_root()

    kt = KottiTinyMCE(root, dummy_request)
    browser = kt.kottibrowser()
    # image_scales do no longer exist as of 0.4
    # assert len(browser['image_scales']) == 12
    # assert browser['image_scales'][0] == \
    #     {'size': [60, 120], 'title': 'span1', 'value': 'span1'}
    assert browser['image_selectable'] is False
    assert browser['image_url'] == 'http://example.com/image/span1'
    assert browser['link_selectable'] is True
    assert browser['upload_allowed'] is True

    image = root['image'] = Image(title=u"Image")
    dummy_request.params['type'] = 'image'
    kt = KottiTinyMCE(image, dummy_request)
    browser = kt.kottibrowser()
    # assert len(browser['image_scales']) == 12
    assert browser['image_selectable'] is True
    assert browser['image_url'] == 'http://example.com/image/image/span1'
    assert browser['link_selectable'] is False
    assert browser['upload_allowed'] is False
Beispiel #9
0
    def test_tween(self, webtest, filedepot, root, image_asset, db_session):

        from kotti.resources import Image, get_root

        # create an image resource
        img = root['img'] = Image(data=image_asset.read(), title='Image')
        db_session.flush()
        root = get_root()
        img = root['img']

        # the image resource itself is served by the full Kotti stack
        resp = webtest.app.get('/img')
        assert resp.content_type == 'text/html'
        assert resp.etag is None
        assert resp.cache_control.max_age == 0
        assert '<img src="http://localhost/img/image" />' in resp.body

        # the attachments (created by the filters) are served by the
        # FiledepotServeApp
        resp = webtest.app.get(img.data[u'thumb_128x128_url'])

        assert resp.etag is not None
        assert resp.cache_control.max_age == 604800
        assert resp.body.startswith('\x89PNG')

        resp = webtest.app.get(img.data[u'thumb_256x256_url'])
        assert resp.etag is not None
        assert resp.cache_control.max_age == 604800
        assert resp.body.startswith('\x89PNG')

        # test 404
        resp = webtest.app.get('/depot/non_existing/fileid', status=404)
        assert resp.status_code == 404

        resp = webtest.app.get(img.data[u'thumb_256x256_url'] + 'not',
                               status=404)
        assert resp.status_code == 404
Beispiel #10
0
def cachetest_content(root, filedepot):
    image = asset('sendeschluss.jpg')
    root['textfile'] = File("file contents", u"mytext.txt", u"text/plain")
    root['image'] = Image(image.read(), u"sendeschluss.jpg", u"image/jpeg")
def populate():

    session = DBSession()

    if session.query(Node).count() == 0:

        root = Document(**_ROOT_ATTRS)
        root.__acl__ = SITE_ACL
        DBSession.add(root)

        root.default_view = u'app'

        wf = get_workflow(root)
        if wf is not None:
            DBSession.flush()  # Initializes workflow
            wf.transition_to_state(root, None, u'public')

        populate_users()

        root_document = \
                session.query(Content).filter(Content.parent_id==None).first()

        fruit_categories_folder = \
                FruitCategoriesFolder(name=u"fruit_categories_folder",
                                      title=u"Fruit Categories Folder",
                                      in_navigation=True,
                                      parent=root_document)

        fruit_categories_folder.__acl__ = SITE_ACL
        session.add(fruit_categories_folder)

        workflow = get_workflow(fruit_categories_folder)
        if workflow:
            DBSession.flush()
            workflow.transition_to_state(fruit_categories_folder, None, u'public')
        else:
            print '################ NO WORKFLOW for ', fruit_categories_folder.title

        folder = \
                session.query(Content).filter_by(
                        name=u"fruit_categories_folder").first()

        fruit_category_instances = {}
        for fruit_category in fruit_categories:
            fruit_category_instances[fruit_category] = \
                FruitCategory(name=fruit_categories[fruit_category]['name'],
                              title=fruit_categories[fruit_category]['name'],
                              parent=folder)

        for key in fruit_category_instances:
            fruit_category_instances[key].__acl__ = SITE_ACL
            session.add(fruit_category_instances[key])

            workflow = get_workflow(fruit_category_instances[key])
            if workflow:
                DBSession.flush()
                workflow.transition_to_state(fruit_category_instances[key], None, u'public')
            else:
                print '################ NO WORKFLOW for ', fruit_category_instances[key].title

        fruit_instances = {}
        for fruit_category in fruit_categories:
            fruit_category_obj = \
                    DBSession.query(FruitCategory).filter_by(
                            title=fruit_category).first()
            for fruit_name in fruit_categories[fruit_category]['fruits']:
                fruit_instances[fruit_name] = \
                    Fruit(**fruit_data_args_dict(fruit_name,
                                                 fruit_category_obj))

        for key in fruit_instances:
            fruit_instances[key].__acl__ = SITE_ACL
            session.add(fruit_instances[key])

            workflow = get_workflow(fruit_instances[key])
            if workflow:
                DBSession.flush()
                workflow.transition_to_state(fruit_instances[key], None, u'public')
            else:
                print '################ NO WORKFLOW for ', fruit_instances[key].title

            # Images have filenames with format: apple.256.jpg. We will use
            # the largest, at 512 pixels, from choices of 32, 64, 128, 256,
            # and 512, and let Kotti handle sizing for thumbnails.
            size = 512
            image_filename = "{0}.{1}.jpg".format(key, size)
            image_path = os.path.join(os.path.dirname(images.__file__),
                                      image_filename)
            image = open(image_path, 'rb').read()
            fruit_instances[key][image_filename] = \
                    Image(image,
                          image_filename,
                          u"image/jpeg",
                          title=image_filename)
            fruit_instances[key][image_filename].__acl__ = SITE_ACL
            session.add(fruit_instances[key][image_filename])


    session.flush()
    transaction.commit()