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
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
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
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
def test_edit_existing(self): doc = Document(name=u_('Foo2')) doc.content = open(self.fake_file.name, 'rb') DBSession.flush() DBSession.clear() d = Document.query.find(dict(name='Foo2')).first() old_file = d.content.path d.content = b'HELLO' new_file = d.content.path DBSession.flush() DBSession.clear() assert get_file(new_file).read() == b'HELLO' try: fold = get_file(old_file) assert False, 'Should have raised IOError here' except IOError: pass
def test_rollback(self): raise SkipTest("Currently Ming Doesn't provide a way to handle discarded documents") doc = Document(name=u_('Foo3')) doc.second_photo = open(self.fake_file.name, 'rb') uploaded_file = doc.second_photo.path uploaded_thumb = doc.second_photo.thumb_12x12_path DBSession.clear() try: fold = get_file(uploaded_file) assert False, 'Should have raised IOError here' except IOError: pass try: fold = get_file(uploaded_thumb) assert False, 'Should have raised IOError here' except IOError: pass
def test_edit_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.content = b'HELLO' new_file = d.content.path DBSession.clear() assert get_file(old_file).read() == self.file_content raise SkipTest("Currently Ming Doesn't provide a way to handle discarded documents") try: fold = get_file(new_file) assert False, 'Should have raised IOError here' except IOError: pass
def test_rollback(self): doc = Document(name=u_('Foo3')) doc.second_photo = open(self.fake_file.name, 'rb') DBSession.add(doc) DBSession.flush() uploaded_file = doc.second_photo.path uploaded_thumb = doc.second_photo.thumb_12x12_path DBSession.rollback() DBSession.remove() try: fold = get_file(uploaded_file) assert False, 'Should have raised IOError here' except IOError: pass try: fold = get_file(uploaded_thumb) assert False, 'Should have raised IOError here' except IOError: pass
def test_rollback(self): doc = Document(name=u_('Foo3')) doc.second_photo = open(self.fake_file.name, 'rb') DBSession.add(doc) DBSession.flush() uploaded_file = doc.second_photo.path uploaded_thumb = doc.second_photo.thumb_path DBSession.rollback() DBSession.remove() try: fold = get_file(uploaded_file) assert False, 'Should have raised IOError here' except IOError: pass try: fold = get_file(uploaded_thumb) assert False, 'Should have raised IOError here' except IOError: pass
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
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
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
def file_exists(self, file_id): try: get_file(file_id) return True except IOError: return False