コード例 #1
0
    def test_edit_existing_rollback(self):
        doc = Document(name=u_('Foo3'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        d = DBSession.query(Document).filter_by(name=u_('Foo3')).first()
        old_file = d.content.path

        d.content = b'HELLO'
        new_file = d.content.path

        DBSession.flush()
        DBSession.rollback()
        DBSession.remove()

        assert get_file(old_file).read() == self.file_content

        try:
            fold = get_file(new_file)
            assert False, 'Should have raised IOError here'
        except IOError:
            pass
コード例 #2
0
ファイル: test_fields_sqlalchemy.py プロジェクト: rlam3/depot
    def test_edit_existing(self):
        doc = Document(name=u_("Foo2"))
        doc.content = open(self.fake_file.name, "rb")
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        d = DBSession.query(Document).filter_by(name=u_("Foo2")).first()
        old_file = d.content.path

        d.content = b"HELLO"
        new_file = d.content.path

        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        assert get_file(new_file).read() == b"HELLO"

        try:
            fold = get_file(old_file)
            assert False, "Should have raised IOError here"
        except IOError:
            pass
コード例 #3
0
    def test_edit_existing(self):
        doc = Document(name=u_('Foo2'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()
        DBSession.remove()

        d = DBSession.query(Document).filter_by(name=u_('Foo2')).first()
        old_file = d.content.path

        d.content = b'HELLO'
        new_file = d.content.path

        self._session_flush()
        DBSession.commit()
        DBSession.remove()

        assert get_file(new_file).read() == b'HELLO'

        try:
            fold = get_file(old_file)
            assert False, 'Should have raised IOError here'
        except IOError:
            pass
コード例 #4
0
    def test_create_empty(self):
        doc = Document(name=u_('Foo'), content=None)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.content is None
コード例 #5
0
    def test_create_empty(self):
        doc = Document(name=u_('Foo'), content=None)
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.content is None
コード例 #6
0
ファイル: test_fields_basic.py プロジェクト: adamchainz/depot
    def test_column_cannot_delete_after_save(self):
        doc = SimpleDocument(name=u_('Foo'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(SimpleDocument).filter_by(name=u_('Foo')).first()
        del d.content['hello']
コード例 #7
0
ファイル: test_fields_basic.py プロジェクト: rmoorman/depot
    def test_column_cannot_edit_attr_after_save(self):
        doc = SimpleDocument(name=u_('Foo'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(SimpleDocument).filter_by(name=u_('Foo')).first()
        d.content.hello = 'Everybody'
コード例 #8
0
ファイル: test_fields_basic.py プロジェクト: adamchainz/depot
    def test_column_cannot_edit_attr_after_save(self):
        doc = SimpleDocument(name=u_('Foo'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(SimpleDocument).filter_by(name=u_('Foo')).first()
        d.content.hello = 'Everybody'
コード例 #9
0
ファイル: test_fields_basic.py プロジェクト: rmoorman/depot
    def test_column_cannot_delete_after_save(self):
        doc = SimpleDocument(name=u_('Foo'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(SimpleDocument).filter_by(name=u_('Foo')).first()
        del d.content['hello']
コード例 #10
0
    def create_file(self, lang='en'):
        fname = {'en': 'hello.txt',
                 'ru': u_('Крупный'),
                 'it': u_('àèìòù')}.get(lang, 'unknown')

        self.UPLOADED_FILES += [DepotManager.get().create(FILE_CONTENT,
                                                          filename=fname)]
        return dict(files=self.UPLOADED_FILES,
                    uploaded_to=DepotManager.get_default(),
                    last=self.UPLOADED_FILES[-1])
コード例 #11
0
ファイル: test_fields_sqlalchemy.py プロジェクト: rlam3/depot
    def test_create_fromfile(self):
        doc = Document(name=u_("Foo"))
        doc.second_photo = open(self.fake_file.name, "rb")
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_("Foo")).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == os.path.basename(self.fake_file.name)
コード例 #12
0
    def test_create_from_bytes(self):
        doc = Document(name=u_('Foo'))
        doc.second_photo = self.file_content
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == 'unknown'
コード例 #13
0
    def test_create_fromfile(self):
        doc = Document(name=u_('Foo'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.content.file.read() == self.file_content
        assert d.content.file.filename == os.path.basename(self.fake_file.name)
コード例 #14
0
    def create_file(self, lang='en'):
        fname = {'en': 'hello.txt',
                 'ru': u_('Крупный'),
                 'it': u_('àèìòù')}.get(lang, 'unknown')

        self.UPLOADED_FILES += [DepotManager.get().create(FILE_CONTENT,
                                                          filename=fname)]
        return dict(files=self.UPLOADED_FILES,
                    uploaded_to=DepotManager.get_default(),
                    last=self.UPLOADED_FILES[-1])
コード例 #15
0
    def test_create_fromfile(self):
        doc = Document(name=u_('Foo'))
        doc.second_photo = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == os.path.basename(self.fake_file.name)
コード例 #16
0
    def test_create_from_bytes(self):
        doc = Document(name=u_('Foo'))
        doc.second_photo = self.file_content
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == 'unnamed'
コード例 #17
0
    def test_create_polymorphic_from_file(self):
        doc = Confidential(name=u_('Secret'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Confidential).filter_by(name=u_('Secret')).first()
        assert d.content.file.read() == self.file_content
        assert d.content.file.filename == os.path.basename(self.fake_file.name)
コード例 #18
0
    def test_create_with_alias(self):
        doc = Document(name=u_('Foo'))
        doc.targeted_content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.targeted_content.file.read() == self.file_content
        assert d.targeted_content.file.filename == os.path.basename(self.fake_file.name)
        assert d.targeted_content.depot_name == 'another'
コード例 #19
0
    def test_create_with_alias(self):
        doc = Document(name=u_('Foo'))
        doc.targeted_content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.targeted_content.file.read() == self.file_content
        assert d.targeted_content.file.filename == os.path.basename(self.fake_file.name)
        assert d.targeted_content.depot_name == 'another'
コード例 #20
0
ファイル: test_fields_basic.py プロジェクト: rmoorman/depot
    def test_column_is_dictlike(self):
        doc = SimpleDocument(name=u_('Foo'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(SimpleDocument).filter_by(name=u_('Foo')).first()
        assert doc.content.hello == 'World', doc.content
        assert 'deleted' not in doc.content, doc.content
        assert doc.content.changed == 'NEW', doc.content
        assert 'deleted_attr' not in doc.content, doc.content
        assert doc.content.missing_attr_trapped == True, doc.content
コード例 #21
0
ファイル: test_fields_sqlalchemy.py プロジェクト: rlam3/depot
    def test_create_fromfield(self):
        field = create_cgifs("image/jpeg", self.fake_file, "test.jpg")

        doc = Document(name=u_("Foo"), content=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_("Foo")).first()
        assert d.content.file.read() == self.file_content
        assert d.content.filename == "test.jpg"
        assert d.content.content_type == "image/jpeg", d.content.content_type
        assert d.content.url == "/depot/%s" % d.content.path
コード例 #22
0
    def test_create_fromfield(self):
        field = create_cgifs('image/jpeg', self.fake_file, 'test.jpg')

        doc = Document(name=u_('Foo'), content=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.content.file.read() == self.file_content
        assert d.content.filename == 'test.jpg'
        assert d.content.content_type == 'image/jpeg', d.content.content_type
        assert d.content.url == '/depot/%s' % d.content.path
コード例 #23
0
    def test_create_fromfield(self):
        field = create_cgifs('image/jpeg', self.fake_file, 'test.jpg')

        doc = Document(name=u_('Foo'), content=field)
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.content.file.read() == self.file_content
        assert d.content.filename == 'test.jpg'
        assert d.content.content_type == 'image/jpeg', d.content.content_type
        assert d.content.url == '/depot/%s' % d.content.path
コード例 #24
0
ファイル: test_fields_basic.py プロジェクト: adamchainz/depot
    def test_column_is_dictlike(self):
        doc = SimpleDocument(name=u_('Foo'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(SimpleDocument).filter_by(name=u_('Foo')).first()
        assert doc.content.hello == 'World', doc.content
        assert 'deleted' not in doc.content, doc.content
        assert doc.content.changed == 'NEW', doc.content
        assert 'deleted_attr' not in doc.content, doc.content
        assert doc.content.missing_attr_trapped == True, doc.content
コード例 #25
0
    def test_serving_files_content_disposition(self):
        app = self.make_app()
        new_file = app.post('/create_file', params={'lang': 'ru'}).json

        uploaded_file = app.get(DepotManager.url_for('%(uploaded_to)s/%(last)s' % new_file))
        content_disposition = uploaded_file.headers['Content-Disposition']
        assert content_disposition == "inline;filename=Krupnyi;filename*=utf-8''%D0%9A%D1%80%D1%83%D0%BF%D0%BD%D1%8B%D0%B9", content_disposition

        new_file = app.post('/create_file', params={'lang': 'it'}).json
        uploaded_file = app.get(DepotManager.url_for('%(uploaded_to)s/%(last)s' % new_file))
        content_disposition = uploaded_file.headers['Content-Disposition']
        _, asciiname, uniname = content_disposition.split(';')
        assert asciiname == 'filename=aeiou', asciiname
        assert u_(unquote(uniname[17:])) == u_('àèìòù'), unquote(uniname[17:])
コード例 #26
0
    def test_thumbnail(self):
        field = create_cgifs('image/gif', self.fake_file, 'test.gif')

        doc = Document(name=u_('Foo'), photo=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert os.path.exists(d.photo.thumb_file._file_path)

        thumb = Image.open(d.photo.thumb_file._file_path)
        thumb.verify()
        assert thumb.format.upper() == d.photo.thumbnail_format.upper()
コード例 #27
0
    def test_thumbnail(self):
        field = create_cgifs('image/gif', self.fake_file, 'test.gif')

        doc = Document(name=u_('Foo'), photo=field)
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert os.path.exists(d.photo.thumb_file._file_path)

        thumb = Image.open(d.photo.thumb_file._file_path)
        thumb.verify()
        assert thumb.format.upper() == d.photo.thumbnail_format.upper()
コード例 #28
0
    def test_serving_files_content_disposition(self):
        app = self.make_app()
        new_file = app.post('/create_file', params={'lang': 'ru'}).json

        uploaded_file = app.get(DepotManager.url_for('%(uploaded_to)s/%(last)s' % new_file))
        content_disposition = uploaded_file.headers['Content-Disposition']
        assert content_disposition == "inline;filename=\"Krupnyi\";filename*=utf-8''%D0%9A%D1%80%D1%83%D0%BF%D0%BD%D1%8B%D0%B9", content_disposition

        new_file = app.post('/create_file', params={'lang': 'it'}).json
        uploaded_file = app.get(DepotManager.url_for('%(uploaded_to)s/%(last)s' % new_file))
        content_disposition = uploaded_file.headers['Content-Disposition']
        _, asciiname, uniname = content_disposition.split(';')
        assert asciiname == 'filename="aeiou"', asciiname
        assert u_(unquote(uniname[17:])) == u_('àèìòù'), unquote(uniname[17:])
コード例 #29
0
    def test_create_fileintent(self):
        field = FileIntent(open(self.fake_file.name, 'rb'), u_('àèìòù.gif'), 'image/gif')

        doc = Document(name=u_('Foo'), second_photo=field)
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == field._filename
        assert d.second_photo.url == '/depot/%s' % d.second_photo.path
        assert d.second_photo.thumb_12x12_url == '/depot/%s' % d.second_photo.thumb_12x12_path
        assert d.second_photo.url != d.second_photo.thumb_12x12_url
        assert d.second_photo.content_type == field._content_type
コード例 #30
0
    def test_create_fileintent(self):
        field = FileIntent(open(self.fake_file.name, 'rb'), u_('àèìòù.gif'), 'image/gif')

        doc = Document(name=u_('Foo'), second_photo=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == field._filename
        assert d.second_photo.url == '/depot/%s' % d.second_photo.path
        assert d.second_photo.thumb_url == '/depot/%s' % d.second_photo.thumb_path
        assert d.second_photo.url != d.second_photo.thumb_url
        assert d.second_photo.content_type == field._content_type
コード例 #31
0
ファイル: test_fields_ming.py プロジェクト: vlcinsky/depot
    def test_create_fromfield(self):
        field = cgi.FieldStorage()
        field.filename = u_('àèìòù.gif')
        field.file = open(self.fake_file.name, 'rb')

        doc = Document(name=u_('Foo'), second_photo=field)
        DBSession.flush()
        DBSession.clear()

        d = Document.query.find(dict(name='Foo')).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == field.filename
        assert d.second_photo.url == '/depot/%s' % d.second_photo.path
        assert d.second_photo.thumb_12x12_url == '/depot/%s' % d.second_photo.thumb_12x12_path
        assert d.second_photo.url != d.second_photo.thumb_12x12_url
コード例 #32
0
    def test_create_fromfield(self):
        field = cgi.FieldStorage()
        field.filename = u_('àèìòù.gif')
        field.file = open(self.fake_file.name, 'rb')

        doc = Document(name=u_('Foo'), photo=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.photo.file.read() == self.file_content
        assert d.photo.filename == field.filename
        assert d.photo.url == '/depot/%s' % d.photo.path
        assert d.photo.thumb_url == '/depot/%s' % d.photo.thumb_path
        assert d.photo.url != d.photo.thumb_url
コード例 #33
0
ファイル: test_fields_ming.py プロジェクト: vlcinsky/depot
    def test_create_empty(self):
        doc = Document(name=u_('Foo'), content=None)
        DBSession.flush()
        DBSession.clear()

        d = Document.query.find(dict(name='Foo')).first()
        assert d.content is None
コード例 #34
0
    def test_create_fromfield(self):
        field = cgi.FieldStorage()
        field.filename = u_('àèìòù.gif')
        field.file = open(self.fake_file.name, 'rb')

        doc = Document(name=u_('Foo'), photo=field)
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()
        assert d.photo.file.read() == self.file_content
        assert d.photo.filename == field.filename
        assert d.photo.url == '/depot/%s' % d.photo.path
        assert d.photo.thumb_url == '/depot/%s' % d.photo.thumb_path
        assert d.photo.url != d.photo.thumb_url
コード例 #35
0
    def test_maximum_size(self):
        field = create_cgifs('image/png', self.bigimage, 'test.png')

        doc = Document(name=u_('Foo'), photo=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()

        img = Image.open(d.photo.file._file_path)
        img.verify()
        assert img.format.upper() == 'PNG'
        assert max(img.size) == 1024
        assert d.photo.filename == field.filename
        assert d.photo.content_type == 'image/png'
コード例 #36
0
 def test_storage_does_not_exists(self):
     doc = SimpleDocument(name=u_('Foo'))
     doc.content = UploadedFile(open(self.fake_file.name, 'rb'),
                                'missing_storage')
     DBSession.add(doc)
     DBSession.flush()
     DBSession.commit()
コード例 #37
0
    def test_maximum_size(self):
        field = create_cgifs('image/png', self.bigimage, 'test.png')

        doc = Document(name=u_('Foo'), photo=field)
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()

        img = Image.open(d.photo.file._file_path)
        img.verify()
        assert img.format.upper() == 'PNG'
        assert max(img.size) == 1024
        assert d.photo.filename == field.filename
        assert d.photo.content_type == 'image/png'
コード例 #38
0
ファイル: test_fields_sqlalchemy.py プロジェクト: rlam3/depot
    def test_create_fromfield(self):
        field = cgi.FieldStorage()
        field.filename = u_("àèìòù.gif")
        field.file = open(self.fake_file.name, "rb")

        doc = Document(name=u_("Foo"), second_photo=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_("Foo")).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == field.filename
        assert d.second_photo.url == "/depot/%s" % d.second_photo.path
        assert d.second_photo.thumb_12x12_url == "/depot/%s" % d.second_photo.thumb_12x12_path
        assert d.second_photo.url != d.second_photo.thumb_12x12_url
コード例 #39
0
ファイル: test_fields_basic.py プロジェクト: adamchainz/depot
 def test_storage_does_not_exists(self):
     doc = SimpleDocument(name=u_('Foo'))
     doc.content = UploadedFile(open(self.fake_file.name, 'rb'),
                                'missing_storage')
     DBSession.add(doc)
     DBSession.flush()
     DBSession.commit()
コード例 #40
0
    def test_delete_existing_rollback(self):
        doc = Document(name=u_('Foo3'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        d = DBSession.query(Document).filter_by(name=u_('Foo3')).first()
        old_file = d.content.path
        DBSession.delete(d)

        DBSession.flush()
        DBSession.rollback()
        DBSession.remove()

        assert get_file(old_file).read() == self.file_content
コード例 #41
0
    def test_public_url(self):
        doc = Document(name=u_('Foo'))
        doc.second_photo = open(self.fake_file.name, 'rb')
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()

        # Hack to force object to have a public url
        d.second_photo._thaw()
        d.second_photo['_public_url'] = 'PUBLIC_URL'
        d.second_photo._freeze()

        assert d.second_photo.url == 'PUBLIC_URL'
        assert d.second_photo.thumb_url.startswith('/depot/default/')
コード例 #42
0
ファイル: test_fields_sqlalchemy.py プロジェクト: rlam3/depot
    def test_public_url(self):
        doc = Document(name=u_("Foo"))
        doc.second_photo = open(self.fake_file.name, "rb")
        doc.content = open(self.fake_file.name, "rb")
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_("Foo")).first()

        # Hack to force object to have a public url
        d.second_photo._thaw()
        d.second_photo["_public_url"] = "PUBLIC_URL"
        d.second_photo._freeze()

        assert d.second_photo.url == "PUBLIC_URL"
        assert d.second_photo.thumb_12x12_url.startswith("/depot/default/")
コード例 #43
0
    def test_thumbnail(self):
        field = create_cgifs('image/gif', self.fake_file, 'test.gif')

        doc = Document(name=u_('Foo'), second_photo=field)
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()

        thumbnail_local_path = DepotManager.get_file(d.second_photo.thumb_path)._file_path
        assert os.path.exists(thumbnail_local_path)

        thumb = Image.open(thumbnail_local_path)
        thumb.verify()
        assert thumb.format.upper() == 'PNG'
        assert max(thumb.size) == 12
コード例 #44
0
    def test_thumbnail(self):
        field = create_cgifs('image/gif', self.fake_file, 'test.gif')

        doc = Document(name=u_('Foo'), second_photo=field)
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()

        thumbnail_local_path = DepotManager.get_file(d.second_photo.thumb_12x12_path)._file_path
        assert os.path.exists(thumbnail_local_path)

        thumb = Image.open(thumbnail_local_path)
        thumb.verify()
        assert thumb.format.upper() == 'PNG'
        assert max(thumb.size) == 12
コード例 #45
0
    def test_public_url(self):
        doc = Document(name=u_('Foo'))
        doc.second_photo = open(self.fake_file.name, 'rb')
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()

        # Hack to force object to have a public url
        d.second_photo._thaw()
        d.second_photo['_public_url'] = 'PUBLIC_URL'
        d.second_photo._freeze()

        assert d.second_photo.url == 'PUBLIC_URL'
        assert d.second_photo.thumb_12x12_url.startswith('/depot/default/')
コード例 #46
0
    def test_delete_existing_rollback(self):
        doc = Document(name=u_('Foo3'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        self._session_flush()
        DBSession.commit()
        DBSession.remove()

        d = DBSession.query(Document).filter_by(name=u_('Foo3')).first()
        old_file = d.content.path
        DBSession.delete(d)

        self._session_flush()
        DBSession.rollback()
        DBSession.remove()

        assert get_file(old_file).read() == self.file_content
コード例 #47
0
    def test_relationship_cascade_delete_rollback(self):
        directory = Directory(name='Parent')
        DBSession.add(directory)
        directory.documents.append(
            Document(name=u_('Foo'), content=open(self.fake_file.name, 'rb')))
        self._session_flush()
        DBSession.commit()

        d = DBSession.query(Directory).filter_by(name=u_('Parent')).first()
        doc = d.documents[0]
        old_file = doc.content.path
        assert self.file_exists(old_file)

        DBSession.delete(d)
        self._session_flush()
        DBSession.rollback()

        assert self.file_exists(old_file)
コード例 #48
0
ファイル: test_fields_ming.py プロジェクト: vlcinsky/depot
    def test_create_fromfile(self):
        doc = Document(name=u_('Foo'))
        doc.second_photo = open(self.fake_file.name, 'rb')
        DBSession.flush()
        DBSession.clear()

        d = Document.query.find(dict(name='Foo')).first()
        assert d.second_photo.file.read() == self.file_content
        assert d.second_photo.filename == os.path.basename(self.fake_file.name)
コード例 #49
0
    def test_public_url(self):
        doc = Document(name=u_('Foo'))
        doc.photo = open(self.fake_file.name, 'rb')
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()

        d = DBSession.query(Document).filter_by(name=u_('Foo')).first()

        # Hack to force object to have a public url
        d.photo._thaw()
        d.photo['_public_url'] = 'PUBLIC_URL'
        d.photo['_thumb_public_url'] = 'THUMB_PUBLIC_URL'
        d.photo._freeze()

        assert d.photo.url == 'PUBLIC_URL'
        assert d.photo.thumb_url == 'THUMB_PUBLIC_URL'
コード例 #50
0
ファイル: test_fields_ming.py プロジェクト: chatid/depot
    def test_delete_existing_rollback(self):
        doc = Document(name=u_('Foo3'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.flush()
        DBSession.clear()

        d = Document.query.find(dict(name='Foo3')).first()
        old_file = d.content.path
        d.delete()
        DBSession.clear()

        assert get_file(old_file).read() == self.file_content
コード例 #51
0
ファイル: test_fields_ming.py プロジェクト: vlcinsky/depot
    def test_create_fromfield(self):
        field = create_cgifs('image/jpeg', self.fake_file, 'test.jpg')

        doc = Document(name=u_('Foo'), content=field)
        DBSession.flush()
        DBSession.clear()

        d = Document.query.find(dict(name='Foo')).first()
        assert d.content.file.read() == self.file_content
        assert d.content.filename == 'test.jpg'
        assert d.content.content_type == 'image/jpeg', d.content.content_type
        assert d.content.url == '/depot/%s' % d.content.path
コード例 #52
0
    def test_delete_existing(self):
        doc = Document(name=u_('Foo2'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        d = DBSession.query(Document).filter_by(name=u_('Foo2')).first()
        old_file = d.content.path
        DBSession.delete(d)

        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        try:
            fold = get_file(old_file)
            assert False, 'Should have raised IOError here'
        except IOError:
            pass
コード例 #53
0
    def test_check_assigned_type(self):
        doc = Document(name=u_('Foo'))
        doc.photo = UploadedFile(open(self.fake_file.name, 'rb'))
        DBSession.add(doc)

        try:
            DBSession.flush()
        except StatementError as e:
            assert 'ValueError' in str(e)
            return

        assert False, 'FLUSH did not raise exception'
コード例 #54
0
    def test_check_assigned_type(self):
        doc = Document(name=u_('Foo'))
        doc.photo = UploadedFile(open(self.fake_file.name, 'rb'))
        DBSession.add(doc)

        try:
            DBSession.flush()
        except StatementError as e:
            assert 'ValueError' in str(e)
            return

        assert False, 'FLUSH did not raise exception'
コード例 #55
0
    def test_delete_existing(self):
        doc = Document(name=u_('Foo2'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        d = DBSession.query(Document).filter_by(name=u_('Foo2')).first()
        old_file = d.content.path
        DBSession.delete(d)

        DBSession.flush()
        DBSession.commit()
        DBSession.remove()

        try:
            fold = get_file(old_file)
            assert False, 'Should have raised IOError here'
        except IOError:
            pass
コード例 #56
0
ファイル: test_fields_ming.py プロジェクト: adamchainz/depot
    def test_delete_existing_rollback(self):
        doc = Document(name=u_('Foo3'))
        doc.content = open(self.fake_file.name, 'rb')
        DBSession.flush()
        DBSession.clear()


        d = Document.query.find(dict(name='Foo3')).first()
        old_file = d.content.path
        d.delete()
        DBSession.clear()

        assert get_file(old_file).read() == self.file_content
コード例 #57
0
    def test_rollback(self):
        doc = Document(name=u_('Foo3'))
        doc.second_photo = open(self.fake_file.name, 'rb')
        DBSession.add(doc)
        self._session_flush()

        uploaded_file = doc.second_photo.path
        uploaded_thumb = doc.second_photo.thumb_12x12_path

        DBSession.rollback()
        DBSession.remove()

        assert not self.file_exists(uploaded_file)
        assert not self.file_exists(uploaded_thumb)