3 from db_test import DBDakTestCase
5 from daklib.dbconn import Architecture, Suite, get_suite_architectures, \
6 get_architecture_suites, Maintainer, DBSource, Location, PoolFile, \
7 check_poolfile, get_poolfile_like_name
11 class PackageTestCase(DBDakTestCase):
13 PackageTestCase checks the handling of source and binary packages in dak's
17 def setup_architectures(self):
18 "setup a hash of Architecture objects in self.arch"
21 for arch_string in ('source', 'all', 'i386', 'amd64', 'kfreebsd-i386'):
22 self.arch[arch_string] = Architecture(arch_string)
23 # hard code ids for source and all
24 self.arch['source'].arch_id = 1
25 self.arch['all'].arch_id = 2
26 for _, architecture in self.arch.items():
27 self.session.add(architecture)
29 self.session.refresh(architecture)
31 def setup_suites(self):
32 "setup a hash of Suite objects in self.suite"
35 for suite_name in ('lenny', 'squeeze', 'sid'):
36 suite = Suite(suite_name = suite_name, version = '-')
37 self.suite[suite_name] = suite
38 self.session.add(suite)
40 self.session.refresh(suite)
43 super(PackageTestCase, self).setUp()
44 self.setup_architectures()
47 def connect_suite_architectures(self):
49 Gonnect all suites and all architectures except for kfreebsd-i386 which
50 should not be in lenny.
53 for arch_string, architecture in self.arch.items():
54 if arch_string != 'kfreebsd-i386':
55 architecture.suites = self.suite.values()
57 architecture.suites = [self.suite['squeeze'], self.suite['sid']]
59 def test_suite_architecture(self):
60 # check the id for architectures source and all
61 self.assertEqual(1, self.arch['source'].arch_id)
62 self.assertEqual(2, self.arch['all'].arch_id)
63 # check the many to many relation between Suite and Architecture
64 self.arch['source'].suites.append(self.suite['lenny'])
65 self.assertEqual('source', self.suite['lenny'].architectures[0])
66 self.arch['source'].suites = []
67 self.assertEqual([], self.suite['lenny'].architectures)
68 self.connect_suite_architectures()
69 self.assertEqual(4, len(self.suite['lenny'].architectures))
70 self.assertEqual(3, len(self.arch['i386'].suites))
71 # check the function get_suite_architectures()
72 architectures = get_suite_architectures('lenny', session = self.session)
73 self.assertEqual(4, len(architectures))
74 self.assertTrue(self.arch['source'] in architectures)
75 self.assertTrue(self.arch['all'] in architectures)
76 self.assertTrue(self.arch['kfreebsd-i386'] not in architectures)
77 architectures = get_suite_architectures('sid', session = self.session)
78 self.assertEqual(5, len(architectures))
79 self.assertTrue(self.arch['kfreebsd-i386'] in architectures)
80 architectures = get_suite_architectures('lenny', skipsrc = True, session = self.session)
81 self.assertEqual(3, len(architectures))
82 self.assertTrue(self.arch['source'] not in architectures)
83 architectures = get_suite_architectures('lenny', skipall = True, session = self.session)
84 self.assertEqual(3, len(architectures))
85 self.assertTrue(self.arch['all'] not in architectures)
86 # check the function get_architecture_suites()
87 suites = get_architecture_suites('i386', self.session)
88 self.assertEqual(3, len(suites))
89 self.assertTrue(self.suite['lenny'] in suites)
90 suites = get_architecture_suites('kfreebsd-i386', self.session)
91 self.assertEqual(2, len(suites))
92 self.assertTrue(self.suite['lenny'] not in suites)
94 def setup_locations(self):
95 'create some Location objects, TODO: add component'
98 self.loc['main'] = Location(path = \
99 '/srv/ftp-master.debian.org/ftp/pool/')
100 self.session.add(self.loc['main'])
102 def setup_poolfiles(self):
103 'create some PoolFile objects'
106 self.file['hello'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.dsc', \
107 location = self.loc['main'], filesize = 0, md5sum = '')
108 self.file['sl'] = PoolFile(filename = 'main/s/sl/sl_3.03-16.dsc', \
109 location = self.loc['main'], filesize = 0, md5sum = '')
110 self.session.add_all(self.file.values())
112 def test_poolfiles(self):
114 Test the relation of the classes PoolFile and Location.
116 The code needs some explaination. The property Location.files is not a
117 list as in other relations because such a list would become rather
118 huge. It is a query object that can be queried, filtered, and iterated
119 as usual. But list like methods like append() and remove() are
120 supported as well which allows code like:
122 somelocation.files.append(somefile)
124 self.setup_locations()
125 self.setup_poolfiles()
126 location = self.session.query(Location)[0]
127 self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/', location.path)
128 self.assertEqual(2, location.files.count())
129 poolfile = location.files. \
130 filter(PoolFile.filename.like('%/hello/hello%')).one()
131 self.assertEqual('main/h/hello/hello_2.2-2.dsc', poolfile.filename)
132 self.assertEqual(location, poolfile.location)
134 self.assertEqual(poolfile, \
135 self.session.query(PoolFile).get(poolfile.file_id))
136 self.assertEqual(None, self.session.query(PoolFile).get(-1))
137 # test remove() and append()
138 location.files.remove(self.file['sl'])
139 # TODO: deletion should cascade automatically
140 self.session.delete(self.file['sl'])
141 self.session.refresh(location)
142 self.assertEqual(1, location.files.count())
143 # please note that we intentionally do not specify 'location' here
144 self.file['sl'] = PoolFile(filename = 'main/s/sl/sl_3.03-16.dsc', \
145 filesize = 0, md5sum = '')
146 location.files.append(self.file['sl'])
147 self.session.refresh(location)
148 self.assertEqual(2, location.files.count())
150 self.assertEqual('/srv/ftp-master.debian.org/ftp/pool/main/s/sl/sl_3.03-16.dsc', \
151 self.file['sl'].fullpath)
152 # test check_poolfile()
153 self.assertEqual((True, self.file['sl']), \
154 check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, '', \
155 location.location_id, self.session))
156 self.assertEqual((False, None), \
157 check_poolfile('foobar', 0, '', location.location_id, self.session))
158 self.assertEqual((False, self.file['sl']), \
159 check_poolfile('main/s/sl/sl_3.03-16.dsc', 42, '', \
160 location.location_id, self.session))
161 self.assertEqual((False, self.file['sl']), \
162 check_poolfile('main/s/sl/sl_3.03-16.dsc', 0, 'deadbeef', \
163 location.location_id, self.session))
164 # test get_poolfile_like_name()
165 self.assertEqual([self.file['sl']], \
166 get_poolfile_like_name('sl_3.03-16.dsc', self.session))
167 self.assertEqual([], get_poolfile_like_name('foobar', self.session))
169 def setup_maintainers(self):
170 'create some Maintainer objects'
173 self.maintainer['maintainer'] = Maintainer(name = 'Mr. Maintainer')
174 self.maintainer['uploader'] = Maintainer(name = 'Mrs. Uploader')
175 self.maintainer['lazyguy'] = Maintainer(name = 'Lazy Guy')
176 self.session.add_all(self.maintainer.values())
179 def setup_sources(self):
180 'create a DBSource object; but it cannot be stored in the DB yet'
182 self.source = DBSource(maintainer = self.maintainer['maintainer'],
183 changedby = self.maintainer['uploader'])
185 def test_maintainers(self):
187 tests relation between Maintainer and DBSource
189 TODO: add relations to changes_pending_source
192 self.setup_maintainers()
193 maintainer = self.maintainer['maintainer']
194 self.assertEqual(maintainer,
195 self.session.query(Maintainer).get(maintainer.maintainer_id))
196 uploader = self.maintainer['uploader']
197 self.assertEqual(uploader,
198 self.session.query(Maintainer).get(uploader.maintainer_id))
199 lazyguy = self.maintainer['lazyguy']
200 self.assertEqual(lazyguy,
201 self.session.query(Maintainer).get(lazyguy.maintainer_id))
203 #TODO: needs File and Location
204 #self.assertEqual(maintainer.maintains_sources, [self.source])
205 #self.assertEqual(maintainer.changed_sources, [])
206 #self.assertEqual(uploader.maintains_sources, [])
207 #self.assertEqual(uploader.changed_sources, [self.source])
208 #self.assertEqual(lazyguy.maintains_sources, [])
209 #self.assertEqual(lazyguy.changed_sources, [])
212 if __name__ == '__main__':