aboutsummaryrefslogtreecommitdiff
blob: 9b17c8aa90b3e9512feb44f727c566c160c75461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
    grumpy.testsuite
    ~~~~~~~~~~~~~~~~

    Unittests for Grumpy project.

    :copyright: (c) by 2010 Priit Laes.
    :license: BSD, see LICENSE for details.
"""
import unittest

from grumpy import app
from grumpy.models import db
from pkgcore.ebuild import ebuild_src, repo_objs

class GrumpyTestCase(unittest.TestCase):

    def get_pkg(self, cpv, pkg_data={}, data={}):
        # We need to set up info from metadata.xml separately
        valid_keys = ("longdescription", "maintainers", "herds")
        for x in valid_keys:
            pkg_data.setdefault(x, "")
        metadata = repo_objs.MetadataXml(None)
        for key, value in pkg_data.iteritems():
            if key not in valid_keys:
                continue
            object.__setattr__(metadata, "_" + key, value)
        shared_pkg_data = repo_objs.SharedPkgData(metadata, None)

        o = ebuild_src.package(shared_pkg_data, None, cpv)
        if data is not None:
            object.__setattr__(o, 'data', data)
        return o

    def setUp(self):
        app.config['SQLALCHEMY_ENGINE'] = 'sqlite://'
        app.config['TESTING'] = True
        db.create_all()

        self.app = app
        self.db = db

    def tearDown(self):
        self.db.session.rollback()
        self.db.drop_all()

def suite():
    from . import favorites, pkgmodel, usermodel
    suite = unittest.TestSuite()
    #suite.addTest(favorites.suite())
    suite.addTest(pkgmodel.suite())
    suite.addTest(usermodel.suite())
    return suite