test_pagure_flask_ui_issues_open_access.py 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2015-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. from unittest.case import SkipTest
  11. import json
  12. import unittest
  13. import shutil
  14. import sys
  15. import os
  16. try:
  17. import pyclamd
  18. except ImportError:
  19. pyclamd = None
  20. import six
  21. import tempfile
  22. import re
  23. from datetime import datetime, timedelta
  24. from six.moves.urllib.parse import urlparse, parse_qs
  25. import pygit2
  26. from bs4 import BeautifulSoup
  27. from mock import patch, MagicMock
  28. sys.path.insert(0, os.path.join(os.path.dirname(
  29. os.path.abspath(__file__)), '..'))
  30. import pagure
  31. import pagure.lib
  32. import tests
  33. class PagureFlaskIssuesOpenAccesstests(tests.Modeltests):
  34. """ Tests for flask issues controller of pagure """
  35. def setUp(self):
  36. """ Set up the environnment, ran before every tests. """
  37. super(PagureFlaskIssuesOpenAccesstests, self).setUp()
  38. tests.create_projects(self.session)
  39. tests.create_projects_git(
  40. os.path.join(self.path, 'repos'), bare=True)
  41. tests.create_projects_git(
  42. os.path.join(self.path, 'tickets'), bare=True)
  43. repo = pagure.lib.get_authorized_project(self.session, 'test')
  44. settings = repo.settings
  45. settings['open_metadata_access_to_all'] = True
  46. repo.settings = settings
  47. repo.milestones = {'v1.0': '', 'v2.0': 'Tomorrow!'}
  48. self.session.add(repo)
  49. self.session.commit()
  50. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  51. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  52. def test_new_issue_with_metadata(self):
  53. """ Test the new_issue endpoint when the user has access to the
  54. project. """
  55. user = tests.FakeUser()
  56. user.username = 'foo'
  57. with tests.user_set(self.app.application, user):
  58. output = self.app.get('/test/new_issue')
  59. self.assertEqual(output.status_code, 200)
  60. output_text = output.get_data(as_text=True)
  61. self.assertIn(
  62. '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
  63. output_text)
  64. self.assertIn('<strong>Tags</strong>', output_text)
  65. self.assertIn(
  66. '<strong>Assignee</strong>', output_text)
  67. csrf_token = self.get_csrf(output=output)
  68. data = {
  69. 'title': 'Test issue3',
  70. 'issue_content': 'We really should improve on this issue\n',
  71. 'status': 'Open',
  72. 'assignee': 'foo',
  73. 'milestone': 'v2.0',
  74. 'tag': 'tag2',
  75. 'csrf_token': csrf_token,
  76. }
  77. output = self.app.post(
  78. '/test/new_issue', data=data, follow_redirects=True)
  79. self.assertEqual(output.status_code, 200)
  80. output_text = output.get_data(as_text=True)
  81. self.assertIn(
  82. '<title>Issue #1: Test issue3 - test - Pagure</title>',
  83. output_text)
  84. self.assertIn(
  85. '<a class="btn btn-outline-secondary btn-sm border-0" '
  86. 'href="/test/issue/1/edit" title="Edit this issue">\n',
  87. output_text)
  88. # Check the metadata
  89. self.assertIn(
  90. 'title="comma separated list of tags"\n '
  91. 'value="tag2" />', output_text)
  92. self.assertIn(
  93. 'placeholder="username"\n value="foo" />\n',
  94. output_text)
  95. self.assertIn(
  96. 'href="/test/roadmap/v2.0/"',
  97. output_text)
  98. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  99. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  100. def test_new_issue_with_metadata_not_user(self):
  101. """ Test the new_issue endpoint when the user does not have access
  102. to the project but still tries to.
  103. """
  104. user = tests.FakeUser()
  105. user.username = 'foo'
  106. with tests.user_set(self.app.application, user):
  107. output = self.app.get('/test/new_issue')
  108. self.assertEqual(output.status_code, 200)
  109. output_text = output.get_data(as_text=True)
  110. self.assertIn(
  111. '<h4 class="font-weight-bold mb-4">New Issue</h4>\n',
  112. output_text)
  113. self.assertIn('<strong>Tags</strong>', output_text)
  114. self.assertIn('<strong>Assignee</strong>', output_text)
  115. csrf_token = self.get_csrf(output=output)
  116. data = {
  117. 'title': 'Test issue3',
  118. 'issue_content': 'We really should improve on this issue\n',
  119. 'status': 'Open',
  120. 'assignee': 'foo',
  121. 'milestone': 'v2.0',
  122. 'tag': 'tag2',
  123. 'csrf_token': csrf_token,
  124. }
  125. output = self.app.post(
  126. '/test/new_issue', data=data, follow_redirects=True)
  127. self.assertEqual(output.status_code, 200)
  128. output_text = output.get_data(as_text=True)
  129. self.assertIn(
  130. '<title>Issue #1: Test issue3 - test - Pagure</title>',
  131. output_text)
  132. self.assertIn(
  133. '<a class="btn btn-outline-secondary btn-sm border-0" '
  134. 'href="/test/issue/1/edit" title="Edit this issue">\n',
  135. output_text)
  136. # Check the metadata
  137. self.assertIn(
  138. 'title="comma separated list of tags"\n '
  139. 'value="tag2" />', output_text)
  140. self.assertIn(
  141. 'placeholder="username"\n value="foo" />\n',
  142. output_text)
  143. self.assertIn(
  144. '<div class="ml-2" id="milestone_plain">'
  145. '\n <span>'
  146. '\n <a href="/test/roadmap/v2.0/">'
  147. '\n v2.0\n', output_text)
  148. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  149. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  150. def test_view_issue(self):
  151. """ Test the view_issue endpoint. """
  152. output = self.app.get('/test/issue/1')
  153. self.assertEqual(output.status_code, 404)
  154. # Create issues to play with
  155. repo = pagure.lib.get_authorized_project(self.session, 'test')
  156. msg = pagure.lib.new_issue(
  157. session=self.session,
  158. repo=repo,
  159. title='Test issue',
  160. content='We should work on this',
  161. user='pingou',
  162. )
  163. self.session.commit()
  164. self.assertEqual(msg.title, 'Test issue')
  165. output = self.app.get('/test/issue/1')
  166. self.assertEqual(output.status_code, 200)
  167. output_text = output.get_data(as_text=True)
  168. # Not authentified = No edit
  169. self.assertNotIn(
  170. '<a class="btn btn-outline-secondary btn-sm border-0" '
  171. 'href="/test/issue/1/edit" title="Edit this issue">\n',
  172. output_text)
  173. self.assertIn(
  174. '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
  175. 'Login</a>\n to comment on this ticket.',
  176. output_text)
  177. user = tests.FakeUser()
  178. with tests.user_set(self.app.application, user):
  179. output = self.app.get('/test/issue/1')
  180. self.assertEqual(output.status_code, 200)
  181. output_text = output.get_data(as_text=True)
  182. # Not author nor admin = No edit
  183. self.assertNotIn(
  184. '<a class="btn btn-outline-secondary btn-sm border-0"'
  185. ' href="/test/issue/1/edit" title="Edit this issue">',
  186. output_text)
  187. self.assertNotIn(
  188. '<a class="dropdown-item text-danger" href="javascript:void(0)" id="closeticket"\n'
  189. ' title="Delete this ticket">\n',
  190. output_text)
  191. self.assertFalse(
  192. '<a href="/login/">Login</a> to comment on this ticket.'
  193. in output_text)
  194. # Not author nor admin but open_access = take
  195. self.assertIn('function take_issue(){', output_text)
  196. self.assertNotIn('function drop_issue(){', output_text)
  197. self.assertIn(
  198. '<a href="javascript:void(0)" id="take-btn"\n',
  199. output_text)
  200. csrf_token = self.get_csrf(output=output)
  201. # Create private issue
  202. repo = pagure.lib.get_authorized_project(self.session, 'test')
  203. msg = pagure.lib.new_issue(
  204. session=self.session,
  205. repo=repo,
  206. title='Test issue',
  207. content='We should work on this',
  208. user='pingou',
  209. private=True,
  210. )
  211. self.session.commit()
  212. self.assertEqual(msg.title, 'Test issue')
  213. # Not logged in
  214. output = self.app.get('/test/issue/2')
  215. self.assertEqual(output.status_code, 404)
  216. # Wrong user
  217. user = tests.FakeUser()
  218. with tests.user_set(self.app.application, user):
  219. output = self.app.get('/test/issue/2')
  220. self.assertEqual(output.status_code, 404)
  221. # another user
  222. user.username = 'foo'
  223. with tests.user_set(self.app.application, user):
  224. output = self.app.get('/test/issue/2')
  225. self.assertEqual(output.status_code, 404)
  226. # Project w/o issue tracker
  227. repo = pagure.lib.get_authorized_project(self.session, 'test')
  228. repo.settings = {'issue_tracker': False}
  229. self.session.add(repo)
  230. self.session.commit()
  231. output = self.app.get('/test/issue/1')
  232. self.assertEqual(output.status_code, 404)
  233. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  234. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  235. def test_view_issue_user_ticket(self):
  236. """ Test the view_issue endpoint. """
  237. output = self.app.get('/test/issue/1')
  238. self.assertEqual(output.status_code, 404)
  239. # Create issues to play with
  240. repo = pagure.lib.get_authorized_project(self.session, 'test')
  241. msg = pagure.lib.new_issue(
  242. session=self.session,
  243. repo=repo,
  244. title='Test issue',
  245. content='We should work on this',
  246. user='pingou',
  247. )
  248. self.session.commit()
  249. self.assertEqual(msg.title, 'Test issue')
  250. output = self.app.get('/test/issue/1')
  251. self.assertEqual(output.status_code, 200)
  252. output_text = output.get_data(as_text=True)
  253. # Not authentified = No edit
  254. self.assertNotIn(
  255. '<a class="btn btn-outline-secondary btn-sm border-0" '
  256. 'href="/test/issue/1/edit" title="Edit this issue">\n',
  257. output_text)
  258. self.assertTrue(
  259. '<a href="/login/?next=http%3A%2F%2Flocalhost%2Ftest%2Fissue%2F1">'
  260. 'Login</a>\n to comment on this ticket.'
  261. in output_text)
  262. # Create issues to play with
  263. repo = pagure.lib.get_authorized_project(self.session, 'test')
  264. # Add user 'foo' with ticket access on repo
  265. msg = pagure.lib.add_user_to_project(
  266. self.session,
  267. repo,
  268. new_user='foo',
  269. user='pingou',
  270. access='ticket',
  271. )
  272. self.assertEqual(msg, 'User added')
  273. self.session.commit()
  274. user = tests.FakeUser(username='foo')
  275. with tests.user_set(self.app.application, user):
  276. output = self.app.get('/test/issue/1')
  277. self.assertEqual(output.status_code, 200)
  278. output_text = output.get_data(as_text=True)
  279. # Not author nor admin = No edit
  280. self.assertNotIn(
  281. '<a class="btn btn-outline-secondary btn-sm border-0"'
  282. ' href="/test/issue/1/edit" title="Edit this issue">',
  283. output_text)
  284. self.assertNotIn(
  285. '<a class="dropdown-item text-danger" href="javascript:void(0)" id="closeticket"\n'
  286. ' title="Delete this ticket">\n',
  287. output_text)
  288. self.assertFalse(
  289. '<a href="/login/">Login</a> to comment on this ticket.'
  290. in output_text)
  291. # user has ticket = take ok
  292. self.assertIn('function take_issue(){', output_text)
  293. self.assertIn('function drop_issue(){', output_text)
  294. self.assertIn(
  295. '<a href="javascript:void(0)" id="take-btn"\n',
  296. output_text)
  297. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  298. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  299. def test_view_issue_custom_field_user_ticket(self):
  300. """ Test the view_issue endpoint. """
  301. output = self.app.get('/test/issue/1')
  302. self.assertEqual(output.status_code, 404)
  303. # Create issues to play with
  304. repo = pagure.lib.get_authorized_project(self.session, 'test')
  305. msg = pagure.lib.new_issue(
  306. session=self.session,
  307. repo=repo,
  308. title='Test issue',
  309. content='We should work on this',
  310. user='pingou',
  311. )
  312. self.session.commit()
  313. self.assertEqual(msg.title, 'Test issue')
  314. # Add user 'foo' with ticket access on repo
  315. repo = pagure.lib.get_authorized_project(self.session, 'test')
  316. msg = pagure.lib.add_user_to_project(
  317. self.session,
  318. repo,
  319. new_user='foo',
  320. user='pingou',
  321. access='ticket',
  322. )
  323. self.assertEqual(msg, 'User added')
  324. self.session.commit()
  325. # Set some custom fields
  326. repo = pagure.lib.get_authorized_project(self.session, 'test')
  327. msg = pagure.lib.set_custom_key_fields(
  328. self.session,
  329. repo,
  330. ['bugzilla', 'upstream', 'reviewstatus'],
  331. ['link', 'boolean', 'list'],
  332. ['unused data for non-list type', '', 'ack, nack , needs review'],
  333. [None, None, None])
  334. self.session.commit()
  335. self.assertEqual(msg, 'List of custom fields updated')
  336. # User with no rights
  337. user = tests.FakeUser()
  338. with tests.user_set(self.app.application, user):
  339. output = self.app.get('/test/issue/1')
  340. self.assertEqual(output.status_code, 200)
  341. output_text = output.get_data(as_text=True)
  342. self.assertNotIn(
  343. '<a class="btn btn-outline-secondary btn-sm border-0"'
  344. ' href="/test/issue/1/edit" title="Edit this issue">',
  345. output_text)
  346. self.assertNotIn(
  347. '<a class="dropdown-item text-danger" href="javascript:void(0)" id="closeticket"\n'
  348. ' title="Delete this ticket">\n',
  349. output_text)
  350. # user no ACLs but open_access = take action/button - no drop
  351. self.assertIn('function take_issue(){', output_text)
  352. self.assertNotIn('function drop_issue(){', output_text)
  353. self.assertIn(
  354. '<a href="javascript:void(0)" id="take-btn"\n',
  355. output_text)
  356. # user no ACLs = no metadata form
  357. self.assertNotIn(
  358. '<input class="form-control" '
  359. 'name="bugzilla" id="bugzilla"/>', output_text)
  360. self.assertNotIn(
  361. '<select class="form-control" name="reviewstatus" '
  362. 'id="reviewstatus>', output_text)
  363. self.assertNotIn(
  364. '<input type="checkbox" '
  365. 'class="form-control" name="upstream" id="upstream"/>',
  366. output_text)
  367. user = tests.FakeUser(username='foo')
  368. with tests.user_set(self.app.application, user):
  369. output = self.app.get('/test/issue/1')
  370. self.assertEqual(output.status_code, 200)
  371. output_text = output.get_data(as_text=True)
  372. self.assertNotIn(
  373. '<a class="btn btn-outline-secondary btn-sm border-0"'
  374. ' href="/test/issue/1/edit" title="Edit this issue">',
  375. output_text)
  376. self.assertNotIn(
  377. '<a class="dropdown-item text-danger" href="javascript:void(0)" id="closeticket"\n'
  378. ' title="Delete this ticket">\n',
  379. output_text)
  380. self.assertNotIn(
  381. '<a href="/login/">Login</a> to comment on this ticket.',
  382. output_text)
  383. # user has ticket = take ok
  384. self.assertIn('function take_issue(){', output_text)
  385. self.assertIn('function drop_issue(){', output_text)
  386. self.assertIn(
  387. '<a href="javascript:void(0)" id="take-btn"\n',
  388. output_text)
  389. # user has ticket == Sees the metadata
  390. self.assertIn(
  391. '<input class="form-control" '
  392. 'name="bugzilla" id="bugzilla"/>', output_text)
  393. self.assertIn(
  394. '<select class="form-control"\n'
  395. ' name="reviewstatus"\n'
  396. ' id="reviewstatus">\n',
  397. output_text)
  398. self.assertIn(
  399. '<input type="checkbox" '
  400. 'class="form-control" name="upstream" id="upstream"/>',
  401. output_text)
  402. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  403. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  404. def test_view_issue_non_ascii_milestone(self):
  405. """ Test the view_issue endpoint with non-ascii milestone. """
  406. output = self.app.get('/test/issue/1')
  407. self.assertEqual(output.status_code, 404)
  408. stone = 'käpy'
  409. # Create issues to play with
  410. repo = pagure.lib.get_authorized_project(self.session, 'test')
  411. msg = pagure.lib.new_issue(
  412. session=self.session,
  413. repo=repo,
  414. title='Test issue',
  415. content='We should work on this',
  416. user='pingou',
  417. )
  418. self.session.commit()
  419. self.assertEqual(msg.title, 'Test issue')
  420. # Add a non-ascii milestone to the issue but project has no milestone
  421. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  422. message = pagure.lib.edit_issue(
  423. self.session,
  424. issue=issue,
  425. milestone=stone,
  426. private=False,
  427. user='pingou',
  428. )
  429. self.assertEqual(
  430. message,
  431. [
  432. 'Issue set to the milestone: k\xe4py'
  433. ]
  434. )
  435. self.session.commit()
  436. # View the issue
  437. output = self.app.get('/test/issue/1')
  438. self.assertEqual(output.status_code, 200)
  439. output_text = output.get_data(as_text=True)
  440. self.assertIn(
  441. '<title>Issue #1: Test issue - test - Pagure</title>',
  442. output_text)
  443. self.assertIn(stone, output_text)
  444. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  445. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  446. def test_view_issue_list_no_data(self):
  447. """ Test the view_issue endpoint when the issue has a custom field
  448. of type list with no data attached. """
  449. repo = pagure.lib.get_authorized_project(self.session, 'test')
  450. # Add custom fields to the project
  451. msg = pagure.lib.set_custom_key_fields(
  452. session=self.session,
  453. project=repo,
  454. fields=['test1'],
  455. types=['list'],
  456. data=[None],
  457. notify=[None]
  458. )
  459. self.session.commit()
  460. self.assertEqual(msg, 'List of custom fields updated')
  461. # Create issues to play with
  462. msg = pagure.lib.new_issue(
  463. session=self.session,
  464. repo=repo,
  465. title='Big problÈm!',
  466. content='We should work on this',
  467. user='pingou',
  468. )
  469. self.session.commit()
  470. self.assertEqual(msg.title, 'Big problÈm!')
  471. # Assign a value to the custom key on that ticket
  472. cfield = pagure.lib.get_custom_key(
  473. session=self.session,
  474. project=repo,
  475. keyname='test1')
  476. msg = pagure.lib.set_custom_key_value(
  477. session=self.session,
  478. issue=msg,
  479. key=cfield,
  480. value='item')
  481. self.session.commit()
  482. self.assertEqual(msg, 'Custom field test1 adjusted to item')
  483. user = tests.FakeUser(username='foo')
  484. with tests.user_set(self.app.application, user):
  485. output = self.app.get('/test/issue/1')
  486. self.assertEqual(output.status_code, 200)
  487. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  488. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  489. def test_update_issue(self):
  490. """ Test the update_issue endpoint. """
  491. output = self.app.get('/test/issue/1/update')
  492. self.assertEqual(output.status_code, 302)
  493. # Create issues to play with
  494. repo = pagure.lib.get_authorized_project(self.session, 'test')
  495. msg = pagure.lib.new_issue(
  496. session=self.session,
  497. repo=repo,
  498. title='Test issue',
  499. content='We should work on this',
  500. user='pingou',
  501. )
  502. self.session.commit()
  503. self.assertEqual(msg.title, 'Test issue')
  504. user = tests.FakeUser(username='foo')
  505. with tests.user_set(self.app.application, user):
  506. output = self.app.get('/test/issue/1')
  507. self.assertEqual(output.status_code, 200)
  508. output_text = output.get_data(as_text=True)
  509. self.assertIn(
  510. '<title>Issue #1: Test issue - test - Pagure</title>',
  511. output_text)
  512. self.assertNotIn(
  513. '<a class="btn btn-outline-secondary btn-sm border-0"'
  514. ' href="/test/issue/1/edit" title="Edit this issue">',
  515. output_text)
  516. self.assertEqual(output_text.count('title="PY C (pingou)"'), 1)
  517. csrf_token = self.get_csrf(output=output)
  518. data = {
  519. 'status': 'Closed',
  520. 'close_status': 'fixed'
  521. }
  522. # Invalid repo
  523. output = self.app.post('/bar/issue/1/update', data=data)
  524. self.assertEqual(output.status_code, 404)
  525. # Non-existing issue
  526. output = self.app.post('/test/issue/100/update', data=data)
  527. self.assertEqual(output.status_code, 404)
  528. output = self.app.post(
  529. '/test/issue/1/update', data=data, follow_redirects=True)
  530. self.assertEqual(output.status_code, 200)
  531. output_text = output.get_data(as_text=True)
  532. self.assertIn(
  533. '<title>Issue #1: Test issue - test - Pagure</title>',
  534. output_text)
  535. self.assertNotIn(
  536. '<a class="btn btn-outline-secondary btn-sm border-0"'
  537. ' href="/test/issue/1/edit" title="Edit this issue">',
  538. output_text)
  539. self.assertFalse(
  540. '<option selected value="Fixed">Fixed</option>'
  541. in output_text)
  542. # Right status, wrong csrf
  543. data['close_status'] = 'Fixed'
  544. output = self.app.post(
  545. '/test/issue/1/update', data=data, follow_redirects=True)
  546. self.assertEqual(output.status_code, 200)
  547. output_text = output.get_data(as_text=True)
  548. self.assertIn(
  549. '<title>Issue #1: Test issue - test - Pagure</title>',
  550. output_text)
  551. self.assertNotIn(
  552. '<a class="btn btn-outline-secondary btn-sm border-0"'
  553. ' href="/test/issue/1/edit" title="Edit this issue">',
  554. output_text)
  555. self.assertFalse(
  556. '<option selected value="Fixed">Fixed</option>'
  557. in output_text)
  558. # status update - blocked, open_access doesn't allow changing status
  559. data['csrf_token'] = csrf_token
  560. output = self.app.post(
  561. '/test/issue/1/update', data=data, follow_redirects=True)
  562. self.assertEqual(output.status_code, 200)
  563. output_text = output.get_data(as_text=True)
  564. self.assertIn(
  565. '<title>Issue #1: Test issue - test - Pagure</title>',
  566. output_text)
  567. self.assertNotIn(
  568. '<a class="btn btn-outline-secondary btn-sm border-0"'
  569. ' href="/test/issue/1/edit" title="Edit this issue">',
  570. output_text)
  571. self.assertNotIn(
  572. 'Issue close_status updated to: Fixed',
  573. output_text)
  574. self.assertNotIn(
  575. 'Issue status updated to: Closed (was: Open)',
  576. output_text)
  577. self.assertNotIn(
  578. '<option selected value="Fixed">Fixed</option>',
  579. output_text)
  580. # Add new comment
  581. data = {
  582. 'csrf_token': csrf_token,
  583. 'status': 'Closed',
  584. 'close_status': 'Fixed',
  585. 'comment': 'Woohoo a second comment!',
  586. }
  587. output = self.app.post(
  588. '/test/issue/1/update', data=data, follow_redirects=True)
  589. self.assertEqual(output.status_code, 200)
  590. output_text = output.get_data(as_text=True)
  591. self.assertIn(
  592. '<title>Issue #1: Test issue - test - Pagure</title>',
  593. output_text)
  594. self.assertNotIn(
  595. '<a class="btn btn-outline-secondary btn-sm border-0"'
  596. ' href="/test/issue/1/edit" title="Edit this issue">',
  597. output_text)
  598. self.assertIn(
  599. 'Comment added',
  600. output_text)
  601. self.assertNotIn(
  602. 'No changes to edit',
  603. output_text)
  604. self.assertIn(
  605. '<p>Woohoo a second comment!</p>',
  606. output_text)
  607. self.assertEqual(
  608. output_text.count('comment_body">'), 2)
  609. self.assertNotIn(
  610. '<option selected value="Fixed">Fixed</option>',
  611. output_text)
  612. # 1: one for the original comment
  613. self.assertEqual(
  614. output_text.count('title="PY C (pingou)"'),
  615. 1)
  616. # Add new tag
  617. data = {
  618. 'csrf_token': csrf_token,
  619. 'status': 'Closed',
  620. 'close_status': 'Fixed',
  621. 'tag': 'tag2',
  622. }
  623. output = self.app.post(
  624. '/test/issue/1/update', data=data, follow_redirects=True)
  625. self.assertEqual(output.status_code, 200)
  626. output_text = output.get_data(as_text=True)
  627. self.assertIn(
  628. '<title>Issue #1: Test issue - test - Pagure</title>',
  629. output_text)
  630. self.assertNotIn(
  631. '<a class="btn btn-outline-secondary btn-sm border-0"'
  632. ' href="/test/issue/1/edit" title="Edit this issue">',
  633. output_text)
  634. self.assertIn(
  635. '<p>Woohoo a second comment!</p>',
  636. output_text)
  637. self.assertEqual(
  638. output_text.count('comment_body">'), 2)
  639. self.assertNotIn(
  640. '<option selected value="Fixed">Fixed</option>',
  641. output_text)
  642. # Assign issue to an non-existent user
  643. data = {
  644. 'csrf_token': csrf_token,
  645. 'status': 'Closed',
  646. 'close_status': 'Fixed',
  647. 'assignee': 'ralph',
  648. }
  649. output = self.app.post(
  650. '/test/issue/1/update', data=data, follow_redirects=True)
  651. self.assertEqual(output.status_code, 200)
  652. output_text = output.get_data(as_text=True)
  653. self.assertIn(
  654. '<title>Issue #1: Test issue - test - Pagure</title>',
  655. output_text)
  656. self.assertNotIn(
  657. '<a class="btn btn-outline-secondary btn-sm border-0"'
  658. ' href="/test/issue/1/edit" title="Edit this issue">',
  659. output_text)
  660. self.assertIn(
  661. 'No user &#34;ralph&#34; found',
  662. output_text)
  663. self.assertIn(
  664. '<p>Woohoo a second comment!</p>',
  665. output_text)
  666. self.assertEqual(
  667. output_text.count('comment_body">'), 2)
  668. self.assertNotIn(
  669. '<option selected value="Fixed">Fixed</option>',
  670. output_text)
  671. # Assign issue properly
  672. data = {
  673. 'csrf_token': csrf_token,
  674. 'status': 'Closed',
  675. 'close_status': 'Fixed',
  676. 'assignee': 'pingou',
  677. }
  678. output = self.app.post(
  679. '/test/issue/1/update', data=data, follow_redirects=True)
  680. self.assertEqual(output.status_code, 200)
  681. output_text = output.get_data(as_text=True)
  682. self.assertIn(
  683. '<title>Issue #1: Test issue - test - Pagure</title>',
  684. output_text)
  685. self.assertNotIn(
  686. '<a class="btn btn-outline-secondary btn-sm border-0"'
  687. ' href="/test/issue/1/edit" title="Edit this issue">',
  688. output_text)
  689. self.assertIn('Issue assigned to pingou', output_text)
  690. self.assertIn(
  691. '<a href="/test/issues?assignee=pingou" title="PY C (pingou)"',
  692. output_text)
  693. self.assertIn(
  694. '<p>Woohoo a second comment!</p>', output_text)
  695. self.assertEqual(
  696. output_text.count('comment_body">'), 2)
  697. self.assertNotIn(
  698. '<option selected value="Fixed">Fixed</option>',
  699. output_text)
  700. # Create another issue with a dependency
  701. repo = pagure.lib.get_authorized_project(self.session, 'test')
  702. msg = pagure.lib.new_issue(
  703. session=self.session,
  704. repo=repo,
  705. title='Test issue',
  706. content='We should work on this',
  707. user='pingou',
  708. )
  709. self.session.commit()
  710. self.assertEqual(msg.title, 'Test issue')
  711. # Reset the status of the first issue
  712. parent_issue = pagure.lib.search_issues(
  713. self.session, repo, issueid=1)
  714. parent_issue.status = 'Open'
  715. self.session.add(parent_issue)
  716. # Add the dependency relationship
  717. self.session.add(parent_issue)
  718. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  719. issue.parents.append(parent_issue)
  720. self.session.add(issue)
  721. self.session.commit()
  722. with tests.user_set(self.app.application, user):
  723. data['csrf_token'] = csrf_token
  724. output = self.app.post(
  725. '/test/issue/2/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 #2: Test issue - test - Pagure</title>',
  730. output_text)
  731. self.assertNotIn(
  732. '<a class="btn btn-outline-secondary btn-sm border-0"'
  733. ' href="/test/issue/2/edit" title="Edit this issue">',
  734. output_text)
  735. self.assertNotIn(
  736. 'You cannot close a ticket '
  737. 'that has ticket depending that are still open.',
  738. output_text)
  739. self.assertNotIn(
  740. '<option selected value="Open">Open</option>',
  741. output_text)
  742. # Create private issue
  743. repo = pagure.lib.get_authorized_project(self.session, 'test')
  744. msg = pagure.lib.new_issue(
  745. session=self.session,
  746. repo=repo,
  747. title='Test issue',
  748. content='We should work on this',
  749. user='pingou',
  750. private=True,
  751. )
  752. self.session.commit()
  753. self.assertEqual(msg.title, 'Test issue')
  754. # Wrong user
  755. user = tests.FakeUser()
  756. with tests.user_set(self.app.application, user):
  757. output = self.app.post(
  758. '/test/issue/3/update', data=data, follow_redirects=True)
  759. self.assertEqual(output.status_code, 403)
  760. # Project w/o issue tracker
  761. repo = pagure.lib.get_authorized_project(self.session, 'test')
  762. repo.settings = {'issue_tracker': False}
  763. self.session.add(repo)
  764. self.session.commit()
  765. with tests.user_set(self.app.application, user):
  766. # Repo not set-up for issue tracker
  767. output = self.app.post('/test/issue/1/update', data=data)
  768. self.assertEqual(output.status_code, 404)
  769. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  770. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  771. def test_update_issue_depend(self):
  772. """ Test adding dependency via the update_issue endpoint. """
  773. # Create issues to play with
  774. repo = pagure.lib.get_authorized_project(self.session, 'test')
  775. msg = pagure.lib.new_issue(
  776. session=self.session,
  777. repo=repo,
  778. title='Test issue',
  779. content='We should work on this',
  780. user='pingou',
  781. )
  782. self.session.commit()
  783. self.assertEqual(msg.title, 'Test issue')
  784. repo = pagure.lib.get_authorized_project(self.session, 'test')
  785. msg = pagure.lib.new_issue(
  786. session=self.session,
  787. repo=repo,
  788. title='Test issue #2',
  789. content='We should work on this again',
  790. user='foo',
  791. )
  792. self.session.commit()
  793. self.assertEqual(msg.title, 'Test issue #2')
  794. user = tests.FakeUser(username='foo')
  795. with tests.user_set(self.app.application, user):
  796. output = self.app.get('/test/issue/1')
  797. self.assertEqual(output.status_code, 200)
  798. output_text = output.get_data(as_text=True)
  799. self.assertIn(
  800. '<title>Issue #1: Test issue - test - Pagure</title>',
  801. output_text)
  802. self.assertNotIn(
  803. '<a class="btn btn-outline-secondary btn-sm border-0"'
  804. ' href="/test/issue/1/edit" title="Edit this issue">',
  805. output_text)
  806. csrf_token = self.get_csrf(output=output)
  807. # Add a dependent ticket
  808. data = {
  809. 'csrf_token': csrf_token,
  810. 'depending': '2',
  811. }
  812. output = self.app.post(
  813. '/test/issue/1/update', data=data, follow_redirects=True)
  814. self.assertEqual(output.status_code, 200)
  815. output_text = output.get_data(as_text=True)
  816. self.assertIn(
  817. '<title>Issue #1: Test issue - test - Pagure</title>',
  818. output_text)
  819. self.assertNotIn(
  820. '<a class="btn btn-outline-secondary btn-sm border-0"'
  821. ' href="/test/issue/1/edit" title="Edit this issue">',
  822. output_text)
  823. # Add an invalid dependent ticket
  824. data = {
  825. 'csrf_token': csrf_token,
  826. 'depending': '2,abc',
  827. }
  828. output = self.app.post(
  829. '/test/issue/1/update', data=data, follow_redirects=True)
  830. self.assertEqual(output.status_code, 200)
  831. output_text = output.get_data(as_text=True)
  832. self.assertIn(
  833. '<title>Issue #1: Test issue - test - Pagure</title>',
  834. output_text)
  835. self.assertNotIn(
  836. '<a class="btn btn-outline-secondary btn-sm border-0"'
  837. ' href="/test/issue/1/edit" title="Edit this issue">',
  838. output_text)
  839. self.assertNotIn(
  840. 'Successfully edited issue #1',
  841. output_text)
  842. repo = pagure.lib.get_authorized_project(self.session, 'test')
  843. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  844. self.assertEqual(issue.depending_text, [2])
  845. self.assertEqual(issue.blocking_text, [])
  846. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  847. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  848. def test_update_issue_block(self):
  849. """ Test adding blocked issue via the update_issue endpoint. """
  850. # Create issues to play with
  851. repo = pagure.lib.get_authorized_project(self.session, 'test')
  852. msg = pagure.lib.new_issue(
  853. session=self.session,
  854. repo=repo,
  855. title='Test issue',
  856. content='We should work on this',
  857. user='pingou',
  858. )
  859. self.session.commit()
  860. self.assertEqual(msg.title, 'Test issue')
  861. repo = pagure.lib.get_authorized_project(self.session, 'test')
  862. msg = pagure.lib.new_issue(
  863. session=self.session,
  864. repo=repo,
  865. title='Test issue #2',
  866. content='We should work on this again',
  867. user='foo',
  868. )
  869. self.session.commit()
  870. self.assertEqual(msg.title, 'Test issue #2')
  871. # User is not an admin of the project
  872. user = tests.FakeUser(username='foo')
  873. with tests.user_set(self.app.application, user):
  874. output = self.app.get('/test/issue/1')
  875. self.assertEqual(output.status_code, 200)
  876. self.assertIn(
  877. '<title>Issue #1: Test issue - test - Pagure</title>',
  878. output.get_data(as_text=True))
  879. csrf_token = self.get_csrf(output=output)
  880. # Add a dependent ticket
  881. data = {
  882. 'csrf_token': csrf_token,
  883. 'blocking': '2',
  884. }
  885. output = self.app.post(
  886. '/test/issue/1/update', data=data, follow_redirects=True)
  887. self.assertEqual(output.status_code, 200)
  888. self.assertIn(
  889. '<title>Issue #1: Test issue - test - Pagure</title>',
  890. output.get_data(as_text=True))
  891. repo = pagure.lib.get_authorized_project(self.session, 'test')
  892. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  893. self.assertEqual(issue.depending_text, [])
  894. self.assertEqual(issue.blocking_text, [2])
  895. # Add an invalid dependent ticket
  896. data = {
  897. 'csrf_token': csrf_token,
  898. 'blocking': '2,abc',
  899. }
  900. output = self.app.post(
  901. '/test/issue/1/update', data=data, follow_redirects=True)
  902. self.assertEqual(output.status_code, 200)
  903. output_text = output.get_data(as_text=True)
  904. self.assertIn(
  905. '<title>Issue #1: Test issue - test - Pagure</title>',
  906. output_text)
  907. self.assertNotIn(
  908. '<a class="btn btn-outline-secondary btn-sm border-0"'
  909. ' href="/test/issue/1/edit" title="Edit this issue">',
  910. output_text)
  911. self.assertNotIn(
  912. 'Successfully edited issue #1',
  913. output_text)
  914. self.session.commit()
  915. repo = pagure.lib.get_authorized_project(self.session, 'test')
  916. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  917. self.assertEqual(issue.depending_text, [])
  918. self.assertEqual(issue.blocking_text, [2])
  919. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  920. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  921. def test_update_issue_edit_comment(self):
  922. """ Test the issues edit comment endpoint """
  923. # Create issues to play with
  924. repo = pagure.lib.get_authorized_project(self.session, 'test')
  925. msg = pagure.lib.new_issue(
  926. session=self.session,
  927. repo=repo,
  928. title='Test issue',
  929. content='We should work on this',
  930. user='pingou',
  931. )
  932. self.session.commit()
  933. self.assertEqual(msg.title, 'Test issue')
  934. user = tests.FakeUser(username='foo')
  935. with tests.user_set(self.app.application, user):
  936. output = self.app.get('/test/issue/1')
  937. self.assertEqual(output.status_code, 200)
  938. output_text = output.get_data(as_text=True)
  939. self.assertIn(
  940. '<title>Issue #1: Test issue - test - Pagure</title>',
  941. output_text)
  942. self.assertNotIn(
  943. '<a class="btn btn-outline-secondary btn-sm border-0"'
  944. ' href="/test/issue/1/edit" title="Edit this issue">\n',
  945. output_text)
  946. csrf_token = self.get_csrf(output=output)
  947. # Add new comment
  948. data = {
  949. 'csrf_token': csrf_token,
  950. 'comment': 'Woohoo a second comment!',
  951. }
  952. output = self.app.post(
  953. '/test/issue/1/update', data=data, follow_redirects=True)
  954. self.assertEqual(output.status_code, 200)
  955. output_text = output.get_data(as_text=True)
  956. self.assertIn(
  957. '<title>Issue #1: Test issue - test - Pagure</title>',
  958. output_text)
  959. self.assertNotIn(
  960. '<a class="btn btn-outline-secondary btn-sm border-0"'
  961. ' href="/test/issue/1/edit" title="Edit this issue">\n',
  962. output_text)
  963. self.assertIn('Comment added', output_text)
  964. self.assertIn(
  965. '<p>Woohoo a second comment!</p>',
  966. output_text)
  967. self.assertEqual(
  968. output_text.count('comment_body">'), 2)
  969. repo = pagure.lib.get_authorized_project(self.session, 'test')
  970. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  971. self.assertEqual(len(issue.comments), 1)
  972. self.assertEqual(
  973. issue.comments[0].comment,
  974. 'Woohoo a second comment!')
  975. data = {
  976. 'csrf_token': csrf_token,
  977. 'edit_comment': 1,
  978. 'update_comment': 'Updated comment',
  979. }
  980. user = tests.FakeUser()
  981. with tests.user_set(self.app.application, user):
  982. # Wrong issue id
  983. output = self.app.post(
  984. '/test/issue/3/update', data=data, follow_redirects=True)
  985. self.assertEqual(output.status_code, 404)
  986. # Wrong user
  987. output = self.app.post(
  988. '/test/issue/1/update', data=data, follow_redirects=True)
  989. self.assertEqual(output.status_code, 403)
  990. user = tests.FakeUser(username='foo')
  991. with tests.user_set(self.app.application, user):
  992. # Edit comment
  993. output = self.app.post(
  994. '/test/issue/1/update', data=data, follow_redirects=True)
  995. self.assertEqual(output.status_code, 200)
  996. output_text = output.get_data(as_text=True)
  997. self.assertIn(
  998. '<title>Issue #1: Test issue - test - Pagure</title>',
  999. output_text)
  1000. self.assertNotIn(
  1001. '<a class="btn btn-outline-secondary btn-sm border-0"'
  1002. ' href="/test/issue/1/edit" title="Edit this issue">',
  1003. output_text)
  1004. self.assertIn('Comment updated', output_text)
  1005. self.session.commit()
  1006. repo = pagure.lib.get_authorized_project(self.session, 'test')
  1007. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  1008. self.assertEqual(len(issue.comments), 1)
  1009. self.assertEqual(issue.comments[0].comment, 'Updated comment')
  1010. with tests.user_set(self.app.application, user):
  1011. output = self.app.get('/test/issue/1/comment/1/edit')
  1012. output_text = output.get_data(as_text=True)
  1013. self.assertIn(
  1014. '<title>test - Pagure</title>', output_text)
  1015. self.assertTrue('<div id="edit">' in output_text)
  1016. self.assertTrue('<section class="edit_comment">' in output_text)
  1017. self.assertTrue(
  1018. '<textarea class="form-control" id="update_comment"'
  1019. in output_text)
  1020. csrf_token = self.get_csrf(output=output)
  1021. data['csrf_token'] = csrf_token
  1022. data['update_comment'] = 'Second update'
  1023. # Edit the comment with the other endpoint
  1024. output = self.app.post(
  1025. '/test/issue/1/comment/1/edit',
  1026. data=data,
  1027. follow_redirects=True)
  1028. self.assertEqual(output.status_code, 200)
  1029. output_text = output.get_data(as_text=True)
  1030. self.assertIn(
  1031. '<title>Issue #1: Test issue - test - Pagure</title>',
  1032. output_text)
  1033. self.assertNotIn(
  1034. '<a class="btn btn-outline-secondary btn-sm border-0"'
  1035. ' href="/test/issue/1/edit" title="Edit this issue">',
  1036. output_text)
  1037. self.assertIn('Comment updated', output_text)
  1038. self.session.commit()
  1039. repo = pagure.lib.get_authorized_project(self.session, 'test')
  1040. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  1041. self.assertEqual(len(issue.comments), 1)
  1042. self.assertEqual(issue.comments[0].comment, 'Second update')
  1043. # Create another issue from someone else
  1044. repo = pagure.lib.get_authorized_project(self.session, 'test')
  1045. msg = pagure.lib.new_issue(
  1046. session=self.session,
  1047. repo=repo,
  1048. title='Test issue',
  1049. content='We should work on this',
  1050. user='foo',
  1051. )
  1052. self.session.commit()
  1053. self.assertEqual(msg.title, 'Test issue')
  1054. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  1055. self.assertEqual(len(issue.comments), 1)
  1056. self.assertEqual(issue.status, 'Open')
  1057. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  1058. self.assertEqual(len(issue.comments), 0)
  1059. self.assertEqual(issue.status, 'Open')
  1060. user = tests.FakeUser(username="foo")
  1061. with tests.user_set(self.app.application, user):
  1062. data = {
  1063. 'csrf_token': csrf_token,
  1064. 'comment': 'Nevermind figured it out',
  1065. 'status': 'Closed',
  1066. 'close_status': 'Invalid'
  1067. }
  1068. # Add a comment and close the ticket #1
  1069. output = self.app.post(
  1070. '/test/issue/1/update', data=data, follow_redirects=True)
  1071. self.assertEqual(output.status_code, 200)
  1072. output_text = output.get_data(as_text=True)
  1073. self.assertNotIn('Successfully edited issue #1\n', output_text)
  1074. self.assertIn('Comment added', output_text)
  1075. self.assertIn(
  1076. '<a class="btn btn-outline-primary border-0 btn-sm issue-metadata-display'
  1077. ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
  1078. '<i class="fa fa-fw fa-pencil">',
  1079. output_text
  1080. )
  1081. data = {
  1082. 'csrf_token': csrf_token,
  1083. 'comment': 'Nevermind figured it out',
  1084. 'status': 'Closed',
  1085. 'close_status': 'Invalid'
  1086. }
  1087. # Add a comment and close the ticket #2
  1088. output = self.app.post(
  1089. '/test/issue/2/update', data=data, follow_redirects=True)
  1090. self.assertEqual(output.status_code, 200)
  1091. output_text = output.get_data(as_text=True)
  1092. self.assertIn(
  1093. 'Issue close_status updated to: Invalid',
  1094. output_text
  1095. )
  1096. self.assertIn('Comment added', output_text)
  1097. self.assertIn(
  1098. 'Issue status updated to: Closed (was: Open)',
  1099. output_text
  1100. )
  1101. self.assertIn(
  1102. '<a class="btn btn-outline-primary border-0 btn-sm issue-metadata-display'
  1103. ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
  1104. '<i class="fa fa-fw fa-pencil">',
  1105. output_text
  1106. )
  1107. # Ticket #1 has one more comment and is still open
  1108. self.session.commit()
  1109. issue = pagure.lib.search_issues(self.session, repo, issueid=1)
  1110. self.assertEqual(len(issue.comments), 2)
  1111. self.assertEqual(issue.status, 'Open')
  1112. # Ticket #2 has one less comment and is closed
  1113. issue = pagure.lib.search_issues(self.session, repo, issueid=2)
  1114. self.assertEqual(len(issue.comments), 2)
  1115. self.assertEqual(
  1116. issue.comments[0].comment,
  1117. 'Nevermind figured it out')
  1118. self.assertEqual(
  1119. issue.comments[1].comment,
  1120. '**Metadata Update from @foo**:\n'
  1121. '- Issue close_status updated to: Invalid\n'
  1122. '- Issue status updated to: Closed (was: Open)')
  1123. self.assertEqual(issue.status, 'Closed')
  1124. @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
  1125. @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
  1126. def test_view_issue_closed(self):
  1127. """ Test viewing a closed issue. """
  1128. # Create issues to play with
  1129. repo = pagure.lib.get_authorized_project(self.session, 'test')
  1130. msg = pagure.lib.new_issue(
  1131. session=self.session,
  1132. repo=repo,
  1133. title='Test issue',
  1134. content='We should work on this',
  1135. user='pingou',
  1136. )
  1137. self.session.commit()
  1138. self.assertEqual(msg.title, 'Test issue')
  1139. user = tests.FakeUser(username='foo')
  1140. with tests.user_set(self.app.application, user):
  1141. output = self.app.get('/test/issue/1')
  1142. self.assertEqual(output.status_code, 200)
  1143. output_text = output.get_data(as_text=True)
  1144. self.assertIn(
  1145. '<title>Issue #1: Test issue - test - Pagure</title>',
  1146. output_text)
  1147. self.assertNotIn(
  1148. '<a class="btn btn-outline-secondary btn-sm border-0"'
  1149. ' href="/test/issue/1/edit" title="Edit this issue">',
  1150. output_text)
  1151. csrf_token = self.get_csrf(output=output)
  1152. # Add new comment
  1153. data = {
  1154. 'csrf_token': csrf_token,
  1155. 'status': 'Closed',
  1156. 'close_status': 'Fixed',
  1157. 'comment': 'Woohoo a second comment!',
  1158. }
  1159. output = self.app.post(
  1160. '/test/issue/1/update', data=data, follow_redirects=True)
  1161. self.assertEqual(output.status_code, 200)
  1162. output_text = output.get_data(as_text=True)
  1163. self.assertIn(
  1164. '<title>Issue #1: Test issue - test - Pagure</title>',
  1165. output_text)
  1166. self.assertNotIn(
  1167. '<a class="btn btn-outline-secondary btn-sm border-0"'
  1168. ' href="/test/issue/1/edit" title="Edit this issue">',
  1169. output_text)
  1170. self.assertIn('Comment added', output_text)
  1171. self.assertIn(
  1172. '<p>Woohoo a second comment!</p>', output_text)
  1173. self.assertEqual(output_text.count('comment_body">'), 2)
  1174. self.assertNotIn(
  1175. '<option selected value="Fixed">Fixed</option>',
  1176. output_text)
  1177. if __name__ == '__main__':
  1178. unittest.main(verbosity=2)