]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_contents.py
Add a test for class BinContents.
[dak.git] / tests / dbtest_contents.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import DBConn, BinContents
6
7 from sqlalchemy.exc import FlushError, IntegrityError
8 import unittest
9
10 class ContentsTestCase(DBDakTestCase):
11     """
12     This TestCase checks the behaviour of contents generation.
13     """
14
15     def test_duplicates1(self):
16         '''
17         Test the BinContents class for duplication problems.
18         '''
19         self.setup_binaries()
20         contents1 = BinContents(file = 'usr/bin/hello', \
21             binary = self.binary['hello_2.2-1_i386'])
22         self.session.add(contents1)
23         self.session.flush()
24         # test duplicates
25         contents2 = BinContents(file = 'usr/bin/hello', \
26             binary = self.binary['hello_2.2-1_i386'])
27         self.session.add(contents2)
28         self.assertRaises(FlushError, self.session.flush)
29
30     def test_duplicates2(self):
31         '''
32         Test the BinContents class for more duplication problems.
33         '''
34         self.setup_binaries()
35         contents1 = BinContents(file = 'usr/bin/hello', \
36             binary = self.binary['hello_2.2-1_i386'])
37         self.session.add(contents1)
38         contents2 = BinContents(file = 'usr/bin/gruezi', \
39             binary = self.binary['hello_2.2-1_i386'])
40         self.session.add(contents2)
41         self.session.flush()
42         # test duplicates
43         contents2.file = 'usr/bin/hello'
44         self.assertRaises(IntegrityError, self.session.flush)
45
46     def test_duplicates3(self):
47         '''
48         Test the BinContents class even more.
49         '''
50         self.setup_binaries()
51         contents1 = BinContents(file = 'usr/bin/hello', \
52             binary = self.binary['hello_2.2-1_i386'])
53         self.session.add(contents1)
54         # same file in different binary packages should be okay
55         contents2 = BinContents(file = 'usr/bin/hello', \
56             binary = self.binary['gnome-hello_2.2-1_i386'])
57         self.session.add(contents2)
58         self.session.flush()
59
60 if __name__ == '__main__':
61     unittest.main()