test_pagure_flask_ui_repo_milestones.py 6.4 KB

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