]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_cruft.py
Merge branch 'master' into dbtests
[dak.git] / tests / dbtest_cruft.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import *
6 from daklib.cruft import *
7
8 import unittest
9
10 class CruftTestCase(DBDakTestCase):
11     """
12     This class checks various functions of cruft-report.
13     """
14
15     def setUp(self):
16         super(CruftTestCase, self).setUp()
17         self.setup_binaries()
18         # flush to make sure that the setup is correct
19         self.session.flush()
20
21     def test_newer_version(self):
22         'tests newer_version()'
23
24         list = newer_version('squeeze', 'sid', self.session)
25         self.assertEqual([], list)
26         self.file['sl_3.03-17.dsc'] = PoolFile(filename = 'main/s/sl/sl_3.03-17.dsc', \
27             location = self.loc['main'], filesize = 0, md5sum = '')
28         self.source['sl_3.03-17'] = DBSource(source = 'sl', version = '3.03-17', \
29             maintainer = self.maintainer['maintainer'], \
30             changedby = self.maintainer['uploader'], \
31             poolfile = self.file['sl_3.03-17.dsc'], install_date = self.now())
32         self.source['sl_3.03-17'].suites.append(self.suite['squeeze'])
33         list = newer_version('squeeze', 'sid', self.session)
34         self.assertEqual([('sl', '3.03-16', '3.03-17')], list)
35
36     def test_multiple_source(self):
37         'tests functions related to report_multiple_source()'
38
39         # test get_package_names()
40         suite = get_suite('sid', self.session)
41         self.assertEqual([('gnome-hello', ), ('hello', )], \
42             get_package_names(suite).all())
43         # test class NamedSource
44         src = NamedSource(suite, 'hello')
45         self.assertEqual('hello', src.source)
46         self.assertEqual(['2.2-1', '2.2-2'], src.versions)
47         self.assertEqual('hello(2.2-1, 2.2-2)', str(src))
48         # test class DejavuBinary
49         bin = DejavuBinary(suite, 'hello')
50         self.assertEqual(False, bin.has_multiple_sources())
51         # add another binary
52         self.file['hello_2.2-3'] = PoolFile(filename = 'main/s/sl/hello_2.2-3_i386.deb', \
53             location = self.loc['main'], filesize = 0, md5sum = '')
54         self.binary['hello_2.2-3_i386'] = DBBinary(package = 'hello', \
55             source = self.source['sl_3.03-16'], version = '2.2-3', \
56             maintainer = self.maintainer['maintainer'], \
57             architecture = self.arch['i386'], \
58             poolfile = self.file['hello_2.2-3'])
59         self.session.add(self.binary['hello_2.2-3_i386'])
60         bin = DejavuBinary(suite, 'hello')
61         self.assertEqual(False, bin.has_multiple_sources())
62         # add it to suite sid
63         self.binary['hello_2.2-3_i386'].suites.append(self.suite['sid'])
64         bin = DejavuBinary(suite, 'hello')
65         self.assertEqual(True, bin.has_multiple_sources())
66         self.assertEqual('hello built by: hello(2.2-1, 2.2-2), sl(3.03-16)', \
67             str(bin))
68
69 if __name__ == '__main__':
70     unittest.main()