def test_delete(self, db_session): file_id = DBFileStorage().create('content here', u'f.jpg', 'image/jpg') fs = DBFileStorage().get(file_id) db_session.add(fs) db_session.flush() assert db_session.query(DBStoredFile.file_id).one()[0] == file_id DBFileStorage().delete(file_id) assert db_session.query(DBStoredFile).count() == 0
def test_replace(self, db_session): file_id = self.make_one() DBFileStorage().replace(file_id, 'second content', u'f2.jpg', 'doc') fs = DBFileStorage().get(file_id) assert fs.filename == u'f2.jpg' assert fs.content_type == 'doc' assert fs.read() == 'second content' DBFileStorage().replace(fs, 'third content', u'f3.jpg', 'xls') assert fs.filename == u'f3.jpg' assert fs.content_type == 'xls' assert fs.read() == 'third content'
def make_one(self, content='content here', filename=u'f.jpg', content_type='image/jpg'): file_id = DBFileStorage().create( content=content, filename=filename, content_type=content_type) return file_id
def make_one( self, content=b"content here", filename="f.jpg", content_type="image/jpg" ): file_id = DBFileStorage().create( content=content, filename=filename, content_type=content_type ) return file_id
def test_replace(self, db_session): file_id = self.make_one() DBFileStorage().replace(file_id, b"second content", "f2.jpg", "doc") fs = DBFileStorage().get(file_id) assert fs.filename == "f2.jpg" assert fs.content_type == "doc" assert fs.read() == b"second content" DBFileStorage().replace(fs, b"third content", "f3.jpg", "xls") assert fs.filename == "f3.jpg" assert fs.content_type == "xls" assert fs.read() == b"third content"
def test_session_integration(self, db_session): from depot.manager import DepotManager DepotManager._default_depot = 'default' DepotManager._depots = {'default': DBFileStorage()} file_id = DepotManager.get().create('content here', u'f.jpg', 'image/jpg') fs = DepotManager.get().get(file_id) db_session.add(fs) import transaction transaction.commit() transaction.begin() db_session.delete(fs) transaction.commit() with pytest.raises(IOError): DepotManager.get().get(file_id)
def test_get(self, db_session): with pytest.raises(IOError): DBFileStorage().get("1") file_id = self.make_one() assert DBFileStorage().get(file_id).data == "content here"
def test_exists(self, db_session): assert DBFileStorage().exists("1") is False file_id = self.make_one() assert DBFileStorage().exists(file_id) is True
def test_list(self): with pytest.raises(NotImplementedError): DBFileStorage().list()