]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_cruft.py
Refactor functions getSource() and getBinaries().
[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.install_date = self.now()
18         self.setup_binaries()
19         # flush to make sure that the setup is correct
20         self.session.flush()
21
22     def test_newer_version(self):
23         'tests newer_version()'
24
25         list = newer_version('squeeze', 'sid', self.session)
26         self.assertEqual([], list)
27         self.file['sl_3.03-17.dsc'] = PoolFile(filename = 'main/s/sl/sl_3.03-17.dsc', \
28             location = self.loc['main'], filesize = 0, md5sum = '')
29         self.source['sl_3.03-17'] = DBSource(source = 'sl', version = '3.03-17', \
30             maintainer = self.maintainer['maintainer'], \
31             changedby = self.maintainer['uploader'], \
32             poolfile = self.file['sl_3.03-17.dsc'], install_date = self.install_date)
33         self.source['sl_3.03-17'].suites.append(self.suite['squeeze'])
34         list = newer_version('squeeze', 'sid', self.session)
35         self.assertEqual([('sl', '3.03-16', '3.03-17')], list)
36
37     def test_multiple_source(self):
38         'tests functions related to report_multiple_source()'
39
40         # test get_package_names()
41         suite = get_suite('sid', self.session)
42         self.assertEqual([('gnome-hello', ), ('hello', )], \
43             get_package_names(suite).all())
44         # test class NamedSource
45         src = NamedSource(suite, 'hello')
46         self.assertEqual('hello', src.source)
47         self.assertEqual(['2.2-1', '2.2-2'], src.versions)
48         self.assertEqual('hello(2.2-1, 2.2-2)', str(src))
49         # test class DejavuBinary
50         bin = DejavuBinary(suite, 'hello')
51         self.assertEqual(False, bin.has_multiple_sources())
52         # add another binary
53         self.file['hello_2.2-3'] = PoolFile(filename = 'main/s/sl/hello_2.2-3_i386.deb', \
54             location = self.loc['main'], filesize = 0, md5sum = '')
55         self.binary['hello_2.2-3_i386'] = DBBinary(package = 'hello', \
56             source = self.source['sl_3.03-16'], version = '2.2-3', \
57             maintainer = self.maintainer['maintainer'], \
58             architecture = self.arch['i386'], \
59             poolfile = self.file['hello_2.2-3'])
60         self.session.add(self.binary['hello_2.2-3_i386'])
61         bin = DejavuBinary(suite, 'hello')
62         self.assertEqual(False, bin.has_multiple_sources())
63         # add it to suite sid
64         self.binary['hello_2.2-3_i386'].suites.append(self.suite['sid'])
65         bin = DejavuBinary(suite, 'hello')
66         self.assertEqual(True, bin.has_multiple_sources())
67         self.assertEqual('hello built by: hello(2.2-1, 2.2-2), sl(3.03-16)', \
68             str(bin))
69
70 if __name__ == '__main__':
71     unittest.main()