diff options
author | 2010-08-22 11:01:01 +0300 | |
---|---|---|
committer | 2010-08-22 11:01:01 +0300 | |
commit | d8836d5fd96948a319acc6c45b5a21aa31ea921f (patch) | |
tree | 2ac373767b12f4a29cdfbf1430cde5786d473854 | |
parent | Updated README (diff) | |
download | gsoc2010-grumpy-d8836d5fd96948a319acc6c45b5a21aa31ea921f.tar.gz gsoc2010-grumpy-d8836d5fd96948a319acc6c45b5a21aa31ea921f.tar.bz2 gsoc2010-grumpy-d8836d5fd96948a319acc6c45b5a21aa31ea921f.zip |
Clean up request_context hacks in tests
-rw-r--r-- | grumpy/testsuite/__init__.py | 22 | ||||
-rw-r--r-- | grumpy/testsuite/favorites.py | 45 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 262 | ||||
-rw-r--r-- | grumpy/testsuite/usermodel.py | 5 |
4 files changed, 166 insertions, 168 deletions
diff --git a/grumpy/testsuite/__init__.py b/grumpy/testsuite/__init__.py index 162b03d..e903df1 100644 --- a/grumpy/testsuite/__init__.py +++ b/grumpy/testsuite/__init__.py @@ -18,16 +18,15 @@ from grumpy.models import db, Category, Ebuild, Package class GrumpyTestCase(unittest.TestCase): def make_package(self, package): - with self.app.test_request_context(): - cat = package.key.split('/')[0] - c = Category.query.filter_by(name=cat).first() - if not c: - c = Category(cat) - self.db.session.add(c) - p = Package(package) - c.packages[package.key] = p - p.ebuilds[package.cpvstr] = Ebuild(package) - self.db.session.commit() + cat = package.key.split('/')[0] + c = Category.query.filter_by(name=cat).first() + if not c: + c = Category(cat) + self.db.session.add(c) + p = Package(package) + c.packages[package.key] = p + p.ebuilds[package.cpvstr] = Ebuild(package) + self.db.session.commit() def get_pkg(self, cpv, pkg_data={}, data={}): """Returns a custom ebuild""" @@ -54,6 +53,9 @@ class GrumpyTestCase(unittest.TestCase): app.config['TESTING'] = True db.create_all() + # Initialize request context + app.test_request_context().push() + self.app = app self.db = db diff --git a/grumpy/testsuite/favorites.py b/grumpy/testsuite/favorites.py index 4add8d4..827a490 100644 --- a/grumpy/testsuite/favorites.py +++ b/grumpy/testsuite/favorites.py @@ -32,30 +32,29 @@ class FavoritesTestCase(GrumpyTestCase): return u def test_favorites(self): - with self.app.test_request_context(): - u = self.make_users() - assert User.query.count() == 2 - for i in self.ps: - self.make_package(self.get_pkg(i, self.d2, self.d1)) - assert Package.query.count() == len(self.ps) - - # Fetch some packages - pkgs = Package.query.filter(Package.key.in_(\ - ['sys-test/kala', 'kala-base/appp', 'sys-apps/ssss'])).all() - for p in pkgs: - u[0].favorites.append(p) - pkgs = Package.query.filter(Package.key.in_(\ - ['sys-apps/fffuuu', 'kala-base/appp'])).all() - for p in pkgs: - u[1].favorites.append(p) - self.db.session.commit() + u = self.make_users() + assert User.query.count() == 2 + for i in self.ps: + self.make_package(self.get_pkg(i, self.d2, self.d1)) + assert Package.query.count() == len(self.ps) + + # Fetch some packages + pkgs = Package.query.filter(Package.key.in_(\ + ['sys-test/kala', 'kala-base/appp', 'sys-apps/ssss'])).all() + for p in pkgs: + u[0].favorites.append(p) + pkgs = Package.query.filter(Package.key.in_(\ + ['sys-apps/fffuuu', 'kala-base/appp'])).all() + for p in pkgs: + u[1].favorites.append(p) + self.db.session.commit() - assert len(u[0].favorites) == 3 - assert len(u[1].favorites) == 2 - p = Package.query.filter_by(key='sys-apps/ssss').one() - assert len(p.favorites) == 1 - p = Package.query.filter_by(key='kala-base/appp').one() - assert len(p.favorites) == 2 + assert len(u[0].favorites) == 3 + assert len(u[1].favorites) == 2 + p = Package.query.filter_by(key='sys-apps/ssss').one() + assert len(p.favorites) == 1 + p = Package.query.filter_by(key='kala-base/appp').one() + assert len(p.favorites) == 2 def suite(): diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index 0c65c91..3d64cca 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -43,140 +43,138 @@ class PkgModelTestCase(GrumpyTestCase): 'IUSE':'test +positive flags -negative split-flag'} p3 = self.get_pkg('%s/testpkg-1.0-r3' % C2, sdata, data) - with self.app.test_request_context(): - ## Create and test categories - c = [Category(C1), Category(C2)] - self.db.session.add_all(c) - self.db.session.commit() - assert Category.query.count() == 2 - - ## Create and test packages - c[0].packages[p1.key] = Package(p1) - self.db.session.commit() - c[1].packages[p3.key] = Package(p3) - self.db.session.commit() - assert Package.query.count() == 2 - # TODO: assert p.category vs package.category.name - - p = Package.query.filter_by(key='%s/testpkg' % C1).first() - assert p.pkg == 'testpkg' - assert p.desc == 'this is description' - assert p.ldesc == 'this is longdescription' - assert p.homepage == 'http://example.org/testpkg-app-misc' - assert p.category.name == C1 - assert len(p.category.packages) == 1 - assert len(p.herds) == 3 - assert len(p.devs) == 2 - - p = Package.query.filter_by(key='%s/testpkg' % C2).first() - assert p.pkg == 'testpkg' - assert p.desc == 'short description' - assert p.ldesc == 'this is longdescription' - assert p.homepage == 'http://example.org/testpkg-app-test' - assert p.category.name == C2 - assert len(p.category.packages) == 1 - assert len(p.herds) == 3 - assert len(p.devs) == 2 - - # Test changes in herds - sdata['herds'] = () - px = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, data) - c[0].packages[px.key].sync(px) - - self.db.session.commit() - p = Package.query.filter_by(key='%s/testpkg' % C1).first() - assert p.pkg == 'testpkg' - assert p.category.name == C1 - assert len(p.herds) == 0 - - # Test Category -> package lookup - for p in (p1, p2, p3): - c = Category.query.filter_by(name=p.category).first() - assert c != None - assert c.packages[p.key].key == p.key - - # Handle ebuilds - c = Category.query.filter_by(name=p1.category).first() - pkg = c.packages[p1.key] - pkg.ebuilds[p1.cpvstr] = Ebuild(p1) - pkg.ebuilds[p2.cpvstr] = Ebuild(p2) - self.db.session.commit() - assert Ebuild.query.count() == 2 - - e = pkg.ebuilds[p1.cpvstr] - assert e.cpv == p1.cpvstr - assert e.iuse == 'test,flags,split-flag' - assert e.iuse_neg == 'negative' - assert e.iuse_pos == 'positive' - assert e.keywords == 'x86,amd64' - assert e.eapi == 0 - assert e.slot == '1.1' - assert e.fullver == p1.fullver - assert e.package == pkg - - e = pkg.ebuilds[p2.cpvstr] - assert e.cpv == p2.cpvstr - assert e.iuse == 'test,flags,split-flag' - assert e.iuse_neg == 'negative' - assert e.iuse_pos == 'positive' - assert e.keywords == 'x86,~amd64' - assert e.eapi == 0 - assert e.slot == '1.1' - 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 - assert Herd.query.count() == 3 - assert Developer.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 - - # Herds and maintainers should be still in db - assert Herd.query.count() == 3 - assert Developer.query.count() == 2 + ## Create and test categories + c = [Category(C1), Category(C2)] + self.db.session.add_all(c) + self.db.session.commit() + assert Category.query.count() == 2 + + ## Create and test packages + c[0].packages[p1.key] = Package(p1) + self.db.session.commit() + c[1].packages[p3.key] = Package(p3) + self.db.session.commit() + assert Package.query.count() == 2 + # TODO: assert p.category vs package.category.name + + p = Package.query.filter_by(key='%s/testpkg' % C1).first() + assert p.pkg == 'testpkg' + assert p.desc == 'this is description' + assert p.ldesc == 'this is longdescription' + assert p.homepage == 'http://example.org/testpkg-app-misc' + assert p.category.name == C1 + assert len(p.category.packages) == 1 + assert len(p.herds) == 3 + assert len(p.devs) == 2 + + p = Package.query.filter_by(key='%s/testpkg' % C2).first() + assert p.pkg == 'testpkg' + assert p.desc == 'short description' + assert p.ldesc == 'this is longdescription' + assert p.homepage == 'http://example.org/testpkg-app-test' + assert p.category.name == C2 + assert len(p.category.packages) == 1 + assert len(p.herds) == 3 + assert len(p.devs) == 2 + + # Test changes in herds + sdata['herds'] = () + px = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, data) + c[0].packages[px.key].sync(px) + + self.db.session.commit() + p = Package.query.filter_by(key='%s/testpkg' % C1).first() + assert p.pkg == 'testpkg' + assert p.category.name == C1 + assert len(p.herds) == 0 + + # Test Category -> package lookup + for p in (p1, p2, p3): + c = Category.query.filter_by(name=p.category).first() + assert c != None + assert c.packages[p.key].key == p.key + + # Handle ebuilds + c = Category.query.filter_by(name=p1.category).first() + pkg = c.packages[p1.key] + pkg.ebuilds[p1.cpvstr] = Ebuild(p1) + pkg.ebuilds[p2.cpvstr] = Ebuild(p2) + self.db.session.commit() + assert Ebuild.query.count() == 2 + + e = pkg.ebuilds[p1.cpvstr] + assert e.cpv == p1.cpvstr + assert e.iuse == 'test,flags,split-flag' + assert e.iuse_neg == 'negative' + assert e.iuse_pos == 'positive' + assert e.keywords == 'x86,amd64' + assert e.eapi == 0 + assert e.slot == '1.1' + assert e.fullver == p1.fullver + assert e.package == pkg + + e = pkg.ebuilds[p2.cpvstr] + assert e.cpv == p2.cpvstr + assert e.iuse == 'test,flags,split-flag' + assert e.iuse_neg == 'negative' + assert e.iuse_pos == 'positive' + assert e.keywords == 'x86,~amd64' + assert e.eapi == 0 + assert e.slot == '1.1' + 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 + assert Herd.query.count() == 3 + assert Developer.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 + + # Herds and maintainers should be still in db + assert Herd.query.count() == 3 + assert Developer.query.count() == 2 def test_package_rename(self): - with self.app.test_request_context(): - self.make_package(self.get_pkg('sys-apps/action-1.0-r2', {}, {})) - assert Category.query.count() == 1 - assert Package.query.count() == 1 - assert Ebuild.query.count() == 1 - - p = Package.query.filter_by(key='sys-apps/action').first() - assert p != None - p.rename('sys-fail/kala') - self.db.session.commit() - assert Category.query.count() == 2 - assert Package.query.count() == 1 - assert Ebuild.query.count() == 1 - p = Package.query.filter_by(key='sys-apps/action').first() - assert p == None - p = Package.query.filter_by(key='sys-fail/kala').first() - assert p != None - assert p.pkg == 'kala' - e = Ebuild.query.first() - assert e.cpv == 'sys-fail/kala-1.0-r2' + self.make_package(self.get_pkg('sys-apps/action-1.0-r2', {}, {})) + assert Category.query.count() == 1 + assert Package.query.count() == 1 + assert Ebuild.query.count() == 1 + + p = Package.query.filter_by(key='sys-apps/action').first() + assert p != None + p.rename('sys-fail/kala') + self.db.session.commit() + assert Category.query.count() == 2 + assert Package.query.count() == 1 + assert Ebuild.query.count() == 1 + p = Package.query.filter_by(key='sys-apps/action').first() + assert p == None + p = Package.query.filter_by(key='sys-fail/kala').first() + assert p != None + assert p.pkg == 'kala' + e = Ebuild.query.first() + assert e.cpv == 'sys-fail/kala-1.0-r2' def suite(): suite = unittest.TestSuite() diff --git a/grumpy/testsuite/usermodel.py b/grumpy/testsuite/usermodel.py index 0063fdd..a381542 100644 --- a/grumpy/testsuite/usermodel.py +++ b/grumpy/testsuite/usermodel.py @@ -23,9 +23,8 @@ class UserModelTestCase(GrumpyTestCase): self.db.session.commit() def test_user_creation(self): - with self.app.test_request_context(): - self.make_users() - assert User.query.count() == 2 + self.make_users() + assert User.query.count() == 2 def suite(): suite = unittest.TestSuite() |