test_pagure_flask_ui_repo_milestones.py 6.5 KB

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