diff options
author | 2010-08-01 23:08:45 +0300 | |
---|---|---|
committer | 2010-08-01 23:08:45 +0300 | |
commit | fb65aa0f9429595c1a2d30e903b4ccc8228a299a (patch) | |
tree | 6798747907ce961c04563ade067e76f2d0fb845c | |
parent | Use column_mapped_collection for Category.packages (diff) | |
download | gsoc2010-grumpy-fb65aa0f9429595c1a2d30e903b4ccc8228a299a.tar.gz gsoc2010-grumpy-fb65aa0f9429595c1a2d30e903b4ccc8228a299a.tar.bz2 gsoc2010-grumpy-fb65aa0f9429595c1a2d30e903b4ccc8228a299a.zip |
Added simple tests for Package
-rw-r--r-- | grumpy/models.py | 8 | ||||
-rw-r--r-- | grumpy/testsuite/__init__.py | 2 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 20 |
3 files changed, 20 insertions, 10 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index 85683fb..cdebe33 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -34,14 +34,14 @@ class Category(db.Model): __tablename__ = 'categories' id = db.Column('id', db.Integer, primary_key=True) - category = db.Column('category', db.String, nullable=False, unique=True) + name = db.Column('name', db.String, nullable=False, unique=True) packages = db.relationship("Package", backref='category', \ cascade='all, delete, delete-orphan', \ collection_class=column_mapped_collection(db.text('packages.pkg_cat'))) - def __init__(self, category): - self.category = category + def __init__(self, name): + self.name = name def __repr__(self): return '<%s> "%s"' % (self.__class__.__name__, self.category) @@ -180,8 +180,8 @@ class Package(db.Model): def __init__(self, ebuild_src, mtime=time.time()): self.pkg = ebuild_src.package - self.pkg_cat = "%s/%s" % (self.pkg, ebuild_src.category) self.desc = ebuild_src.description + self.pkg_cat = "%s/%s" % (self.pkg, ebuild_src.category) self.homepage = ebuild_src.homepage self.mtime = datetime.fromtimestamp(mtime) # shared pkg data (from metadata.xml) diff --git a/grumpy/testsuite/__init__.py b/grumpy/testsuite/__init__.py index 9b17c8a..b9db759 100644 --- a/grumpy/testsuite/__init__.py +++ b/grumpy/testsuite/__init__.py @@ -17,6 +17,7 @@ from pkgcore.ebuild import ebuild_src, repo_objs class GrumpyTestCase(unittest.TestCase): def get_pkg(self, cpv, pkg_data={}, data={}): + """Returns a custom ebuild""" # We need to set up info from metadata.xml separately valid_keys = ("longdescription", "maintainers", "herds") for x in valid_keys: @@ -34,6 +35,7 @@ class GrumpyTestCase(unittest.TestCase): return o def setUp(self): + #app.config['SQLALCHEMY_ECHO'] = True app.config['SQLALCHEMY_ENGINE'] = 'sqlite://' app.config['TESTING'] = True db.create_all() diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index fc6a8d8..44f9dbe 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -12,7 +12,7 @@ from . import GrumpyTestCase from grumpy.models import Category, Ebuild, Package -import time, unittest +import copy, time, unittest class PkgModelTestCase(GrumpyTestCase): @@ -22,15 +22,15 @@ class PkgModelTestCase(GrumpyTestCase): # app-misc/testpkg C1 = 'app-misc' data = {'EAPI': '0', 'SLOT': '1.1', \ - 'DESCRIPTION': 'This is a simple description', \ - 'LONGDESCRIPTION': 'This is long description from metadata.xml', \ + 'DESCRIPTION': u'this is description', \ 'HOMEPAGE': 'http://example.org/testpkg-app-misc', \ 'KEYWORDS':'x86 amd64', \ 'IUSE':'test +positive flags -negative split-flag'} - sdata = {'longdescription': 'foo!'} - p1 = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, data) + sdata = {'longdescription': 'this is longdescription'} + p1 = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, copy.copy(data)) data['KEYWORDS'] = 'x86 ~amd64' - p2 = self.get_pkg('%s/testpkg-1.0-r4' % C1, sdata, data) + p2 = self.get_pkg('%s/testpkg-1.0-r4' % C1, sdata, copy.copy(data)) + # app-test/testpkg C2 = 'app-test' data = {'EAPI': '0', 'SLOT': '1.0', \ @@ -56,6 +56,14 @@ class PkgModelTestCase(GrumpyTestCase): self.db.session.commit() assert Package.query.count() == 2 + # Query info + p = Package.query.filter_by(pkg_cat='testpkg/%s' % 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 + def make_packages_and_ebuild(self, categories): # Create package... p = Package(categories[0], 'testpkg', 'Test Package', \ |