Example #1
0
    def test_referred(self):
        tmpfile = self._create_tmp_file()
        newfile = File(name='testfile.txt', source=tmpfile,
                       session=self.session)
        self.session.commit()
        source = self._get_test_file('sample.png')
        newimage = Image(source=source, name="original.png",
                         session=self.session)
        self.session.commit()

        page = create_page(self.session)
        content = '<a href={f.url}>{f.name}</a><img src={img.url}/>'
        page.content = content.format(f=newfile, img=newimage)
        # Statements aren't needed: append will be performed by after_flush.
        #page.files.append(newfile)
        #page.images.append(newimage)
        self.session.commit()
        self.assertIn(page, newfile.pages)
        self.assertIn(page, newimage.pages)

        with self.assertRaises(ConstraintError):
            newfile.delete()

        with self.assertRaises(ConstraintError):
            newimage.delete()

        self.assertIn(page, newfile.pages)
        self.assertIn(page, newimage.pages)

        d = newfile.to_dict()
        self.assertNotIn('used_by', d)
        d = newfile.to_dict(ref_pages=True)
        self.assertIn('used_by', d)
Example #2
0
    def test_delete(self):
        tmpfile = self._create_tmp_file()

        f = File(name='testfile.txt', source=tmpfile, session=self.session)
        self.session.commit()
        f.delete()
        self.session.commit()
        self.assertEqual(len(File.all(self.session)), 0)