diff options
author | Priit Laes <plaes@plaes.org> | 2010-08-02 12:32:38 +0300 |
---|---|---|
committer | Priit Laes <plaes@plaes.org> | 2010-08-02 12:32:38 +0300 |
commit | 069c02791d45325957a9cac774194a41217caa05 (patch) | |
tree | 990ed64e605686329bf4774c8007d7d994c28afc | |
parent | Added tests for Ebuild's fullver and cpv properties (diff) | |
download | gsoc2010-grumpy-069c02791d45325957a9cac774194a41217caa05.tar.gz gsoc2010-grumpy-069c02791d45325957a9cac774194a41217caa05.tar.bz2 gsoc2010-grumpy-069c02791d45325957a9cac774194a41217caa05.zip |
Added tests for cascading delete
-rw-r--r-- | grumpy/models.py | 4 | ||||
-rw-r--r-- | grumpy/testsuite/__init__.py | 1 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 25 |
3 files changed, 28 insertions, 2 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index 8ca7912..0218d8b 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -44,7 +44,7 @@ class Category(db.Model): self.name = name def __repr__(self): - return '<%s> "%s"' % (self.__class__.__name__, self.category) + return '<%s> "%s"' % (self.__class__.__name__, self.name) class Developer(db.Model): """Represents developers in the system""" @@ -172,7 +172,7 @@ class Package(db.Model): herds = db.relationship(Herd, secondary=package_herds, backref='packages') ebuilds = db.relationship(Ebuild, backref='package', \ - cascade='all, delete, delete-orphan', \ + cascade='all, delete-orphan', \ collection_class=column_mapped_collection(Ebuild.cpv)) def __init__(self, ebuild_src, mtime=time.time()): diff --git a/grumpy/testsuite/__init__.py b/grumpy/testsuite/__init__.py index b9db759..7fcecd9 100644 --- a/grumpy/testsuite/__init__.py +++ b/grumpy/testsuite/__init__.py @@ -37,6 +37,7 @@ class GrumpyTestCase(unittest.TestCase): def setUp(self): #app.config['SQLALCHEMY_ECHO'] = True app.config['SQLALCHEMY_ENGINE'] = 'sqlite://' + #app.config['SQLALCHEMY_ENGINE'] = 'postgresql+psycopg://grumpy:grumpy@localhost/grumpy_test' app.config['TESTING'] = True db.create_all() diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index f4bd207..740d67a 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -108,6 +108,31 @@ class PkgModelTestCase(GrumpyTestCase): assert e.fullver == p2.fullver assert e.package == pkg + # Add more ebuilds to tree + c = Category.query.filter_by(name=p3.category).first() + pkg = c.packages[p3.key] + pkg.ebuilds[p1.cpvstr] = Ebuild(p3) + self.db.session.commit() + + assert Ebuild.query.count() == 3 + assert Package.query.count() == 2 + assert Category.query.count() == 2 + + # Delete second category + c = Category.query.filter_by(name=p3.category).first() + self.db.session.delete(c) + self.db.session.commit() + assert Category.query.count() == 1 + assert Package.query.count() == 1 + assert Ebuild.query.count() == 2 + # Delete first category + c = Category.query.filter_by(name=p1.category).first() + self.db.session.delete(c) + self.db.session.commit() + assert Category.query.count() == 0 + assert Package.query.count() == 0 + assert Ebuild.query.count() == 0 + def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(PkgModelTestCase)) |