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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# -*- 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 pkgcore.ebuild.repo_objs import Maintainer
from grumpy.models import Category, Developer, Ebuild, Herd, Package
import unittest
class PkgModelTestCase(GrumpyTestCase):
def test_portage_data_model(self):
## Create portage data
# app-misc/testpkg
C1 = 'app-misc'
data = {'EAPI': '0', 'SLOT': '1.1', \
'DESCRIPTION': u'this is description', \
'HOMEPAGE': 'http://example.org/testpkg-app-misc', \
'KEYWORDS':'x86 amd64', \
'IUSE':'test +positive flags -negative split-flag'}
sdata = {'longdescription': 'this is longdescription', \
'herds': (None, '', 'kala', 'test'), \
'maintainers': (Maintainer('test@gentoo.org'), Maintainer('nobody@gentoo.org'))
}
p1 = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, data)
data['KEYWORDS'] = 'x86 ~amd64'
p2 = self.get_pkg('%s/testpkg-1.0-r4' % C1, sdata, data)
# app-test/testpkg
C2 = 'app-test'
data = {'EAPI': '0', 'SLOT': '1.0', \
'DESCRIPTION': 'short description', \
'HOMEPAGE': 'http://example.org/testpkg-app-test', \
'KEYWORDS':'x86 ~amd64', \
'IUSE':'test +positive flags -negative split-flag'}
p3 = self.get_pkg('%s/testpkg-1.0-r3' % C2, sdata, data)
with self.app.test_request_context():
## Create and test categories
c = [Category(C1), Category(C2)]
self.db.session.add_all(c)
self.db.session.commit()
assert Category.query.count() == 2
## Create and test packages
c[0].packages[p1.key] = Package(p1)
self.db.session.commit()
c[1].packages[p3.key] = Package(p3)
self.db.session.commit()
assert Package.query.count() == 2
# TODO: assert p.category vs package.category.name
p = Package.query.filter_by(key='%s/testpkg' % 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
assert len(p.category.packages) == 1
assert len(p.herds) == 3
assert len(p.devs) == 2
p = Package.query.filter_by(key='%s/testpkg' % C2).first()
assert p.pkg == 'testpkg'
assert p.desc == 'short description'
assert p.ldesc == 'this is longdescription'
assert p.homepage == 'http://example.org/testpkg-app-test'
assert p.category.name == C2
assert len(p.category.packages) == 1
assert len(p.herds) == 3
assert len(p.devs) == 2
# Test changes in herds
sdata['herds'] = ()
px = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, data)
c[0].packages[px.key].sync(px)
self.db.session.commit()
p = Package.query.filter_by(key='%s/testpkg' % C1).first()
assert p.pkg == 'testpkg'
assert p.category.name == C1
assert len(p.herds) == 0
# Test Category -> package lookup
for p in (p1, p2, p3):
c = Category.query.filter_by(name=p.category).first()
assert c != None
assert c.packages[p.key].key == p.key
# Handle ebuilds
c = Category.query.filter_by(name=p1.category).first()
pkg = c.packages[p1.key]
pkg.ebuilds[p1.cpvstr] = Ebuild(p1)
pkg.ebuilds[p2.cpvstr] = Ebuild(p2)
self.db.session.commit()
assert Ebuild.query.count() == 2
e = pkg.ebuilds[p1.cpvstr]
assert e.cpv == p1.cpvstr
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.fullver == p1.fullver
assert e.package == pkg
e = pkg.ebuilds[p2.cpvstr]
assert e.cpv == p2.cpvstr
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.fullver == p2.fullver
assert e.package == pkg
# Add more ebuilds to tree
c = Category.query.filter_by(name=p3.category).first()
pkg = c.packages[p3.key]
pkg.ebuilds[p1.cpvstr] = Ebuild(p3)
self.db.session.commit()
assert Ebuild.query.count() == 3
assert Package.query.count() == 2
assert Category.query.count() == 2
assert Herd.query.count() == 3
assert Developer.query.count() == 2
# Delete second category
c = Category.query.filter_by(name=p3.category).first()
self.db.session.delete(c)
self.db.session.commit()
assert Category.query.count() == 1
assert Package.query.count() == 1
assert Ebuild.query.count() == 2
# Delete first category
c = Category.query.filter_by(name=p1.category).first()
self.db.session.delete(c)
self.db.session.commit()
assert Category.query.count() == 0
assert Package.query.count() == 0
assert Ebuild.query.count() == 0
# Herds and maintainers should be still in db
assert Herd.query.count() == 3
assert Developer.query.count() == 2
def test_package_rename(self):
with self.app.test_request_context():
self.make_package(self.get_pkg('sys-apps/action-1.0-r2', {}, {}))
assert Category.query.count() == 1
assert Package.query.count() == 1
assert Ebuild.query.count() == 1
p = Package.query.filter_by(key='sys-apps/action').first()
assert p != None
p.rename('sys-fail/kala')
self.db.session.commit()
assert Category.query.count() == 2
assert Package.query.count() == 1
assert Ebuild.query.count() == 1
p = Package.query.filter_by(key='sys-apps/action').first()
assert p == None
p = Package.query.filter_by(key='sys-fail/kala').first()
assert p != None
assert p.pkg == 'kala'
e = Ebuild.query.first()
assert e.cpv == 'sys-fail/kala-1.0-r2'
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(PkgModelTestCase))
return suite
|