dbtest_contents.py 7.1 KB

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