test_pagure_flask_ui_priorities.py 52 KB

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