]> git.decadent.org.uk Git - dak.git/blob - tests/dbtest_metadata.py
Refactor functions getSource() and getBinaries().
[dak.git] / tests / dbtest_metadata.py
1 #!/usr/bin/env python
2
3 from db_test import DBDakTestCase
4
5 from daklib.dbconn import DBConn, MetadataKey, BinaryMetadata, SourceMetadata
6
7 import unittest
8
9 class MetadataTestCase(DBDakTestCase):
10     """
11     This TestCase checks the metadata handling.
12     """
13
14     def setup_metadata(self):
15         '''
16         Setup the metadata objects.
17         '''
18         self.setup_binaries()
19         self.depends = MetadataKey('Depends')
20         self.session.add(self.depends)
21         self.session.flush()
22         self.bin_hello = self.binary['hello_2.2-1_i386']
23         self.src_hello = self.bin_hello.source
24         self.session.add(self.bin_hello)
25         self.session.add(self.src_hello)
26         self.hello_dep = BinaryMetadata(self.depends, 'foobar (>= 1.0)', self.bin_hello)
27         self.session.add(self.hello_dep)
28         self.recommends = MetadataKey('Recommends')
29         self.bin_hello.key[self.recommends] = BinaryMetadata(self.recommends, 'goodbye')
30         self.build_dep = MetadataKey('Build-Depends')
31         self.hello_bd = SourceMetadata(self.build_dep, 'foobar-dev', self.src_hello)
32         self.session.add(self.hello_bd)
33         self.homepage = MetadataKey('Homepage')
34         self.src_hello.key[self.homepage] = SourceMetadata(self.homepage, 'http://debian.org')
35         self.session.flush()
36
37     def test_mappers(self):
38         '''
39         Tests the mapper configuration.
40         '''
41         self.setup_metadata()
42         # MetadataKey
43         self.assertTrue(self.depends.key_id is not None)
44         # BinaryMetadata
45         self.assertEqual('hello', self.hello_dep.binary.package)
46         self.assertEqual('Depends', self.hello_dep.key.key)
47         self.assertEqual('foobar (>= 1.0)', self.hello_dep.value)
48         # SourceMetadata
49         self.assertEqual('hello', self.hello_bd.source.source)
50         self.assertEqual('Build-Depends', self.hello_bd.key.key)
51         self.assertEqual('foobar-dev', self.hello_bd.value)
52         # DBBinary relation
53         self.assertEqual(self.hello_dep, self.bin_hello.key[self.depends])
54         self.assertEqual('goodbye', self.bin_hello.key[self.recommends].value)
55         # DBSource relation
56         self.assertEqual(self.hello_bd, self.src_hello.key[self.build_dep])
57         self.assertEqual('http://debian.org', self.src_hello.key[self.homepage].value)
58
59     def test_association_proxy(self):
60         '''
61         Test the association proxies 'metadata' in DBBinary and DBSource.
62         '''
63         self.setup_metadata()
64         # DBBinary association proxy
65         essential = MetadataKey('Essential')
66         self.bin_hello.metadata[essential] = 'yes'
67         self.session.flush()
68         self.assertEqual('yes', self.bin_hello.metadata[essential])
69         self.assertEqual('foobar (>= 1.0)', self.bin_hello.metadata[self.depends])
70         self.assertTrue(self.recommends in self.bin_hello.metadata)
71         # DBSource association proxy
72         std_version = MetadataKey('Standards-Version')
73         self.src_hello.metadata[std_version] = '3.9.1'
74         self.session.flush()
75         self.assertEqual('3.9.1', self.src_hello.metadata[std_version])
76         self.assertEqual('http://debian.org', self.src_hello.metadata[self.homepage])
77         self.assertTrue(self.depends not in self.src_hello.metadata)
78
79     def test_delete(self):
80         '''
81         Tests the delete / cascading behaviour.
82         '''
83         self.setup_metadata()
84         self.session.delete(self.bin_hello)
85         # Remove associated binaries because we have no cascading rule for
86         # them.
87         for binary in self.src_hello.binaries:
88             self.session.delete(binary)
89         self.session.delete(self.src_hello)
90         self.session.flush()
91
92 if __name__ == '__main__':
93     unittest.main()