dbtest_metadata.py 3.9 KB

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