test_pagure_flask_ui_priorities.py 52 KB

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