1
0

test_pagure_lib_drop_issue.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2017 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. __requires__ = ['SQLAlchemy >= 0.8']
  8. import pkg_resources
  9. import unittest
  10. import shutil
  11. import sys
  12. import os
  13. from mock import patch, MagicMock
  14. sys.path.insert(0, os.path.join(os.path.dirname(
  15. os.path.abspath(__file__)), '..'))
  16. import pagure
  17. import pagure.lib
  18. import pagure.lib.model
  19. import tests
  20. class PagureLibDropIssuetests(tests.Modeltests):
  21. """ Tests for pagure.lib.drop_issue """
  22. @patch('pagure.lib.git.update_git')
  23. @patch('pagure.lib.notify.send_email')
  24. def setUp(self, p_send_email, p_ugt):
  25. """ Create a couple of tickets and add tag to the project so we can
  26. play with them later.
  27. """
  28. super(PagureLibDropIssuetests, self).setUp()
  29. p_send_email.return_value = True
  30. p_ugt.return_value = True
  31. tests.create_projects(self.session)
  32. repo = pagure.get_authorized_project(self.session, 'test')
  33. # Before
  34. issues = pagure.lib.search_issues(self.session, repo)
  35. self.assertEqual(len(issues), 0)
  36. self.assertEqual(repo.open_tickets, 0)
  37. self.assertEqual(repo.open_tickets_public, 0)
  38. # Create two issues to play with
  39. msg = pagure.lib.new_issue(
  40. session=self.session,
  41. repo=repo,
  42. title='Test issue',
  43. content='We should work on this',
  44. user='pingou',
  45. ticketfolder=None
  46. )
  47. self.session.commit()
  48. self.assertEqual(msg.title, 'Test issue')
  49. self.assertEqual(repo.open_tickets, 1)
  50. self.assertEqual(repo.open_tickets_public, 1)
  51. msg = pagure.lib.new_issue(
  52. session=self.session,
  53. repo=repo,
  54. title='Test issue #2',
  55. content='We should work on this for the second time',
  56. user='foo',
  57. status='Open',
  58. ticketfolder=None
  59. )
  60. self.session.commit()
  61. self.assertEqual(msg.title, 'Test issue #2')
  62. self.assertEqual(repo.open_tickets, 2)
  63. self.assertEqual(repo.open_tickets_public, 2)
  64. # After
  65. issues = pagure.lib.search_issues(self.session, repo)
  66. self.assertEqual(len(issues), 2)
  67. # Add tag to the project
  68. pagure.lib.new_tag(
  69. self.session,
  70. 'red',
  71. 'red tag',
  72. '#ff0000',
  73. repo.id
  74. )
  75. self.session.commit()
  76. repo = pagure.get_authorized_project(self.session, 'test')
  77. self.assertEqual(
  78. str(repo.tags_colored),
  79. '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
  80. )
  81. @patch('pagure.lib.git.update_git')
  82. @patch('pagure.lib.notify.send_email')
  83. def test_drop_issue(self, p_send_email, p_ugt):
  84. """ Test the drop_issue of pagure.lib.
  85. We had an issue where we could not delete issue that had been tagged
  86. with this test, we create two issues, tag one of them and delete
  87. it, ensuring it all goes well.
  88. """
  89. p_send_email.return_value = True
  90. p_ugt.return_value = True
  91. repo = pagure.get_authorized_project(self.session, 'test')
  92. # Add tag to the second issue
  93. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  94. msgs = pagure.lib.update_tags(
  95. self.session,
  96. issue,
  97. tags=['red'],
  98. username='pingou',
  99. ticketfolder=None,
  100. )
  101. self.session.commit()
  102. self.assertEqual(msgs, ['Issue tagged with: red'])
  103. repo = pagure.get_authorized_project(self.session, 'test')
  104. self.assertEqual(len(repo.issues), 2)
  105. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  106. self.assertEqual(
  107. str(issue.tags),
  108. '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
  109. )
  110. # Drop the issue #2
  111. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  112. pagure.lib.drop_issue(
  113. self.session, issue, user='pingou', ticketfolder=None)
  114. self.session.commit()
  115. repo = pagure.get_authorized_project(self.session, 'test')
  116. self.assertEqual(len(repo.issues), 1)
  117. @patch('pagure.lib.git.update_git')
  118. @patch('pagure.lib.notify.send_email')
  119. def test_drop_issue_two_issues_one_tag(self, p_send_email, p_ugt):
  120. """ Test the drop_issue of pagure.lib.
  121. We had an issue where we could not delete issue that had been tagged
  122. with this test, we create two issues, tag them both and delete one
  123. then we check that the other issue is still tagged.
  124. """
  125. p_send_email.return_value = True
  126. p_ugt.return_value = True
  127. repo = pagure.get_authorized_project(self.session, 'test')
  128. # Add the tag to both issues
  129. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  130. msgs = pagure.lib.update_tags(
  131. self.session,
  132. issue,
  133. tags=['red'],
  134. username='pingou',
  135. ticketfolder=None,
  136. )
  137. self.session.commit()
  138. self.assertEqual(msgs, ['Issue tagged with: red'])
  139. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  140. msgs = pagure.lib.update_tags(
  141. self.session,
  142. issue,
  143. tags=['red'],
  144. username='pingou',
  145. ticketfolder=None,
  146. )
  147. self.session.commit()
  148. self.assertEqual(msgs, ['Issue tagged with: red'])
  149. repo = pagure.get_authorized_project(self.session, 'test')
  150. self.assertEqual(len(repo.issues), 2)
  151. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  152. self.assertEqual(
  153. str(issue.tags),
  154. '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
  155. )
  156. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  157. self.assertEqual(
  158. str(issue.tags),
  159. '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
  160. )
  161. # Drop the issue #2
  162. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  163. pagure.lib.drop_issue(
  164. self.session, issue, user='pingou', ticketfolder=None)
  165. self.session.commit()
  166. repo = pagure.get_authorized_project(self.session, 'test')
  167. self.assertEqual(len(repo.issues), 1)
  168. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  169. self.assertEqual(
  170. str(issue.tags),
  171. '[TagColored(id: 1, tag:red, tag_description:red tag, color:#ff0000)]'
  172. )
  173. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  174. self.assertIsNone(issue)
  175. if __name__ == '__main__':
  176. unittest.main(verbosity=2)