Ejemplo n.º 1
0
    def test_folder_indexed(self):
        folder = Folder(title=u'Folder 1', parent=self.community.folder)
        self.session.add(folder)
        folder_other = Folder(title=u'Folder 2: other', parent=self.c2.folder)
        self.session.add(folder_other)
        self.session.commit()

        svc = self.svc
        obj_types = (Folder.entity_type,)
        with self.login(self.user_no_community):
            res = svc.search(u'folder', object_types=obj_types)
            assert len(res) == 0

        with self.login(self.user):
            res = svc.search(u'folder', object_types=obj_types)
            assert len(res) == 1
            hit = res[0]
            assert hit['object_key'] == folder.object_key
            assert hit['community_slug'] == self.community.slug

        with self.login(self.user_c2):
            res = svc.search(u'folder', object_types=obj_types)
            assert len(res) == 1
            hit = res[0]
            assert hit['object_key'] == folder_other.object_key
            assert hit['community_slug'] == self.c2.slug
Ejemplo n.º 2
0
    def test_document_is_clonable(self):
        root = Folder(title="/")
        doc = root.create_document(title="toto")
        doc.content = "tototiti"

        clone = doc.clone()
        assert clone.title == doc.title
Ejemplo n.º 3
0
def test_folder_can_create_subfolders():
    root = Folder(title="/")

    subfolder = root.create_subfolder("folder")
    assert len(root.children) == 1
    assert subfolder.title == "folder"
    assert subfolder.path == "/folder"
    assert subfolder in root.subfolders
    assert subfolder in root.children
    assert subfolder.parent == root
Ejemplo n.º 4
0
def test_folder_can_create_documents():
    root = Folder(title="/")

    document = root.create_document("doc")

    assert len(root.children) == 1
    assert document.title == "doc"
    assert document.path == "/doc"
    assert document in root.documents
    assert document in root.children
    assert document.parent == root
Ejemplo n.º 5
0
def test_title_prevails():
    f = Folder(name="name", title="title")
    assert f.title == "title"
    assert f.name == "title"

    f = Folder(name="name", title=None)
    assert f.title == "name"
    assert f.name == "name"

    f = Folder(name="name")
    assert f.title == "name"
    assert f.name == "name"
Ejemplo n.º 6
0
def test_title_prevails():
    f = Folder(name=u'name', title=u'title')
    assert f.title == u'title'
    assert f.name == u'title'

    f = Folder(name=u'name', title=None)
    assert f.title == u'name'
    assert f.name == u'name'

    f = Folder(name=u'name')
    assert f.title == u'name'
    assert f.name == u'name'
Ejemplo n.º 7
0
    def test_document(self):
        root = Folder(title=u"root")
        doc = Document(parent=root, title=u"test")
        data = self.open_file("onepage.pdf").read()
        doc.set_content(data, "application/pdf")
        self.session.add(doc)
        self.session.commit()

        # coverage
        self.app.config['ANTIVIRUS_CHECK_REQUIRED'] = True
        doc.ensure_antivirus_scheduled()
Ejemplo n.º 8
0
def test_nested_subobjects():
    root = Folder(title="/")
    subfolder = root.create_subfolder("folder1")
    subsubfolder = subfolder.create_subfolder("folder2")
    document = subfolder.create_document("doc")

    assert len(root.children) == 1
    assert len(subfolder.children) == 2
    assert subsubfolder.title == "folder2"
    assert subsubfolder.path == "/folder1/folder2"
    assert document.title == "doc"
    assert document.path == "/folder1/doc"

    assert root.get_object_by_path("/folder1") == subfolder
    assert root.get_object_by_path("/folder1/folder2") == subsubfolder
    assert root.get_object_by_path("/folder1/doc") == document
