test_pagure_flask_ui_priorities.py 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2016-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 datetime
  9. import json
  10. import unittest
  11. import shutil
  12. import sys
  13. import tempfile
  14. import os
  15. import pygit2
  16. from mock import patch, MagicMock
  17. sys.path.insert(0, os.path.join(os.path.dirname(
  18. os.path.abspath(__file__)), '..'))
  19. import pagure.lib.query
  20. import tests
  21. from pagure.lib.repo import PagureRepo
  22. class PagureFlaskPrioritiestests(tests.Modeltests):
  23. """ Tests for the behavior of priorities in pagure """
  24. @patch('pagure.lib.git.update_git')
  25. @patch('pagure.lib.notify.send_email')
  26. def test_ticket_with_no_priority(self, p_send_email, p_ugt):
  27. """ Test creating a ticket without priority. """
  28. p_send_email.return_value = True
  29. p_ugt.return_value = True
  30. tests.create_projects(self.session)
  31. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  32. user = tests.FakeUser()
  33. user.username = 'pingou'
  34. with tests.user_set(self.app.application, user):
  35. # Get the CSRF token
  36. output = self.app.get('/test/new_issue')
  37. self.assertEqual(output.status_code, 200)
  38. output_text = output.get_data(as_text=True)
  39. self.assertTrue(
  40. '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
  41. in output_text)
  42. csrf_token = output_text.split(
  43. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  44. data = {
  45. 'title': 'Test issue',
  46. 'issue_content': 'We really should improve on this issue',
  47. 'status': 'Open',
  48. 'csrf_token': csrf_token,
  49. }
  50. # Create the issue
  51. output = self.app.post(
  52. '/test/new_issue', data=data, follow_redirects=True)
  53. self.assertEqual(output.status_code, 200)
  54. output_text = output.get_data(as_text=True)
  55. self.assertIn(
  56. '<title>Issue #1: Test issue - test - Pagure</title>',
  57. output_text)
  58. self.assertIn(
  59. '<a class="btn btn-outline-secondary btn-sm border-0" '
  60. 'href="/test/issue/1/edit" title="Edit this issue">',
  61. output_text)
  62. self.assertNotIn('<div class="ml-2" id="priority_plain">', output_text)
  63. self.assertNotIn('<option value="1">High</option>', output_text)
  64. @patch('pagure.lib.git.update_git')
  65. @patch('pagure.lib.notify.send_email')
  66. def test_ticket_with_priorities(self, p_send_email, p_ugt):
  67. """ Test creating a ticket with priorities. """
  68. p_send_email.return_value = True
  69. p_ugt.return_value = True
  70. tests.create_projects(self.session)
  71. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  72. # Set some priorities
  73. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  74. repo.priorities = {'1': 'High', '2': 'Normal'}
  75. self.session.add(repo)
  76. self.session.commit()
  77. user = tests.FakeUser()
  78. user.username = 'pingou'
  79. with tests.user_set(self.app.application, user):
  80. # Get the CSRF token
  81. output = self.app.get('/test/new_issue')
  82. self.assertEqual(output.status_code, 200)
  83. output_text = output.get_data(as_text=True)
  84. self.assertTrue(
  85. '<h4 class="font-weight-bold mb-4">New Issue</h4>\n'
  86. in output_text)
  87. csrf_token = output_text.split(
  88. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  89. data = {
  90. 'title': 'Test issue',
  91. 'issue_content': 'We really should improve on this issue',
  92. 'status': 'Open',
  93. 'csrf_token': csrf_token,
  94. }
  95. # Create the issue
  96. output = self.app.post(
  97. '/test/new_issue', data=data, follow_redirects=True)
  98. self.assertEqual(output.status_code, 200)
  99. output_text = output.get_data(as_text=True)
  100. self.assertIn(
  101. '<title>Issue #1: Test issue - test - Pagure</title>',
  102. output_text)
  103. self.assertIn(
  104. '<a class="btn btn-outline-secondary btn-sm border-0" '
  105. 'href="/test/issue/1/edit" title="Edit this issue">',
  106. output_text)
  107. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  108. self.assertIn('<option value="1">High</option>', output_text)
  109. def test_update_priorities(self):
  110. """ Test updating priorities of a repo. """
  111. tests.create_projects(self.session)
  112. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  113. # Set some priorities
  114. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  115. self.assertEqual(repo.priorities, {})
  116. user = tests.FakeUser()
  117. user.username = 'pingou'
  118. with tests.user_set(self.app.application, user):
  119. # Get the CSRF token
  120. output = self.app.get('/test/settings')
  121. self.assertEqual(output.status_code, 200)
  122. output_text = output.get_data(as_text=True)
  123. self.assertIn(
  124. '<title>Settings - test - Pagure</title>', output_text)
  125. self.assertIn(
  126. '<h5 class="pl-2 font-weight-bold text-muted">'
  127. 'Project Settings</h5>\n', output_text)
  128. csrf_token = output_text.split(
  129. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  130. data = {
  131. 'priority_weigth': 1,
  132. 'priority_title': 'High',
  133. }
  134. output = self.app.post(
  135. '/test/update/priorities', data=data, follow_redirects=True)
  136. self.assertEqual(output.status_code, 200)
  137. output_text = output.get_data(as_text=True)
  138. # Check the redirect
  139. self.assertIn(
  140. '<title>Settings - test - Pagure</title>', output_text)
  141. self.assertIn(
  142. '<h5 class="pl-2 font-weight-bold text-muted">'
  143. 'Project Settings</h5>\n', output_text)
  144. # Check the result of the action -- None, no CSRF
  145. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  146. self.assertEqual(repo.priorities, {})
  147. data = {
  148. 'priority_weigth': 1,
  149. 'priority_title': 'High',
  150. 'csrf_token': csrf_token,
  151. }
  152. output = self.app.post(
  153. '/test/update/priorities', data=data, follow_redirects=True)
  154. self.assertEqual(output.status_code, 200)
  155. output_text = output.get_data(as_text=True)
  156. # Check the redirect
  157. self.assertIn(
  158. '<title>Settings - test - Pagure</title>', output_text)
  159. self.assertIn(
  160. '<h5 class="pl-2 font-weight-bold text-muted">'
  161. 'Project Settings</h5>\n', output_text)
  162. # Check the result of the action -- Priority recorded
  163. self.session.commit()
  164. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  165. self.assertEqual(repo.priorities, {'': '', '1': 'High'})
  166. data = {
  167. 'priority_weigth': [1, 2, 3],
  168. 'priority_title': ['High', 'Normal', 'Low'],
  169. 'csrf_token': csrf_token,
  170. }
  171. output = self.app.post(
  172. '/test/update/priorities', data=data, follow_redirects=True)
  173. self.assertEqual(output.status_code, 200)
  174. output_text = output.get_data(as_text=True)
  175. # Check the redirect
  176. self.assertIn(
  177. '<title>Settings - test - Pagure</title>', output_text)
  178. self.assertIn(
  179. '<h5 class="pl-2 font-weight-bold text-muted">'
  180. 'Project Settings</h5>\n', output_text)
  181. # Check the ordering
  182. self.assertTrue(
  183. output_text.find('High') < output_text.find('Normal'))
  184. self.assertTrue(
  185. output_text.find('Normal') < output_text.find('Low'))
  186. # Check the result of the action -- Priority recorded
  187. self.session.commit()
  188. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  189. self.assertEqual(
  190. repo.priorities,
  191. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  192. )
  193. # Check error - less weigths than titles
  194. data = {
  195. 'priority_weigth': [1, 2],
  196. 'priority_title': ['High', 'Normal', 'Low'],
  197. 'csrf_token': csrf_token,
  198. }
  199. output = self.app.post(
  200. '/test/update/priorities', data=data, follow_redirects=True)
  201. self.assertEqual(output.status_code, 200)
  202. output_text = output.get_data(as_text=True)
  203. # Check the redirect
  204. self.assertIn(
  205. '<title>Settings - test - Pagure</title>', output_text)
  206. self.assertIn(
  207. '<h5 class="pl-2 font-weight-bold text-muted">'
  208. 'Project Settings</h5>\n', output_text)
  209. self.assertIn(
  210. 'Priorities weights and titles are '
  211. 'not of the same length', output_text)
  212. # Check the result of the action -- Priorities un-changed
  213. self.session.commit()
  214. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  215. self.assertEqual(
  216. repo.priorities,
  217. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  218. )
  219. # Check error - weigths must be integer
  220. data = {
  221. 'priority_weigth': [1, 2, 'c'],
  222. 'priority_title': ['High', 'Normal', 'Low'],
  223. 'csrf_token': csrf_token,
  224. }
  225. output = self.app.post(
  226. '/test/update/priorities', data=data, follow_redirects=True)
  227. self.assertEqual(output.status_code, 200)
  228. output_text = output.get_data(as_text=True)
  229. # Check the redirect
  230. self.assertIn(
  231. '<title>Settings - test - Pagure</title>', output_text)
  232. self.assertIn(
  233. '<h5 class="pl-2 font-weight-bold text-muted">'
  234. 'Project Settings</h5>\n', output_text)
  235. self.assertIn(
  236. 'Priorities weights must be numbers',
  237. output_text)
  238. # Check the result of the action -- Priorities un-changed
  239. self.session.commit()
  240. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  241. self.assertEqual(
  242. repo.priorities,
  243. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  244. )
  245. # Check error - Twice the same priority weigth
  246. data = {
  247. 'priority_weigth': [1, 2, 2],
  248. 'priority_title': ['High', 'Normal', 'Low'],
  249. 'csrf_token': csrf_token,
  250. }
  251. output = self.app.post(
  252. '/test/update/priorities', data=data, follow_redirects=True)
  253. self.assertEqual(output.status_code, 200)
  254. output_text = output.get_data(as_text=True)
  255. # Check the redirect
  256. self.assertIn(
  257. '<title>Settings - test - Pagure</title>', output_text)
  258. self.assertIn(
  259. '<h5 class="pl-2 font-weight-bold text-muted">'
  260. 'Project Settings</h5>\n', output_text)
  261. self.assertIn(
  262. 'Priority weight 2 is present 2 times',
  263. output_text)
  264. # Check the result of the action -- Priorities un-changed
  265. self.session.commit()
  266. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  267. self.assertEqual(
  268. repo.priorities,
  269. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  270. )
  271. # Check error - Twice the same priority title
  272. data = {
  273. 'priority_weigth': [1, 2, 3],
  274. 'priority_title': ['High', 'Normal', 'Normal'],
  275. 'csrf_token': csrf_token,
  276. }
  277. output = self.app.post(
  278. '/test/update/priorities', data=data, follow_redirects=True)
  279. self.assertEqual(output.status_code, 200)
  280. output_text = output.get_data(as_text=True)
  281. # Check the redirect
  282. self.assertIn(
  283. '<title>Settings - test - Pagure</title>', output_text)
  284. self.assertIn(
  285. '<h5 class="pl-2 font-weight-bold text-muted">'
  286. 'Project Settings</h5>\n', output_text)
  287. self.assertIn(
  288. 'Priority Normal is present 2 times',
  289. output_text)
  290. # Check the result of the action -- Priorities un-changed
  291. self.session.commit()
  292. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  293. self.assertEqual(
  294. repo.priorities,
  295. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  296. )
  297. # Check the behavior if the project disabled the issue tracker
  298. settings = repo.settings
  299. settings['issue_tracker'] = False
  300. repo.settings = settings
  301. self.session.add(repo)
  302. self.session.commit()
  303. output = self.app.post(
  304. '/test/update/priorities', data=data)
  305. self.assertEqual(output.status_code, 404)
  306. # Check for an invalid project
  307. output = self.app.post(
  308. '/foo/update/priorities', data=data)
  309. self.assertEqual(output.status_code, 404)
  310. # Check for a non-admin user
  311. settings = repo.settings
  312. settings['issue_tracker'] = True
  313. repo.settings = settings
  314. self.session.add(repo)
  315. self.session.commit()
  316. user.username = 'ralph'
  317. with tests.user_set(self.app.application, user):
  318. output = self.app.post(
  319. '/test/update/priorities', data=data)
  320. self.assertEqual(output.status_code, 403)
  321. @patch('pagure.lib.git.update_git')
  322. @patch('pagure.lib.notify.send_email')
  323. def test_reset_priorities(self, p_send_email, p_ugt):
  324. """ Test resetting the priorities of a repo. """
  325. p_send_email.return_value = True
  326. p_ugt.return_value = True
  327. tests.create_projects(self.session)
  328. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  329. # Start from scrach on priorities
  330. repo = pagure.lib.query._get_project(self.session, 'test')
  331. self.assertEqual(repo.priorities, {})
  332. user = tests.FakeUser()
  333. user.username = 'pingou'
  334. with tests.user_set(self.app.application, user):
  335. # Get the CSRF token
  336. output = self.app.get('/test/settings')
  337. self.assertEqual(output.status_code, 200)
  338. output_text = output.get_data(as_text=True)
  339. self.assertIn(
  340. '<title>Settings - test - Pagure</title>', output_text)
  341. self.assertIn(
  342. '<h5 class="pl-2 font-weight-bold text-muted">'
  343. 'Project Settings</h5>\n', output_text)
  344. csrf_token = output_text.split(
  345. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  346. # Set some priorities
  347. data = {
  348. 'priority_weigth': [1, 2, 3],
  349. 'priority_title': ['High', 'Normal', 'Low'],
  350. 'csrf_token': csrf_token,
  351. }
  352. output = self.app.post(
  353. '/test/update/priorities', data=data, follow_redirects=True)
  354. self.assertEqual(output.status_code, 200)
  355. output_text = output.get_data(as_text=True)
  356. self.assertIn(
  357. '<title>Settings - test - Pagure</title>', output_text)
  358. self.assertIn(
  359. '<h5 class="pl-2 font-weight-bold text-muted">'
  360. 'Project Settings</h5>\n', output_text)
  361. # Check the result of the action -- Priority recorded
  362. self.session.commit()
  363. repo = pagure.lib.query._get_project(self.session, 'test')
  364. self.assertEqual(
  365. repo.priorities,
  366. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  367. )
  368. # Create an issue
  369. data = {
  370. 'title': 'Test issue',
  371. 'issue_content': 'We really should improve on this issue',
  372. 'status': 'Open',
  373. 'csrf_token': csrf_token,
  374. }
  375. output = self.app.post(
  376. '/test/new_issue', data=data, follow_redirects=True)
  377. self.assertEqual(output.status_code, 200)
  378. output_text = output.get_data(as_text=True)
  379. self.assertIn(
  380. '<title>Issue #1: Test issue - test - Pagure</title>',
  381. output_text)
  382. self.assertIn(
  383. '<a class="btn btn-outline-secondary btn-sm border-0" '
  384. 'href="/test/issue/1/edit" title="Edit this issue">',
  385. output_text)
  386. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  387. self.assertIn('<option value="1">High</option>', output_text)
  388. # Check that the ticket *does* have priorities
  389. output = self.app.get('/test/issue/1')
  390. self.assertEqual(output.status_code, 200)
  391. output_text = output.get_data(as_text=True)
  392. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  393. self.assertIn('<option value="1">High</option>', output_text)
  394. # Reset the priorities
  395. data = {
  396. 'csrf_token': csrf_token,
  397. }
  398. output = self.app.post(
  399. '/test/update/priorities', data=data, follow_redirects=True)
  400. self.assertEqual(output.status_code, 200)
  401. output_text = output.get_data(as_text=True)
  402. self.assertIn(
  403. '<title>Settings - test - Pagure</title>', output_text)
  404. self.assertIn(
  405. '<h5 class="pl-2 font-weight-bold text-muted">'
  406. 'Project Settings</h5>\n', output_text)
  407. # Check that the issue list renders fine
  408. output = self.app.get('/test/issues')
  409. self.assertEqual(output.status_code, 200)
  410. output_text = output.get_data(as_text=True)
  411. # Check that the ticket *does not* have priorities
  412. output = self.app.get('/test/issue/1')
  413. self.assertEqual(output.status_code, 200)
  414. output_text = output.get_data(as_text=True)
  415. self.assertNotIn('<div class="ml-2" id="priority_plain">', output_text)
  416. self.assertNotIn('<option value="1">High</option>', output_text)
  417. # Check the result of the action -- Priority reset
  418. self.session.commit()
  419. repo = pagure.lib.query._get_project(self.session, 'test')
  420. self.assertEqual(repo.priorities, {})
  421. @patch('pagure.lib.git.update_git')
  422. @patch('pagure.lib.notify.send_email')
  423. def test_reset_priorities_None(self, p_send_email, p_ugt):
  424. """ Test resetting the priorities of a repo. """
  425. p_send_email.return_value = True
  426. p_ugt.return_value = True
  427. tests.create_projects(self.session)
  428. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  429. # Start from scrach on priorities
  430. repo = pagure.lib.query._get_project(self.session, 'test')
  431. self.assertEqual(repo.priorities, {})
  432. user = tests.FakeUser()
  433. user.username = 'pingou'
  434. with tests.user_set(self.app.application, user):
  435. # Get the CSRF token
  436. output = self.app.get('/test/settings')
  437. self.assertEqual(output.status_code, 200)
  438. output_text = output.get_data(as_text=True)
  439. self.assertIn(
  440. '<title>Settings - test - Pagure</title>', output_text)
  441. self.assertIn(
  442. '<h5 class="pl-2 font-weight-bold text-muted">'
  443. 'Project Settings</h5>\n', output_text)
  444. csrf_token = output_text.split(
  445. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  446. # Set some priorities
  447. data = {
  448. 'priority_weigth': [1, 2, 3],
  449. 'priority_title': ['High', 'Normal', 'Low'],
  450. 'csrf_token': csrf_token,
  451. }
  452. output = self.app.post(
  453. '/test/update/priorities', data=data, follow_redirects=True)
  454. self.assertEqual(output.status_code, 200)
  455. output_text = output.get_data(as_text=True)
  456. self.assertIn(
  457. '<title>Settings - test - Pagure</title>', output_text)
  458. self.assertIn(
  459. '<h5 class="pl-2 font-weight-bold text-muted">'
  460. 'Project Settings</h5>\n', output_text)
  461. # Check the result of the action -- Priority recorded
  462. self.session.commit()
  463. repo = pagure.lib.query._get_project(self.session, 'test')
  464. self.assertEqual(
  465. repo.priorities,
  466. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  467. )
  468. # Create an issue
  469. data = {
  470. 'title': 'Test issue',
  471. 'issue_content': 'We really should improve on this issue',
  472. 'status': 'Open',
  473. 'csrf_token': csrf_token,
  474. }
  475. output = self.app.post(
  476. '/test/new_issue', data=data, follow_redirects=True)
  477. self.assertEqual(output.status_code, 200)
  478. output_text = output.get_data(as_text=True)
  479. self.assertIn(
  480. '<title>Issue #1: Test issue - test - Pagure</title>',
  481. output_text)
  482. self.assertIn(
  483. '<a class="btn btn-outline-secondary btn-sm border-0" '
  484. 'href="/test/issue/1/edit" title="Edit this issue">',
  485. output_text)
  486. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  487. self.assertIn('<option value="1">High</option>', output_text)
  488. # Check that the ticket *does* have priorities
  489. output = self.app.get('/test/issue/1')
  490. self.assertEqual(output.status_code, 200)
  491. output_text = output.get_data(as_text=True)
  492. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  493. self.assertIn('<option value="1">High</option>', output_text)
  494. # Reset the priorities
  495. data = {
  496. 'priority': None,
  497. 'csrf_token': csrf_token,
  498. }
  499. output = self.app.post(
  500. '/test/update/priorities', data=data, follow_redirects=True)
  501. self.assertEqual(output.status_code, 200)
  502. output_text = output.get_data(as_text=True)
  503. self.assertIn(
  504. '<title>Settings - test - Pagure</title>', output_text)
  505. self.assertIn(
  506. '<h5 class="pl-2 font-weight-bold text-muted">'
  507. 'Project Settings</h5>\n', output_text)
  508. # Check that the issue list renders fine
  509. output = self.app.get('/test/issues')
  510. self.assertEqual(output.status_code, 200)
  511. output_text = output.get_data(as_text=True)
  512. # Check that the ticket *does not* have priorities
  513. output = self.app.get('/test/issue/1')
  514. self.assertEqual(output.status_code, 200)
  515. output_text = output.get_data(as_text=True)
  516. self.assertNotIn('<div class="ml-2" id="priority_plain">', output_text)
  517. self.assertNotIn('<option value="1">High</option>', output_text)
  518. # Check the result of the action -- Priority recorded
  519. self.session.commit()
  520. repo = pagure.lib.query._get_project(self.session, 'test')
  521. self.assertEqual(repo.priorities, {})
  522. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  523. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  524. def test_set_priority_1_and_back(self):
  525. """ Test setting the priority of a ticket to 1. """
  526. tests.create_projects(self.session)
  527. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  528. # Start from scrach on priorities
  529. repo = pagure.lib.query._get_project(self.session, 'test')
  530. self.assertEqual(repo.priorities, {})
  531. user = tests.FakeUser()
  532. user.username = 'pingou'
  533. with tests.user_set(self.app.application, user):
  534. # Get the CSRF token
  535. output = self.app.get('/test/settings')
  536. self.assertEqual(output.status_code, 200)
  537. output_text = output.get_data(as_text=True)
  538. self.assertIn(
  539. '<title>Settings - test - Pagure</title>', output_text)
  540. self.assertIn(
  541. '<h5 class="pl-2 font-weight-bold text-muted">'
  542. 'Project Settings</h5>\n', output_text)
  543. csrf_token = output_text.split(
  544. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  545. # Set some priorities
  546. data = {
  547. 'priority_weigth': [-1, 0, 1, 2, 3],
  548. 'priority_title': [
  549. 'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
  550. 'csrf_token': csrf_token,
  551. }
  552. output = self.app.post(
  553. '/test/update/priorities', data=data, follow_redirects=True)
  554. self.assertEqual(output.status_code, 200)
  555. output_text = output.get_data(as_text=True)
  556. self.assertIn(
  557. '<title>Settings - test - Pagure</title>', output_text)
  558. self.assertIn(
  559. '<h5 class="pl-2 font-weight-bold text-muted">'
  560. 'Project Settings</h5>\n', output_text)
  561. # Check the result of the action -- Priority recorded
  562. self.session.commit()
  563. repo = pagure.lib.query._get_project(self.session, 'test')
  564. self.assertEqual(
  565. repo.priorities,
  566. {'': '', '-1': 'Sky Falling', '0': 'Urgent',
  567. '1': 'High', '2': 'Normal', '3': 'Low'}
  568. )
  569. # Create an issue
  570. data = {
  571. 'title': 'Test issue',
  572. 'issue_content': 'We really should improve on this issue',
  573. 'status': 'Open',
  574. 'csrf_token': csrf_token,
  575. }
  576. output = self.app.post(
  577. '/test/new_issue', data=data, follow_redirects=True)
  578. self.assertEqual(output.status_code, 200)
  579. output_text = output.get_data(as_text=True)
  580. self.assertIn(
  581. '<title>Issue #1: Test issue - test - Pagure</title>',
  582. output_text)
  583. self.assertIn(
  584. '<a class="btn btn-outline-secondary btn-sm border-0" '
  585. 'href="/test/issue/1/edit" title="Edit this issue">',
  586. output_text)
  587. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  588. self.assertIn('<option value="1">High</option>', output_text)
  589. # Check that the ticket *does* have priorities
  590. output = self.app.get('/test/issue/1')
  591. self.assertEqual(output.status_code, 200)
  592. output_text = output.get_data(as_text=True)
  593. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  594. self.assertIn(
  595. '<option value="-1">Sky Falling</option>', output_text)
  596. self.assertIn('<option value="0">Urgent</option>', output_text)
  597. self.assertIn('<option value="1">High</option>', output_text)
  598. # Set the priority to High
  599. data = {
  600. 'priority': '1',
  601. 'csrf_token': csrf_token,
  602. }
  603. output = self.app.post(
  604. '/test/issue/1/update', data=data, follow_redirects=True)
  605. self.assertEqual(output.status_code, 200)
  606. output_text = output.get_data(as_text=True)
  607. self.assertIn(
  608. '<title>Issue #1: Test issue - test - Pagure</title>',
  609. output_text)
  610. self.assertIn(
  611. '<a class="btn btn-outline-secondary btn-sm border-0" '
  612. 'href="/test/issue/1/edit" title="Edit this issue">',
  613. output_text)
  614. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  615. self.assertIn(
  616. '<option value="-1">Sky Falling</option>', output_text)
  617. self.assertIn('<option value="0">Urgent</option>', output_text)
  618. self.assertIn(
  619. '<option selected value="1">High</option>', output_text)
  620. # Reset the priority
  621. data = {
  622. 'priority': '',
  623. 'csrf_token': csrf_token,
  624. }
  625. output = self.app.post(
  626. '/test/issue/1/update', data=data, follow_redirects=True)
  627. self.assertEqual(output.status_code, 200)
  628. output_text = output.get_data(as_text=True)
  629. self.assertIn(
  630. '<title>Issue #1: Test issue - test - Pagure</title>',
  631. output_text)
  632. self.assertIn(
  633. '<a class="btn btn-outline-secondary btn-sm border-0" '
  634. 'href="/test/issue/1/edit" title="Edit this issue">',
  635. output_text)
  636. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  637. self.assertIn(
  638. '<option value="-1">Sky Falling</option>', output_text)
  639. self.assertIn('<option value="0">Urgent</option>', output_text)
  640. self.assertIn('<option value="1">High</option>', output_text)
  641. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  642. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  643. def test_set_priority_0(self):
  644. """ Test setting the priority of a ticket to 0. """
  645. tests.create_projects(self.session)
  646. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  647. # Start from scrach on priorities
  648. repo = pagure.lib.query._get_project(self.session, 'test')
  649. self.assertEqual(repo.priorities, {})
  650. user = tests.FakeUser()
  651. user.username = 'pingou'
  652. with tests.user_set(self.app.application, user):
  653. # Get the CSRF token
  654. output = self.app.get('/test/settings')
  655. self.assertEqual(output.status_code, 200)
  656. output_text = output.get_data(as_text=True)
  657. self.assertIn(
  658. '<title>Settings - test - Pagure</title>', output_text)
  659. self.assertIn(
  660. '<h5 class="pl-2 font-weight-bold text-muted">'
  661. 'Project Settings</h5>\n', output_text)
  662. csrf_token = output_text.split(
  663. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  664. # Set some priorities
  665. data = {
  666. 'priority_weigth': [-1, 0, 1, 2, 3],
  667. 'priority_title': [
  668. 'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
  669. 'csrf_token': csrf_token,
  670. }
  671. output = self.app.post(
  672. '/test/update/priorities', data=data, follow_redirects=True)
  673. self.assertEqual(output.status_code, 200)
  674. output_text = output.get_data(as_text=True)
  675. self.assertIn(
  676. '<title>Settings - test - Pagure</title>', output_text)
  677. self.assertIn(
  678. '<h5 class="pl-2 font-weight-bold text-muted">'
  679. 'Project Settings</h5>\n', output_text)
  680. # Check the result of the action -- Priority recorded
  681. self.session.commit()
  682. repo = pagure.lib.query._get_project(self.session, 'test')
  683. self.assertEqual(
  684. repo.priorities,
  685. {'': '', '-1': 'Sky Falling', '0': 'Urgent',
  686. '1': 'High', '2': 'Normal', '3': 'Low'}
  687. )
  688. # Create an issue
  689. data = {
  690. 'title': 'Test issue',
  691. 'issue_content': 'We really should improve on this issue',
  692. 'status': 'Open',
  693. 'csrf_token': csrf_token,
  694. }
  695. output = self.app.post(
  696. '/test/new_issue', data=data, follow_redirects=True)
  697. self.assertEqual(output.status_code, 200)
  698. output_text = output.get_data(as_text=True)
  699. self.assertIn(
  700. '<title>Issue #1: Test issue - test - Pagure</title>',
  701. output_text)
  702. self.assertIn(
  703. '<a class="btn btn-outline-secondary btn-sm border-0" '
  704. 'href="/test/issue/1/edit" title="Edit this issue">',
  705. output_text)
  706. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  707. self.assertIn('<option value="1">High</option>', output_text)
  708. # Check that the ticket *does* have priorities
  709. output = self.app.get('/test/issue/1')
  710. self.assertEqual(output.status_code, 200)
  711. output_text = output.get_data(as_text=True)
  712. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  713. self.assertIn(
  714. '<option value="-1">Sky Falling</option>', output_text)
  715. self.assertIn('<option value="0">Urgent</option>', output_text)
  716. self.assertIn('<option value="1">High</option>', output_text)
  717. # Set the priority to Urgent
  718. data = {
  719. 'priority': '0',
  720. 'csrf_token': csrf_token,
  721. }
  722. output = self.app.post(
  723. '/test/issue/1/update', data=data, follow_redirects=True)
  724. self.assertEqual(output.status_code, 200)
  725. output_text = output.get_data(as_text=True)
  726. self.assertIn(
  727. '<title>Issue #1: Test issue - test - Pagure</title>',
  728. output_text)
  729. self.assertIn(
  730. '<a class="btn btn-outline-secondary btn-sm border-0" '
  731. 'href="/test/issue/1/edit" title="Edit this issue">',
  732. output_text)
  733. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  734. self.assertIn(
  735. '<option value="-1">Sky Falling</option>', output_text)
  736. self.assertIn(
  737. '<option selected value="0">Urgent</option>',
  738. output_text)
  739. self.assertIn('<option value="1">High</option>', output_text)
  740. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  741. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  742. def test_set_priority_minus1(self):
  743. """ Test setting the priority of a ticket to -1. """
  744. tests.create_projects(self.session)
  745. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  746. # Start from scrach on priorities
  747. repo = pagure.lib.query._get_project(self.session, 'test')
  748. self.assertEqual(repo.priorities, {})
  749. user = tests.FakeUser()
  750. user.username = 'pingou'
  751. with tests.user_set(self.app.application, user):
  752. # Get the CSRF token
  753. output = self.app.get('/test/settings')
  754. self.assertEqual(output.status_code, 200)
  755. output_text = output.get_data(as_text=True)
  756. self.assertIn(
  757. '<title>Settings - test - Pagure</title>', output_text)
  758. self.assertIn(
  759. '<h5 class="pl-2 font-weight-bold text-muted">'
  760. 'Project Settings</h5>\n', output_text)
  761. csrf_token = output_text.split(
  762. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  763. # Set some priorities
  764. data = {
  765. 'priority_weigth': [-1, 0, 1, 2, 3],
  766. 'priority_title': [
  767. 'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
  768. 'csrf_token': csrf_token,
  769. }
  770. output = self.app.post(
  771. '/test/update/priorities', data=data, follow_redirects=True)
  772. self.assertEqual(output.status_code, 200)
  773. output_text = output.get_data(as_text=True)
  774. self.assertIn(
  775. '<title>Settings - test - Pagure</title>', output_text)
  776. self.assertIn(
  777. '<h5 class="pl-2 font-weight-bold text-muted">'
  778. 'Project Settings</h5>\n', output_text)
  779. # Check the result of the action -- Priority recorded
  780. self.session.commit()
  781. repo = pagure.lib.query._get_project(self.session, 'test')
  782. self.assertEqual(
  783. repo.priorities,
  784. {'': '', '-1': 'Sky Falling', '0': 'Urgent',
  785. '1': 'High', '2': 'Normal', '3': 'Low'}
  786. )
  787. # Create an issue
  788. data = {
  789. 'title': 'Test issue',
  790. 'issue_content': 'We really should improve on this issue',
  791. 'status': 'Open',
  792. 'csrf_token': csrf_token,
  793. }
  794. output = self.app.post(
  795. '/test/new_issue', data=data, follow_redirects=True)
  796. self.assertEqual(output.status_code, 200)
  797. output_text = output.get_data(as_text=True)
  798. self.assertIn(
  799. '<title>Issue #1: Test issue - test - Pagure</title>',
  800. output_text)
  801. self.assertIn(
  802. '<a class="btn btn-outline-secondary btn-sm border-0" '
  803. 'href="/test/issue/1/edit" title="Edit this issue">',
  804. output_text)
  805. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  806. self.assertIn('<option value="1">High</option>', output_text)
  807. # Check that the ticket *does* have priorities
  808. output = self.app.get('/test/issue/1')
  809. self.assertEqual(output.status_code, 200)
  810. output_text = output.get_data(as_text=True)
  811. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  812. self.assertIn(
  813. '<option value="-1">Sky Falling</option>', output_text)
  814. self.assertIn('<option value="0">Urgent</option>', output_text)
  815. self.assertIn('<option value="1">High</option>', output_text)
  816. # Set the priority to Sky Falling
  817. data = {
  818. 'priority': '-1',
  819. 'csrf_token': csrf_token,
  820. }
  821. output = self.app.post(
  822. '/test/issue/1/update', data=data, follow_redirects=True)
  823. self.assertEqual(output.status_code, 200)
  824. output_text = output.get_data(as_text=True)
  825. self.assertIn(
  826. '<title>Issue #1: Test issue - test - Pagure</title>',
  827. output_text)
  828. self.assertIn(
  829. '<a class="btn btn-outline-secondary btn-sm border-0" '
  830. 'href="/test/issue/1/edit" title="Edit this issue">',
  831. output_text)
  832. self.assertIn('<div class="ml-2" id="priority_plain">', output_text)
  833. self.assertIn(
  834. '<option selected value="-1">Sky Falling</option>',
  835. output_text)
  836. self.assertIn('<option value="0">Urgent</option>', output_text)
  837. self.assertIn('<option value="1">High</option>', output_text)
  838. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  839. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  840. def test_default_priority(self):
  841. """ Test updating the default priority of a repo. """
  842. tests.create_projects(self.session)
  843. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  844. # Check the default priorities
  845. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  846. self.assertEqual(repo.priorities, {})
  847. self.assertEqual(repo.default_priority, None)
  848. user = tests.FakeUser()
  849. user.username = 'pingou'
  850. with tests.user_set(self.app.application, user):
  851. csrf_token = self.get_csrf()
  852. # Set some priorities
  853. data = {
  854. 'priority_weigth': [1, 2, 3],
  855. 'priority_title': ['High', 'Normal', 'Low'],
  856. 'csrf_token': csrf_token,
  857. }
  858. output = self.app.post(
  859. '/test/update/priorities', data=data, follow_redirects=True)
  860. self.assertEqual(output.status_code, 200)
  861. output_text = output.get_data(as_text=True)
  862. # Check the redirect
  863. self.assertIn(
  864. '<title>Settings - test - Pagure</title>', output_text)
  865. self.assertIn(
  866. '<h5 class="pl-2 font-weight-bold text-muted">'
  867. 'Project Settings</h5>\n', output_text)
  868. # Check the ordering
  869. self.assertTrue(
  870. output_text.find('High') < output_text.find('Normal'))
  871. self.assertTrue(
  872. output_text.find('Normal') < output_text.find('Low'))
  873. # Check the result of the action -- Priority recorded
  874. self.session.commit()
  875. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  876. self.assertEqual(
  877. repo.priorities,
  878. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  879. )
  880. # Try setting the default priority -- no csrf
  881. data = {'priority': 'High'}
  882. output = self.app.post(
  883. '/test/update/default_priority', data=data,
  884. follow_redirects=True)
  885. self.assertEqual(output.status_code, 200)
  886. output_text = output.get_data(as_text=True)
  887. # Check the redirect
  888. self.assertIn(
  889. '<title>Settings - test - Pagure</title>', output_text)
  890. self.assertIn(
  891. '<h5 class="pl-2 font-weight-bold text-muted">'
  892. 'Project Settings</h5>\n', output_text)
  893. # Check the result of the action -- default_priority no change
  894. self.session.commit()
  895. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  896. self.assertEqual(repo.default_priority, None)
  897. # Try setting the default priority
  898. data = {'priority': 'High', 'csrf_token': csrf_token}
  899. output = self.app.post(
  900. '/test/update/default_priority', data=data,
  901. follow_redirects=True)
  902. self.assertEqual(output.status_code, 200)
  903. output_text = output.get_data(as_text=True)
  904. # Check the redirect
  905. self.assertIn(
  906. '<title>Settings - test - Pagure</title>', output_text)
  907. self.assertIn(
  908. '<h5 class="pl-2 font-weight-bold text-muted">'
  909. 'Project Settings</h5>\n', output_text)
  910. self.assertIn(
  911. 'Default priority set '
  912. 'to High', output_text)
  913. # Check the result of the action -- default_priority no change
  914. self.session.commit()
  915. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  916. self.assertEqual(repo.default_priority, 'High')
  917. # Try setting a wrong default priority
  918. data = {'priority': 'Smooth', 'csrf_token': csrf_token}
  919. output = self.app.post(
  920. '/test/update/default_priority', data=data,
  921. follow_redirects=True)
  922. self.assertEqual(output.status_code, 200)
  923. output_text = output.get_data(as_text=True)
  924. # Check the redirect
  925. self.assertIn(
  926. '<title>Settings - test - Pagure</title>', output_text)
  927. self.assertIn(
  928. '<h5 class="pl-2 font-weight-bold text-muted">'
  929. 'Project Settings</h5>\n', output_text)
  930. # Check the result of the action -- default_priority no change
  931. self.session.commit()
  932. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  933. self.assertEqual(repo.default_priority, 'High')
  934. # reset the default priority
  935. data = {'csrf_token': csrf_token, 'priority': ''}
  936. output = self.app.post(
  937. '/test/update/default_priority', data=data,
  938. follow_redirects=True)
  939. self.assertEqual(output.status_code, 200)
  940. output_text = output.get_data(as_text=True)
  941. # Check the redirect
  942. self.assertIn(
  943. '<title>Settings - test - Pagure</title>', output_text)
  944. self.assertIn(
  945. '<h5 class="pl-2 font-weight-bold text-muted">'
  946. 'Project Settings</h5>\n', output_text)
  947. self.assertIn(
  948. 'Default priority reset',
  949. output_text)
  950. # Check the result of the action -- default_priority no change
  951. self.session.commit()
  952. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  953. self.assertEqual(repo.default_priority, None)
  954. # Check the behavior if the project disabled the issue tracker
  955. settings = repo.settings
  956. settings['issue_tracker'] = False
  957. repo.settings = settings
  958. self.session.add(repo)
  959. self.session.commit()
  960. output = self.app.post(
  961. '/test/update/default_priority', data=data)
  962. self.assertEqual(output.status_code, 404)
  963. # Check for an invalid project
  964. output = self.app.post(
  965. '/foo/update/default_priority', data=data)
  966. self.assertEqual(output.status_code, 404)
  967. # Check for a non-admin user
  968. settings = repo.settings
  969. settings['issue_tracker'] = True
  970. repo.settings = settings
  971. self.session.add(repo)
  972. self.session.commit()
  973. user.username = 'ralph'
  974. with tests.user_set(self.app.application, user):
  975. output = self.app.post(
  976. '/test/update/default_priority', data=data)
  977. self.assertEqual(output.status_code, 403)
  978. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  979. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  980. def test_default_priority_reset_when_updating_priorities(self):
  981. """ Test updating the default priority of a repo when updating the
  982. priorities.
  983. """
  984. tests.create_projects(self.session)
  985. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  986. # Check the default priorities
  987. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  988. self.assertEqual(repo.priorities, {})
  989. self.assertEqual(repo.default_priority, None)
  990. user = tests.FakeUser()
  991. user.username = 'pingou'
  992. with tests.user_set(self.app.application, user):
  993. csrf_token = self.get_csrf()
  994. # Set some priorities
  995. data = {
  996. 'priority_weigth': [1, 2, 3],
  997. 'priority_title': ['High', 'Normal', 'Low'],
  998. 'csrf_token': csrf_token,
  999. }
  1000. output = self.app.post(
  1001. '/test/update/priorities', data=data, follow_redirects=True)
  1002. self.assertEqual(output.status_code, 200)
  1003. output_text = output.get_data(as_text=True)
  1004. # Check the redirect
  1005. self.assertIn(
  1006. '<title>Settings - test - Pagure</title>', output_text)
  1007. self.assertIn(
  1008. '<h5 class="pl-2 font-weight-bold text-muted">'
  1009. 'Project Settings</h5>\n', output_text)
  1010. # Check the ordering
  1011. self.assertTrue(
  1012. output_text.find('High') < output_text.find('Normal'))
  1013. self.assertTrue(
  1014. output_text.find('Normal') < output_text.find('Low'))
  1015. # Check the result of the action -- Priority recorded
  1016. self.session.commit()
  1017. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  1018. self.assertEqual(
  1019. repo.priorities,
  1020. {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
  1021. )
  1022. # Try setting the default priority
  1023. data = {'priority': 'High', 'csrf_token': csrf_token}
  1024. output = self.app.post(
  1025. '/test/update/default_priority', data=data,
  1026. follow_redirects=True)
  1027. self.assertEqual(output.status_code, 200)
  1028. output_text = output.get_data(as_text=True)
  1029. # Check the redirect
  1030. self.assertIn(
  1031. '<title>Settings - test - Pagure</title>', output_text)
  1032. self.assertIn(
  1033. '<h5 class="pl-2 font-weight-bold text-muted">'
  1034. 'Project Settings</h5>\n', output_text)
  1035. self.assertIn(
  1036. 'Default priority set '
  1037. 'to High', output_text)
  1038. # Check the result of the action -- default_priority no change
  1039. self.session.commit()
  1040. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  1041. self.assertEqual(repo.default_priority, 'High')
  1042. # Remove the Hight priority
  1043. data = {
  1044. 'priority_weigth': [1, 2],
  1045. 'priority_title': ['Normal', 'Low'],
  1046. 'csrf_token': csrf_token,
  1047. }
  1048. output = self.app.post(
  1049. '/test/update/priorities', data=data, follow_redirects=True)
  1050. self.assertEqual(output.status_code, 200)
  1051. output_text = output.get_data(as_text=True)
  1052. # Check the redirect
  1053. self.assertIn(
  1054. '<title>Settings - test - Pagure</title>', output_text)
  1055. self.assertIn(
  1056. '<h5 class="pl-2 font-weight-bold text-muted">'
  1057. 'Project Settings</h5>\n', output_text)
  1058. self.assertIn(
  1059. 'Priorities updated',
  1060. output_text)
  1061. self.assertIn(
  1062. 'Default priority reset '
  1063. 'as it is no longer one of set priorities.',
  1064. output_text)
  1065. # Check the ordering
  1066. self.assertTrue(
  1067. output_text.find('Normal') < output_text.find('Low'))
  1068. # Check the result of the action -- Priority recorded
  1069. self.session.commit()
  1070. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  1071. self.assertEqual(
  1072. repo.priorities,
  1073. {'': '', '1': 'Normal', '2': 'Low'}
  1074. )
  1075. # Default priority is now None
  1076. self.assertIsNone(repo.default_priority)
  1077. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  1078. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  1079. def test_default_priority_on_new_ticket(self):
  1080. """ Test updating the default priority of a repo. """
  1081. tests.create_projects(self.session)
  1082. tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
  1083. # Set some priority and the default one
  1084. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  1085. repo.priorities = {'1': 'High', '2': 'Normal'}
  1086. repo.default_priority = 'Normal'
  1087. self.session.add(repo)
  1088. self.session.commit()
  1089. # Check the default priorities
  1090. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  1091. self.assertEqual(repo.priorities, {'1': 'High', '2': 'Normal'})
  1092. self.assertEqual(repo.default_priority, 'Normal')
  1093. user = tests.FakeUser()
  1094. user.username = 'pingou'
  1095. with tests.user_set(self.app.application, user):
  1096. csrf_token = self.get_csrf()
  1097. data = {
  1098. 'title': 'Test issue',
  1099. 'issue_content': 'We really should improve on this issue',
  1100. 'status': 'Open',
  1101. 'csrf_token': csrf_token,
  1102. }
  1103. output = self.app.post(
  1104. '/test/new_issue', data=data, follow_redirects=True)
  1105. self.assertEqual(output.status_code, 200)
  1106. output_text = output.get_data(as_text=True)
  1107. self.assertIn(
  1108. '<title>Issue #1: Test issue - test - Pagure</title>',
  1109. output_text)
  1110. self.assertIn(
  1111. '<a class="btn btn-outline-secondary btn-sm border-0" '
  1112. 'href="/test/issue/1/edit" title="Edit this issue">',
  1113. output_text)
  1114. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  1115. self.assertEqual(len(repo.issues), 1)
  1116. self.assertEqual(repo.issues[0].priority, 2)
  1117. if __name__ == '__main__':
  1118. unittest.main(verbosity=2)