aboutsummaryrefslogtreecommitdiff
blob: d5992e4a78fecb85c0c508dba649acd47c0c7b83 (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
55
56
57
58
# -*- coding: utf-8 -*-
"""
    grumpy.testsuite
    ~~~~~~~~~~~~~~~~

    Unittests for Grumpy project.

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

from pkgcore.ebuild import ebuild_src, repo_objs

from grumpy import app
from grumpy.models import db

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:
            pkg_data.setdefault(x, "")
        metadata = repo_objs.MetadataXml(None)
        for key, value in copy.copy(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', copy.copy(data))
        return o

    def setUp(self):
        #app.config['SQLALCHEMY_ECHO'] = True
        app.config['SQLALCHEMY_ENGINE'] = 'sqlite://'
        #app.config['SQLALCHEMY_ENGINE'] = 'postgresql+psycopg://grumpy:grumpy@localhost/grumpy_test'
        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