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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# -*- coding: utf-8 -*-
"""
grumpy.testsuite.pkgmodel
~~~~~~~~~~~~~~~~~~~~~~~~~
Unittests for package and ebuild handling.
:copyright: (c) by 2010 Priit Laes.
:license: BSD, see LICENSE for details.
"""
from . import GrumpyTestCase
from grumpy.models import Category, Ebuild, Package
import time, unittest
categories = ['app-misc', 'app-test']
class PkgModelTestCase(GrumpyTestCase):
def make_categories(self):
for cat in categories:
self.db.session.add(Category(cat))
self.db.session.commit()
def make_package_and_ebuilds(self):
# Create package...
p = Package(categories[0], 'testpkg', 'Test Package', \
'Long Description', 'http://example.com/test', \
time.time())
# ...and two ebuilds
data = {'EAPI': '0', 'SLOT': '1.1', \
'KEYWORDS':'x86 amd64', \
'IUSE':'test +positive flags -negative split-flag'}
p.ebuilds.append(Ebuild(self.get_pkg('app-misc/testpkg-1.0-r3', data)))
p.ebuilds.append(Ebuild(self.get_pkg('app-misc/testpkg-1.0-r4', data)))
self.db.session.add(p)
self.db.session.commit()
return p
def test_ebuild_parsing(self):
with self.app.test_request_context():
p = self.make_package_and_ebuilds()
e = Ebuild.query.first()
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.pcv == 'testpkg/app-misc-1.0-r3'
assert e.package == p
def test_category_and_package_model(self):
with self.app.test_request_context():
self.make_categories()
self.make_package_and_ebuilds()
assert Category.query.count() == 2
assert Ebuild.query.count() == 2
assert Package.query.count() == 1
p = Package.query.first()
assert len(p.ebuilds) == 2
# Test garbage collection
self.db.session.delete(p)
self.db.session.commit()
assert Category.query.count() == 2
# Cascade delete should also get rid of ebuilds
assert Ebuild.query.count() == 0
assert Package.query.count() == 0
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(PkgModelTestCase))
return suite
|