diff options
author | 2010-08-10 16:13:46 +0300 | |
---|---|---|
committer | 2010-08-10 16:13:46 +0300 | |
commit | 608bf946f7e55ba3e3a48808f06ed60e7ff8c8e6 (patch) | |
tree | 1031061630fa002520502bae3a11ed1497c0c747 | |
parent | Added GSoC report no. 7 (diff) | |
download | gsoc2010-grumpy-608bf946f7e55ba3e3a48808f06ed60e7ff8c8e6.tar.gz gsoc2010-grumpy-608bf946f7e55ba3e3a48808f06ed60e7ff8c8e6.tar.bz2 gsoc2010-grumpy-608bf946f7e55ba3e3a48808f06ed60e7ff8c8e6.zip |
Cleaned up unittests for Favorites
-rw-r--r-- | grumpy/testsuite/__init__.py | 2 | ||||
-rw-r--r-- | grumpy/testsuite/favorites.py | 84 |
2 files changed, 42 insertions, 44 deletions
diff --git a/grumpy/testsuite/__init__.py b/grumpy/testsuite/__init__.py index d5992e4..eb7540c 100644 --- a/grumpy/testsuite/__init__.py +++ b/grumpy/testsuite/__init__.py @@ -52,7 +52,7 @@ class GrumpyTestCase(unittest.TestCase): def suite(): from . import favorites, pkgmodel, usermodel suite = unittest.TestSuite() - #suite.addTest(favorites.suite()) + suite.addTest(favorites.suite()) suite.addTest(pkgmodel.suite()) suite.addTest(usermodel.suite()) return suite diff --git a/grumpy/testsuite/favorites.py b/grumpy/testsuite/favorites.py index 9c701aa..89aa032 100644 --- a/grumpy/testsuite/favorites.py +++ b/grumpy/testsuite/favorites.py @@ -3,19 +3,37 @@ grumpy.testsuite.favorites ~~~~~~~~~~~~~~~~~~~~~~~~~~ - Unittests for "favorite" user packages unittests. + Unittests for "favorite" user packages. :copyright: (c) by 2010 Priit Laes. :license: BSD, see LICENSE for details. """ +import unittest + from . import GrumpyTestCase +from grumpy.models import Category, Package, User -from grumpy.models import Ebuild, Favorite, Package, User -from sqlalchemy.exc import IntegrityError +class FavoritesTestCase(GrumpyTestCase): -import time, unittest + d1 = {'DESCRIPTION': u'Desc', + 'HOMEPAGE': 'http://example.com', + 'KEYWORDS': '~amd64'} + d2 = {'longdescription': 'longdesc', + 'herds': ('test'), + 'maintainers': ()} + ps = ['sys-test/kala-0.12', 'sys-kala/test-0.10', 'sys-apps/ffff-0.1', \ + 'sys-apps/fffuuu-0.9', 'sys-apps/ssss-0.3', 'kala-base/appp-3.0'] -class FavoritesTestCase(GrumpyTestCase): + def make_packages(self): + for i in self.ps: + cat = i.split('/')[0] + c = Category.query.filter_by(name=cat).first() + if not c: + c = Category(cat) + self.db.session.add(c) + p = self.get_pkg(i, self.d2, self.d1) + c.packages[p.key] = Package(p) + self.db.session.commit() def make_users(self): u = [User('user1@gentoo.org', 'http://example.net/openid1'), @@ -24,51 +42,31 @@ class FavoritesTestCase(GrumpyTestCase): self.db.session.commit() return u - def make_packages(self): - p = [] - p.append(Package('sys-misc', 'testpkg', 'Test Package', \ - 'Long Description', 'http://example.com/test', \ - time.time())) - p[0].ebuilds.append(Ebuild(self.get_pkg('sys-misc/testpkg-1.0'))) - p[0].ebuilds.append(Ebuild(self.get_pkg('sys-misc/testpkg-1.1'))) - p.append(Package('sys-devel', 'testpkg', 'Test Package 2', \ - 'Long Description 2', 'http://example.com/test2', \ - time.time())) - p[1].ebuilds.append(Ebuild(self.get_pkg('sys-devel/testpkg-0.1'))) - self.db.session.add_all(p) - self.db.session.commit() - return p - def test_favorites(self): with self.app.test_request_context(): - _u = self.make_users() - _p = self.make_packages() + u = self.make_users() assert User.query.count() == 2 - assert Package.query.count() == 2 + self.make_packages() + assert Package.query.count() == len(self.ps) - u = _u[0] - u.favorites.append(Favorite(_p[0])) - u.favorites.append(Favorite(_p[1])) + # 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 Favorite.query.count() == 2 - assert len(u.favorites) == 2 - - def test_favorites_uniqueness(self): - with self.app.test_request_context(): - _u = self.make_users() - _p = self.make_packages() - - u = _u[0] - u.favorites.append(Favorite(_p[0])) - 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 - u.favorites.append(Favorite(_p[0])) - self.assertRaises(IntegrityError, self.db.session.commit) - self.db.session.rollback() - assert len(u.favorites) == 1 - for i in u.favorites: - assert u == i.user def suite(): suite = unittest.TestSuite() |