예제 #1
0
    def test_storedfile_interface(self, db_session, events, setup_app):
        f = DBStoredFile('fileid', filename=u'f.jpg', content_type='image/jpeg',
                         content_length=1000, data='content')

        assert f.close() is None
        assert f.closed() is False
        assert f.seekable() is True
        assert f.writable() is False

        assert f.read() == 'content'
        assert f.read() == ''
        f.seek(0)
        assert f.read() == 'content'
        f.seek(0)
        assert f.read(-1) == 'content'
        f.seek(0)
        assert f.read(2) == 'co'
        assert f.read(4) == 'nten'
        assert f.tell() == 6
        f.seek(0)
        f.seek(100)
        assert f.tell() == 100
        assert f.read() == ''

        assert f.content_length == 1000
        assert f.content_type == 'image/jpeg'
        assert f.file_id == 'fileid'
        assert f.filename == u'f.jpg'
        assert f.name == u"f.jpg"
        assert f.public_url is None

        f.data = None
        db_session.add(f)
        db_session.flush()
        assert f.content_length == 0
예제 #2
0
    def test_storedfile_interface(self, db_session, events, setup_app):
        f = DBStoredFile('fileid', filename=u'f.jpg', content_type='image/jpeg',
                         content_length=1000, data='content')

        assert f.close() is None
        assert f.closed() is False
        assert f.seekable() is True
        assert f.writable() is False

        assert f.read() == 'content'
        assert f.read() == ''
        f.seek(0)
        assert f.read() == 'content'
        f.seek(0)
        assert f.read(-1) == 'content'
        f.seek(0)
        assert f.read(2) == 'co'
        assert f.read(4) == 'nten'
        assert f.tell() == 6
        f.seek(0)
        f.seek(100)
        assert f.tell() == 100
        assert f.read() == ''

        assert f.content_length == 1000
        assert f.content_type == 'image/jpeg'
        assert f.file_id == 'fileid'
        assert f.filename == u'f.jpg'
        assert f.name == u"f.jpg"
        assert f.public_url is None

        f.data = None
        db_session.add(f)
        db_session.flush()
        assert f.content_length == 0
예제 #3
0
    def test_content_length(self, db_session, events, setup_app):
        f = DBStoredFile('fileid', data="content")
        db_session.add(f)
        db_session.flush()

        assert f.content_length == 7

        f.data = 'content changed'
        db_session.flush()

        assert f.content_length == len('content changed')
예제 #4
0
    def test_content_length(self, db_session, events, setup_app):
        f = DBStoredFile('fileid', data="content")
        db_session.add(f)
        db_session.flush()

        assert f.content_length == 7

        f.data = 'content changed'
        db_session.flush()

        assert f.content_length == len('content changed')
예제 #5
0
    def test_content_length(self, db_session, events, setup_app):
        f = DBStoredFile("fileid", data=b"content")
        db_session.add(f)
        db_session.flush()

        assert f.content_length == 7

        f.data = b"content changed"
        db_session.flush()

        assert f.content_length == len(b"content changed")
예제 #6
0
    def test_storedfile_interface(self, db_session, events, setup_app):
        f = DBStoredFile(
            "fileid",
            filename="f.jpg",
            content_type="image/jpeg",
            content_length=1000,
            data=b"content",
        )

        assert f.close() is None
        assert f.closed() is False
        assert f.seekable() is True
        assert f.writable() is False

        assert f.read() == b"content"
        assert f.read() == b""
        f.seek(0)
        assert f.read() == b"content"
        f.seek(0)
        assert f.read(-1) == b"content"
        f.seek(0)
        assert f.read(2) == b"co"
        assert f.read(4) == b"nten"
        assert f.tell() == 6
        f.seek(0)
        f.seek(100)
        assert f.tell() == 100
        assert f.read() == b""

        assert f.content_length == 1000
        assert f.content_type == "image/jpeg"
        assert f.file_id == "fileid"
        assert f.filename == "f.jpg"
        assert f.name == "f.jpg"
        assert f.public_url is None

        f.data = None
        db_session.add(f)
        db_session.flush()
        assert f.content_length == 0
예제 #7
0
    def test_last_modified(self, monkeypatch, db_session, events, setup_app):
        from kotti import filedepot

        now = datetime.datetime.now()

        class mockdatetime:
            @staticmethod
            def now():
                return now

        monkeypatch.setattr(filedepot, 'datetime', mockdatetime)

        f = DBStoredFile('fileid', data="content")
        db_session.add(f)
        db_session.flush()

        assert f.last_modified == now

        f.last_modified = None
        f.data = 'content changed'
        db_session.flush()

        assert f.last_modified == now
예제 #8
0
    def test_last_modified(self, monkeypatch, db_session, events, setup_app):
        from kotti import filedepot

        now = datetime.datetime.now()

        class mockdatetime:
            @staticmethod
            def now():
                return now

        monkeypatch.setattr(filedepot, 'datetime', mockdatetime)

        f = DBStoredFile('fileid', data="content")
        db_session.add(f)
        db_session.flush()

        assert f.last_modified == now

        f.last_modified = None
        f.data = 'content changed'
        db_session.flush()

        assert f.last_modified == now