Ejemplo n.º 9
0
    def test_zip_upload_uncompress(self):
        folder = Folder(title=u'folder 1', parent=self.community.folder)
        self.session.add(folder)
        self.session.flush()
        folder = self.community.folder
        files = []
        files.append((BytesIO(b'A document'), u'existing-doc', 'text/plain'))
        files.append((self.open_file('content.zip'), u'content.zip',
                      'application/zip'))
        data = {'file': files, 'action': 'upload', 'uncompress_files': True}
        url = url_for(
            "documents.folder_post",
            community_id=self.community.slug,
            folder_id=folder.id)
        with self.client_login(self.user.email, password='******'):
            response = self.client.post(url, data=data)

        expected = {u'existing-doc', u'folder 1', u'existing-doc-1'}
        self.assert_status(response, 302)
        assert expected == {f.title for f in folder.children}
        expected = {u'folder 1', u'existing-doc-1'}
        assert expected == {f.title for f in folder.subfolders}
Ejemplo n.º 10
0
def root(session):
    # type: (Any) -> Folder
    root = Folder(title="")
    session.add(root)
    session.flush()
    return root
Ejemplo n.º 11
0
def test_folder_is_clonable():
    root = Folder(title="/")
    clone = root.clone()

    assert clone.title == root.title
    assert clone.path == root.path
Ejemplo n.º 12
0
def test_folder_editables():
    root = Folder(title="/")
    check_editable(root)
Ejemplo n.º 13
0
def test_document_has_an_icon(app_context):
    root = Folder(title="/")
    doc = root.create_document(title="toto")
    doc.content_type = "image/jpeg"
    filename = doc.icon.split("/")[-1]
    assert filename in ("jpg.png", "jpeg.png"), doc.icon
Ejemplo n.º 14
0
    def test_antivirus_properties(self):
        root = Folder(title=u"root")
        doc = Document(parent=root, title=u"test")
        doc.set_content('content', 'text/plain')
        appcfg = self.app.config
        meta = doc.content_blob.meta

        # 1: not check required ################
        # no data in meta
        appcfg['ANTIVIRUS_CHECK_REQUIRED'] = False
        assert doc.antivirus_scanned is False
        assert doc.antivirus_status is None
        assert doc.antivirus_required is False
        assert doc.antivirus_ok is True

        # antivirus was run, but no result
        meta['antivirus'] = None
        assert doc.antivirus_scanned is True
        assert doc.antivirus_status is None
        assert doc.antivirus_required is False
        assert doc.antivirus_ok is True

        # virus detected
        meta['antivirus'] = False
        assert doc.antivirus_scanned is True
        assert doc.antivirus_status is False
        assert doc.antivirus_required is False
        assert doc.antivirus_ok is False

        # virus free
        meta['antivirus'] = True
        assert doc.antivirus_scanned is True
        assert doc.antivirus_status is True
        assert doc.antivirus_required is False
        assert doc.antivirus_ok is True

        # 2: check required ##################
        # no data in meta
        del meta['antivirus']
        appcfg['ANTIVIRUS_CHECK_REQUIRED'] = True
        assert doc.antivirus_scanned is False
        assert doc.antivirus_status is None
        assert doc.antivirus_required is True
        assert doc.antivirus_ok is False

        # antivirus was run, but no result
        meta['antivirus'] = None
        assert doc.antivirus_scanned is True
        assert doc.antivirus_status is None
        assert doc.antivirus_required is True
        assert doc.antivirus_ok is False

        # virus detected
        meta['antivirus'] = False
        assert doc.antivirus_scanned is True
        assert doc.antivirus_status is False
        assert doc.antivirus_required is False
        assert doc.antivirus_ok is False

        # virus free
        meta['antivirus'] = True
        assert doc.antivirus_scanned is True
        assert doc.antivirus_status is True
        assert doc.antivirus_required is False
        assert doc.antivirus_ok is True
Ejemplo n.º 15
0
    def setUp(self):
        super(BaseTests, self).setUp()

        self.root_folder = Folder(title=u"root")
        db.session.add(self.root_folder)
        db.session.flush()