Example #1
0
def test_file_data_property(dummy_blobstore, blobstore_settings):
    with blobstore_settings:

        from kotti.resources import File

        data = 'Some test data'
        f1 = File()
        f1.data = data
        id = f1._data
        assert type(id) == str
        assert f1.data == data

        f1._delete()
        assert id not in dummy_blobstore._data
Example #2
0
    def test_multi_delete(self, root):
        from kotti.resources import Document
        from kotti.resources import File
        from kotti.views.edit.actions import NodeActions

        root['child1'] = Document(title="Child 1")
        root['child2'] = Document(title="Child 2")
        root['file1'] = File(title="File 1")

        request = DummyRequest()
        request.POST = MultiDict()
        id1 = str(root['child1'].id)
        id2 = str(root['child2'].id)
        id3 = str(root['file1'].id)
        request.POST.add('delete_nodes', 'delete_nodes')
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash('info') ==\
            ['Nothing was deleted.']

        request.POST.add('children-to-delete', id1)
        request.POST.add('children-to-delete', id2)
        request.POST.add('children-to-delete', id3)
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash('success') == \
            ['${title} was deleted.',
             '${title} was deleted.',
             '${title} was deleted.']
Example #3
0
    def test_multi_delete(self, root):
        from kotti.resources import Document
        from kotti.resources import File
        from kotti.views.edit.actions import NodeActions

        root["child1"] = Document(title="Child 1")
        root["child2"] = Document(title="Child 2")
        root["file1"] = File(title="File 1")

        request = DummyRequest()
        request.POST = MultiDict()
        id1 = str(root["child1"].id)
        id2 = str(root["child2"].id)
        id3 = str(root["file1"].id)
        request.POST.add("delete_nodes", "delete_nodes")
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash("info") == ["Nothing was deleted."]

        request.POST.add("children-to-delete", id1)
        request.POST.add("children-to-delete", id2)
        request.POST.add("children-to-delete", id3)
        NodeActions(root, request).delete_nodes()
        assert request.session.pop_flash("success") == [
            "${title} was deleted.",
            "${title} was deleted.",
            "${title} was deleted.",
        ]
Example #4
0
    def _create_file(self,
                     data=b"file contents",
                     filename="myfüle.png",
                     mimetype="image/png"):
        from kotti.resources import File

        return File(data, filename, mimetype)
Example #5
0
def create_contents(root):
    from kotti.resources import Content, File
    doc1 = root['doc1'] = Content(title=u'First Document')
    doc11 = root['doc1']['doc11'] = Content(title=u'Second Document')
    doc12 = root['doc1']['doc12'] = Content(title=u'Third Document')
    file1 = root['doc1']['file1'] = File(title=u'First File',
                                         description=u'this is a file')
    return doc1, doc11, doc12, file1
