3 from db_test import DBDakTestCase
5 from daklib.dbconn import DBConn, MetadataKey, BinaryMetadata, SourceMetadata
9 class MetadataTestCase(DBDakTestCase):
11 This TestCase checks the metadata handling.
14 def setup_metadata(self):
16 Setup the metadata objects.
19 self.depends = MetadataKey('Depends')
20 self.session.add(self.depends)
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')
37 def test_mappers(self):
39 Tests the mapper configuration.
43 self.assertTrue(self.depends.key_id is not None)
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)
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)
53 self.assertEqual(self.hello_dep, self.bin_hello.key[self.depends])
54 self.assertEqual('goodbye', self.bin_hello.key[self.recommends].value)
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)
59 def test_association_proxy(self):
61 Test the association proxies 'metadata' in DBBinary and DBSource.
64 # DBBinary association proxy
65 essential = MetadataKey('Essential')
66 self.bin_hello.metadata[essential] = 'yes'
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'
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)
79 def test_delete(self):
81 Tests the delete / cascading behaviour.
84 self.session.delete(self.bin_hello)
85 # Remove associated binaries because we have no cascading rule for
87 for binary in self.src_hello.binaries:
88 self.session.delete(binary)
89 self.session.delete(self.src_hello)
92 if __name__ == '__main__':