dbtest_metadata.py 3.6 KB

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