test_pagure_flask_ui_repo_milestones.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2018 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import sys
  9. import unittest
  10. import os
  11. from mock import ANY, patch, MagicMock
  12. sys.path.insert(
  13. 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
  14. )
  15. import pagure.lib.query
  16. import tests
  17. class PagureFlaskRepoMilestonestests(tests.Modeltests):
  18. """ Tests for milestones in pagure """
  19. @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
  20. def setUp(self):
  21. """ Set up the environnment, ran before every tests. """
  22. super(PagureFlaskRepoMilestonestests, self).setUp()
  23. tests.create_projects(self.session)
  24. tests.create_projects_git(os.path.join(self.path, "repos"))
  25. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  26. msg = pagure.lib.query.new_issue(
  27. session=self.session,
  28. repo=repo,
  29. title="Test issue #1",
  30. content="We should work on this for the second time",
  31. user="foo",
  32. status="Open",
  33. )
  34. self.session.commit()
  35. self.assertEqual(msg.title, "Test issue #1")
  36. @patch(
  37. "pagure.decorators.admin_session_timedout",
  38. MagicMock(return_value=False),
  39. )
  40. def test_milestones_settings_empty(self):
  41. """ Test the settings page when no milestones are set. """
  42. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  43. self.assertEqual(repo.milestones, {})
  44. user = tests.FakeUser(username="pingou")
  45. with tests.user_set(self.app.application, user):
  46. output = self.app.get("/test/settings")
  47. self.assertEqual(output.status_code, 200)
  48. self.assertIn(
  49. "<title>Settings - test - Pagure</title>",
  50. output.get_data(as_text=True),
  51. )
  52. # Check that the milestones have their empty fields
  53. self.assertIn(
  54. """<div id="milestones">
  55. <div class="row p-t-1 milestone" id="milestone_1">
  56. <input type="hidden" name="milestones" value="1">
  57. <div class="col-sm-4 p-r-0">
  58. <input type="text" name="milestone_1_name"
  59. value="" size="3" class="form-control"/>
  60. </div>
  61. <div class="col-sm-4 p-r-0">
  62. <input type="text" name="milestone_1_date"
  63. value="" class="form-control"/>
  64. </div>
  65. <div class="col-sm-2 p-r-0" >
  66. <span class="fa fa-long-arrow-up milestone_order_up"
  67. data-stone="1"></span>
  68. <span class="fa fa-long-arrow-down milestone_order_bottom"
  69. data-stone="1"></span>
  70. </div>
  71. <div class="col-sm-1 p-r-0" >
  72. <input type="checkbox" name="milestone_1_active" />
  73. </div>
  74. </div>""",
  75. output.get_data(as_text=True),
  76. )
  77. @patch(
  78. "pagure.decorators.admin_session_timedout",
  79. MagicMock(return_value=False),
  80. )
  81. def test_setting_retrieving_milestones(self):
  82. """ Test setting and retrieving milestones off a project. """
  83. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  84. milestones = {
  85. "1.0": None,
  86. "1.1": None,
  87. "1.2": "2018-12-31",
  88. "2.0": "2019",
  89. "3.0": "future",
  90. "4.0": None,
  91. }
  92. repo.milestones = milestones
  93. self.session.add(repo)
  94. self.session.commit()
  95. self.assertEqual(
  96. repo.milestones,
  97. {
  98. "1.0": {"active": True, "date": None},
  99. "1.1": {"active": True, "date": None},
  100. "1.2": {"active": True, "date": "2018-12-31"},
  101. "2.0": {"active": True, "date": "2019"},
  102. "3.0": {"active": True, "date": "future"},
  103. "4.0": {"active": True, "date": None},
  104. },
  105. )
  106. @patch(
  107. "pagure.decorators.admin_session_timedout",
  108. MagicMock(return_value=False),
  109. )
  110. def test_issue_page_milestone_actives(self):
  111. """ Test viewing tickets on a project having milestones, all active.
  112. """
  113. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  114. milestones = {"1.0": None, "2.0": "2019", "3.0": "future"}
  115. milestones_keys = ["1.0", "3.0", "2.0"]
  116. repo.milestones = milestones
  117. repo.milestones_keys = milestones_keys
  118. self.session.add(repo)
  119. self.session.commit()
  120. user = tests.FakeUser(username="pingou")
  121. with tests.user_set(self.app.application, user):
  122. output = self.app.get("/test/issue/1")
  123. self.assertEqual(output.status_code, 200)
  124. self.assertIn(
  125. '<select class="form-control c-select" id="milestone" name="milestone">'
  126. '<option selected value=""></option>'
  127. '<option value="1.0">1.0</option>'
  128. '<option value="3.0">3.0</option>'
  129. '<option value="2.0">2.0</option>'
  130. "</select>",
  131. output.get_data(as_text=True),
  132. )
  133. @patch(
  134. "pagure.decorators.admin_session_timedout",
  135. MagicMock(return_value=False),
  136. )
  137. def test_issue_page_milestone_not_allactives(self):
  138. """ Test viewing tickets on a project having milestones, not all
  139. being active.
  140. """
  141. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  142. milestones = {
  143. "1.0": {"date": None, "active": False},
  144. "2.0": {"date": "2018-01-01", "active": False},
  145. "3.0": {"date": "2025-01-01", "active": True},
  146. "4.0": {"date": "future", "active": True},
  147. }
  148. milestones_keys = ["1.0", "2.0", "3.0", "4.0"]
  149. repo.milestones = milestones
  150. repo.milestones_keys = milestones_keys
  151. self.session.add(repo)
  152. self.session.commit()
  153. user = tests.FakeUser(username="pingou")
  154. with tests.user_set(self.app.application, user):
  155. output = self.app.get("/test/issue/1")
  156. self.assertEqual(output.status_code, 200)
  157. self.assertIn(
  158. '<select class="form-control c-select" id="milestone" name="milestone">'
  159. '<option selected value=""></option>'
  160. '<option value="3.0">3.0</option>'
  161. '<option value="4.0">4.0</option>'
  162. "</select>",
  163. output.get_data(as_text=True),
  164. )
  165. if __name__ == "__main__":
  166. unittest.main(verbosity=2)