dbtest_contents.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #! /usr/bin/env python3
  2. from db_test import DBDakTestCase, fixture
  3. from daklib.dbconn import *
  4. from daklib.contents import BinaryContentsWriter, BinaryContentsScanner, \
  5. UnpackedSource, SourceContentsScanner, SourceContentsWriter
  6. from os.path import normpath
  7. from sqlalchemy.exc import IntegrityError
  8. from sqlalchemy.orm.exc import FlushError
  9. from subprocess import CalledProcessError
  10. import unittest
  11. class ContentsTestCase(DBDakTestCase):
  12. """
  13. This TestCase checks the behaviour of contents generation.
  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. def test_duplicates2(self):
  30. '''
  31. Test the BinContents class for more duplication problems.
  32. '''
  33. self.setup_binaries()
  34. contents1 = BinContents(file='usr/bin/hello',
  35. binary=self.binary['hello_2.2-1_i386'])
  36. self.session.add(contents1)
  37. contents2 = BinContents(file='usr/bin/gruezi',
  38. binary=self.binary['hello_2.2-1_i386'])
  39. self.session.add(contents2)
  40. self.session.flush()
  41. # test duplicates
  42. contents2.file = 'usr/bin/hello'
  43. self.assertRaises(IntegrityError, self.session.flush)
  44. def test_duplicates3(self):
  45. '''
  46. Test the BinContents class even more.
  47. '''
  48. self.setup_binaries()
  49. contents1 = BinContents(file='usr/bin/hello',
  50. binary=self.binary['hello_2.2-1_i386'])
  51. self.session.add(contents1)
  52. # same file in different binary packages should be okay
  53. contents2 = BinContents(file='usr/bin/hello',
  54. binary=self.binary['gnome-hello_2.2-1_i386'])
  55. self.session.add(contents2)
  56. self.session.flush()
  57. def test_overridetype(self):
  58. '''
  59. Test the OverrideType class.
  60. '''
  61. self.setup_overridetypes()
  62. self.assertEqual('deb', self.otype['deb'].overridetype)
  63. self.assertEqual(0, self.otype['deb'].overrides.count())
  64. self.assertEqual(
  65. self.otype['deb'], get_override_type('deb', self.session))
  66. def test_section(self):
  67. '''
  68. Test Section class.
  69. '''
  70. self.setup_sections()
  71. self.assertEqual('python', self.section['python'].section)
  72. self.assertEqual('python', self.section['python'])
  73. self.assertTrue(self.section['python'] != 'java')
  74. self.assertEqual(
  75. self.section['python'], get_section('python', self.session))
  76. all_sections = get_sections(self.session)
  77. self.assertEqual(
  78. self.section['python'].section_id, all_sections['python'])
  79. self.assertEqual(0, self.section['python'].overrides.count())
  80. def test_priority(self):
  81. '''
  82. Test Priority class.
  83. '''
  84. self.setup_priorities()
  85. self.assertEqual('standard', self.prio['standard'].priority)
  86. self.assertEqual(3, self.prio['standard'].level)
  87. self.assertEqual('standard', self.prio['standard'])
  88. self.assertTrue(self.prio['standard'] != 'extra')
  89. self.assertEqual(
  90. self.prio['standard'], get_priority('standard', self.session))
  91. all_priorities = get_priorities(self.session)
  92. self.assertEqual(
  93. self.prio['standard'].priority_id, all_priorities['standard'])
  94. self.assertEqual(0, self.prio['standard'].overrides.count())
  95. def test_override(self):
  96. '''
  97. Test Override class.
  98. '''
  99. self.setup_overrides()
  100. list = get_override('hello', session=self.session)
  101. self.assertEqual(3, len(list))
  102. self.assertTrue(self.override['hello_sid_main_udeb'] in list)
  103. self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
  104. list = get_override('hello', suite='sid', session=self.session)
  105. self.assertEqual([self.override['hello_sid_main_udeb']], list)
  106. list = get_override('hello', suite=['sid'], session=self.session)
  107. self.assertEqual([self.override['hello_sid_main_udeb']], list)
  108. list = get_override('hello', component='contrib', session=self.session)
  109. self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
  110. list = get_override(
  111. 'hello', component=['contrib'], session=self.session)
  112. self.assertEqual([self.override['hello_lenny_contrib_deb']], list)
  113. list = get_override('hello', overridetype='deb', session=self.session)
  114. self.assertEqual(2, len(list))
  115. self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
  116. self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
  117. list = get_override(
  118. 'hello', overridetype=['deb'], session=self.session)
  119. self.assertEqual(2, len(list))
  120. self.assertTrue(self.override['hello_sid_main_udeb'] not in list)
  121. self.assertTrue(self.override['hello_squeeze_main_deb'] in list)
  122. # test the backrefs
  123. self.assertEqual(self.override['hello_sid_main_udeb'],
  124. self.suite['sid'].overrides.one())
  125. self.assertEqual(2, self.comp['main'].overrides.count())
  126. self.assertEqual(self.override['hello_sid_main_udeb'],
  127. self.comp['main'].overrides.filter_by(suite=self.suite['sid']).one())
  128. self.assertEqual(self.override['hello_sid_main_udeb'],
  129. self.otype['udeb'].overrides.one())
  130. def test_binarycontentswriter(self):
  131. '''
  132. Test the BinaryContentsWriter class.
  133. '''
  134. self.setup_binaries()
  135. self.setup_overrides()
  136. self.binary['hello_2.2-1_i386'].contents.append(
  137. BinContents(file='/usr/bin/hello'))
  138. self.session.flush()
  139. cw = BinaryContentsWriter(self.suite['squeeze'], self.arch['i386'],
  140. self.otype['deb'], self.comp['main'])
  141. self.assertEqual(
  142. ['/usr/bin/hello python/hello\n'],
  143. cw.get_list())
  144. # test formatline and sort order
  145. self.assertEqual(
  146. '/usr/bin/hello python/hello\n',
  147. cw.formatline('/usr/bin/hello', 'python/hello'))
  148. # test unicode support
  149. self.binary['hello_2.2-1_i386'].contents.append(
  150. BinContents(file='\xc3\xb6'))
  151. self.session.flush()
  152. if __name__ == '__main__':
  153. unittest.main()