Example #6
0
    def _create_content(self, db_session, root, image1, image2):
        data = [
            (b'f1...', 'file1.jpg', 'image/jpeg'),
            (b'f2...', '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, 'image1.jpg', 'image/jpeg'),
            (image1, 'image2.png', 'image/png'),
        ]
        for row in data:
            f = File(data=row[0], filename=row[1], mimetype=row[2])
            root[row[1]] = f

        db_session.flush()
Example #7
0
File: file.py Project: dnouri/Kotti
 def add(self, **appstruct):
     buf = appstruct['file']['fp'].read()
     return File(
         title=appstruct['title'],
         description=appstruct['description'],
         data=buf,
         filename=appstruct['file']['filename'],
         mimetype=appstruct['file']['mimetype'],
         size=len(buf),
         )
Example #8
0
def _create_contents(root):
    from kotti.resources import Content, File

    doc1 = root["doc1"] = Content(title="First Document",
                                  description="I am the first.")
    doc11 = root["doc1"]["doc11"] = Content(title="Second Document",
                                            description="And I am the second.")
    doc12 = root["doc1"]["doc12"] = Content(title="Third Document")
    file1 = root["doc1"]["file1"] = File(title="First File",
                                         description="this is a file")
    return doc1, doc11, doc12, file1
Example #9
0
    def test_tween(self, webtest, filedepot, root, image_asset, db_session):

        from kotti.resources import File
        from kotti.resources import get_root

        # create an image resource
        root['img'] = File(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 '<a href="http://localhost/img/@@attachment-view">' in resp.text

        # test 404
        resp = webtest.app.get('/depot/non_existing/fileid', status=404)
        assert resp.status_code == 404
Example #10
0
    def test_addable_views_registered_to_some_context(self, config, root):

        from kotti.resources import Document, File

        _saved = Document.type_info.addable_to
        Document.type_info.addable_to = ['File']

        config.testing_securitypolicy(permissive=True)
        config.add_view(
            lambda context, request: {},
            name=Document.type_info.add_view,
            permission='add',
            renderer='kotti:templates/edit/node.pt',
            context=File,
        )
        request = DummyRequest()

        assert Document.type_info.addable(Document(), request) is False
        assert Document.type_info.addable(File(), request) is True

        Document.type_info.addable_to = _saved
Example #11
0
def _create_contents_with_tags(root=None):
    from kotti.resources import get_root
    from kotti.resources import Content, File
    if root is None:
        root = get_root()

    animals = root['animals'] = Content(title='Animals')
    cat = root['animals']['cat'] = Content(title='Cat')
    dog = root['animals']['dog'] = Content(title='Dog')
    monkey = root['animals']['monkey'] = Content(title='Monkey')
    gorilla = root['animals']['gorilla'] = Content(title='Gorilla')
    monkey_file = root['animals']['monkey_file'] = File(
        title='Monkey File',
        description='A Rhesus Macaque and a Green Monkey walk into a bar...')

    root['animals']['cat'].tags = ['Animals', 'Cat']
    root['animals']['dog'].tags = ['Animals', 'Dog']
    root['animals']['monkey'].tags = ['Animals', 'Monkey', 'Primate']
    root['animals']['monkey_file'].tags = ['Animals', 'Monkey', 'Primate']
    root['animals']['gorilla'].tags = ['Animals', 'Gorilla', 'Primate']

    return animals, cat, dog, monkey, gorilla, monkey_file
Example #12
0
def _create_contents_with_tags(root=None):
    from kotti.resources import get_root
    from kotti.resources import Content, File

    if root is None:
        root = get_root()

    animals = root["animals"] = Content(title="Animals")
    cat = root["animals"]["cat"] = Content(title="Cat")
    dog = root["animals"]["dog"] = Content(title="Dog")
    monkey = root["animals"]["monkey"] = Content(title="Monkey")
    gorilla = root["animals"]["gorilla"] = Content(title="Gorilla")
    monkey_file = root["animals"]["monkey_file"] = File(
        title="Monkey File",
        description="A Rhesus Macaque and a Green Monkey walk into a bar...",
    )

    root["animals"]["cat"].tags = ["Animals", "Cat"]
    root["animals"]["dog"].tags = ["Animals", "Dog"]
    root["animals"]["monkey"].tags = ["Animals", "Monkey", "Primate"]
    root["animals"]["monkey_file"].tags = ["Animals", "Monkey", "Primate"]
    root["animals"]["gorilla"].tags = ["Animals", "Gorilla", "Primate"]

    return animals, cat, dog, monkey, gorilla, monkey_file
Example #13
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")
Example #14
0
 def _create_file(self, config):
     from kotti.resources import File
     self.file = File("file contents", u"myf\xfcle.png", u"image/png")
Example #15
0
def cachetest_content(root, filedepot):
    image = asset("sendeschluss.jpg")
    root["textfile"] = File(b"file contents", "mytext.txt", "text/plain")
    root["image"] = File(image.read(), "sendeschluss.jpg", "image/jpeg")
Example #16
0
 def setup_method(self, method):
     from kotti.resources import File
     self.file = File("file contents", u"myf\xfcle.png", u"image/png")
Example #17
0
    def make_one(self):
        from kotti.views.edit.content import FileEditForm
        from kotti.resources import File

        return FileEditForm(File(), DummyRequest())
Example #18
0
 def _create_file(self, config):
     from kotti.resources import File
     self.file = File(asset('logo.png').read(), "myfüle.png", "image/png")
Example #19
0
 def _create_file(self,
                  data=b'file contents',
                  filename='myfüle.png',
                  mimetype='image/png'):
     from kotti.resources import File
     return File(data, filename, mimetype)
Example #20
0
def cachetest_content(root, filedepot):
    image = asset('sendeschluss.jpg')
    root['textfile'] = File(b"file contents", 'mytext.txt', 'text/plain')
    root['image'] = File(image.read(), 'sendeschluss.jpg', 'image/jpeg')
Example #21
0
 def setUp(self):
     from kotti.resources import File
     self.file = File("file contents", u"myf\xfcle.png", u"image/png")