diff options
author | 2010-07-27 05:47:00 +0300 | |
---|---|---|
committer | 2010-07-27 05:47:00 +0300 | |
commit | 516f8332ee1b077fc82a28baa4689a801bf5c855 (patch) | |
tree | 1de235b839aa44dc7940fe83e51c1a7ee282c7d2 | |
parent | Basic user creation test (diff) | |
download | gsoc2010-grumpy-516f8332ee1b077fc82a28baa4689a801bf5c855.tar.gz gsoc2010-grumpy-516f8332ee1b077fc82a28baa4689a801bf5c855.tar.bz2 gsoc2010-grumpy-516f8332ee1b077fc82a28baa4689a801bf5c855.zip |
Added simple unittest for Ebuilds and Packages
-rw-r--r-- | grumpy/testsuite/__init__.py | 3 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 58 |
2 files changed, 60 insertions, 1 deletions
diff --git a/grumpy/testsuite/__init__.py b/grumpy/testsuite/__init__.py index 6dc55e3..e9762db 100644 --- a/grumpy/testsuite/__init__.py +++ b/grumpy/testsuite/__init__.py @@ -27,7 +27,8 @@ class GrumpyTestCase(unittest.TestCase): self.db.drop_all() def suite(): - from . import usermodel + from . import pkgmodel, usermodel suite = unittest.TestSuite() + suite.addTest(pkgmodel.suite()) suite.addTest(usermodel.suite()) return suite diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py new file mode 100644 index 0000000..49ae354 --- /dev/null +++ b/grumpy/testsuite/pkgmodel.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +""" + grumpy.testsuite.pkgmodel + ~~~~~~~~~~~~~~~~~~~~~~~~~ + + Unittests for package and ebuild handling. + + :copyright: (c) by 2010 Priit Laes. + :license: BSD, see LICENSE for details. +""" +from . import GrumpyTestCase + +from grumpy.models import Category, Ebuild, Package + +import time, unittest + +categories = ['app-misc', 'app-test'] + +class PkgModelTestCase(GrumpyTestCase): + + def make_categories(self): + for cat in categories: + self.db.session.add(Category(cat)) + self.db.session.commit() + + def make_package_and_ebuilds(self): + # Create package... + p = Package(categories[0], 'testpkg', 'Test Package', \ + 'Long Description', 'http://example.com/test', \ + time.time()) + # ...and two ebuilds + p.ebuilds.append(Ebuild(p, '1.0-r3', 2, 0, 'x86,~amd64', 'doc', '')) + p.ebuilds.append(Ebuild(p, '1.0-r4', 2, 0, '~x86,~amd64', 'doc', '')) + self.db.session.add(p) + self.db.session.commit() + + def test_category_and_package_model(self): + with self.app.test_request_context(): + self.make_categories() + self.make_package_and_ebuilds() + assert Category.query.count() == 2 + assert Ebuild.query.count() == 2 + assert Package.query.count() == 1 + p = Package.query.first() + assert len(p.ebuilds) == 2 + + # Test garbage collection + self.db.session.delete(p) + self.db.session.commit() + assert Category.query.count() == 2 + # Cascade delete should also get rid of ebuilds + assert Ebuild.query.count() == 0 + assert Package.query.count() == 0 + +def suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(PkgModelTestCase)) + return suite |