test_pagure_flask_ui_boards.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2015 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import unittest
  9. import shutil
  10. import sys
  11. import os
  12. import json
  13. from mock import patch, MagicMock
  14. import pygit2
  15. import pytest
  16. sys.path.insert(
  17. 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
  18. )
  19. import pagure.api
  20. import pagure.flask_app
  21. import pagure.lib.query
  22. import tests
  23. def set_projects_up(self):
  24. tests.create_projects(self.session)
  25. tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
  26. tests.add_content_git_repo(os.path.join(self.path, "repos", "test.git"))
  27. tests.create_tokens(self.session)
  28. tests.create_tokens_acl(self.session)
  29. tag = pagure.lib.model.TagColored(
  30. tag="dev", tag_color="DeepBlueSky", project_id=1
  31. )
  32. self.session.add(tag)
  33. tag = pagure.lib.model.TagColored(
  34. tag="infra", tag_color="DeepGreen", project_id=1
  35. )
  36. self.session.add(tag)
  37. self.session.commit()
  38. def set_up_board(self):
  39. headers = {
  40. "Authorization": "token aaabbbcccddd",
  41. "Content-Type": "application/json",
  42. }
  43. data = json.dumps({"dev": {"active": True, "tag": "dev"}})
  44. output = self.app.post("/api/0/test/boards", headers=headers, data=data)
  45. self.assertEqual(output.status_code, 200)
  46. data = json.loads(output.get_data(as_text=True))
  47. self.assertDictEqual(
  48. data,
  49. {
  50. "boards": [
  51. {
  52. "active": True,
  53. "name": "dev",
  54. "status": [],
  55. "tag": {
  56. "tag": "dev",
  57. "tag_color": "DeepBlueSky",
  58. "tag_description": "",
  59. },
  60. "full_url": "http://localhost.localdomain/test/boards/dev",
  61. }
  62. ]
  63. },
  64. )
  65. class PagureFlaskUiBoardstests(tests.SimplePagureTest):
  66. """Tests for flask UI Boards controller of pagure"""
  67. maxDiff = None
  68. def setUp(self):
  69. super(PagureFlaskUiBoardstests, self).setUp()
  70. set_projects_up(self)
  71. set_up_board(self)
  72. # Set up the ticket repo
  73. tests.create_projects_git(
  74. os.path.join(self.path, "repos", "tickets"), bare=True
  75. )
  76. # Set up some status to the board
  77. headers = {
  78. "Authorization": "token aaabbbcccddd",
  79. "Content-Type": "application/json",
  80. }
  81. data = json.dumps(
  82. {
  83. "Backlog": {
  84. "close": False,
  85. "close_status": "",
  86. "bg_color": "#FFB300",
  87. "default": True,
  88. "rank": 1,
  89. },
  90. "In Progress": {
  91. "close": False,
  92. "close_status": "",
  93. "bg_color": "#ca0eef",
  94. "default": False,
  95. "rank": 2,
  96. },
  97. "Done": {
  98. "close": True,
  99. "close_status": "Fixed",
  100. "bg_color": "#34d240",
  101. "default": False,
  102. "rank": 4,
  103. },
  104. }
  105. )
  106. output = self.app.post(
  107. "/api/0/test/boards/dev/status", headers=headers, data=data
  108. )
  109. self.assertEqual(output.status_code, 200)
  110. # Create two issues to play with
  111. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  112. msg = pagure.lib.query.new_issue(
  113. session=self.session,
  114. repo=repo,
  115. title="Test issue",
  116. content="We should work on this",
  117. user="pingou",
  118. )
  119. self.session.commit()
  120. self.assertEqual(msg.title, "Test issue")
  121. self.assertEqual(repo.open_tickets, 1)
  122. self.assertEqual(repo.open_tickets_public, 1)
  123. msg = pagure.lib.query.new_issue(
  124. session=self.session,
  125. repo=repo,
  126. title="Test issue #2",
  127. content="We should work on this for the second time",
  128. user="foo",
  129. status="Open",
  130. )
  131. self.session.commit()
  132. self.assertEqual(msg.title, "Test issue #2")
  133. self.assertEqual(repo.open_tickets, 2)
  134. self.assertEqual(repo.open_tickets_public, 2)
  135. msg = pagure.lib.query.new_issue(
  136. session=self.session,
  137. repo=repo,
  138. title="Private issue #3",
  139. content="We should work on this for the second time",
  140. user="foo",
  141. status="Open",
  142. private=True,
  143. )
  144. self.session.commit()
  145. self.assertEqual(msg.title, "Private issue #3")
  146. self.assertEqual(repo.open_tickets, 3)
  147. self.assertEqual(repo.open_tickets_public, 2)
  148. self.tickets_uid = [t.uid for t in repo.issues]
  149. def test_view_board_empty(self):
  150. output = self.app.get("/test/boards/dev")
  151. self.assertEqual(output.status_code, 200)
  152. output_text = output.get_data(as_text=True)
  153. # There are 3 columns
  154. self.assertEqual(output_text.count("drag-inner-list"), 3)
  155. self.assertEqual(output_text.count("drag-inner"), 3)
  156. # No tickets
  157. self.assertEqual(output_text.count("text-success"), 0)
  158. # One (!) in the nav bar on the issues title
  159. self.assertEqual(output_text.count("fa-exclamation-circle"), 1)
  160. @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
  161. @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
  162. def test_update_issue_add_tags_check_board_not_tagged(self):
  163. """Test the update_issue endpoint."""
  164. # Before update, list tags
  165. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  166. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  167. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  168. self.assertEqual(repo.issues[0].tags_text, [])
  169. user = tests.FakeUser()
  170. user.username = "pingou"
  171. with tests.user_set(self.app.application, user):
  172. csrf_token = self.get_csrf()
  173. # Tag to the issue
  174. data = {"csrf_token": csrf_token, "tag": "infra"}
  175. output = self.app.post(
  176. "/test/issue/1/update", data=data, follow_redirects=True
  177. )
  178. self.assertEqual(output.status_code, 200)
  179. output_text = output.get_data(as_text=True)
  180. self.assertIn(
  181. "<title>Issue #1: Test issue - test - Pagure</title>",
  182. output_text,
  183. )
  184. self.assertIn(
  185. '<a class="btn btn-outline-secondary btn-sm border-0"'
  186. ' href="/test/issue/1/edit" title="Edit this issue">',
  187. output_text,
  188. )
  189. self.assertIn("</i> Issue tagged with: infra</div>", output_text)
  190. # After update, list tags
  191. self.session = pagure.lib.query.create_session(self.dbpath)
  192. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  193. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  194. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  195. self.assertEqual(repo.issues[0].tags_text, ["infra"])
  196. self.assertEqual(repo.issues[1].tags_text, [])
  197. # Check the board - No changes since the ticket was tagged `infra`
  198. output = self.app.get("/test/boards/dev")
  199. self.assertEqual(output.status_code, 200)
  200. output_text = output.get_data(as_text=True)
  201. # There are 3 columns
  202. self.assertEqual(output_text.count("drag-inner-list"), 3)
  203. self.assertEqual(output_text.count("drag-inner"), 3)
  204. # 0 ticket
  205. self.assertEqual(output_text.count("id_txt"), 0)
  206. self.assertEqual(output_text.count("text-success"), 0)
  207. self.assertEqual(output_text.count("text-danger"), 0)
  208. # One (!) in the nav bar on the issues title
  209. self.assertEqual(output_text.count("fa-exclamation-circle"), 1)
  210. @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
  211. @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
  212. def test_update_issue_add_tags_check_board(self):
  213. """Test the update_issue endpoint."""
  214. # Before update, list tags
  215. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  216. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  217. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  218. self.assertEqual(repo.issues[0].tags_text, [])
  219. user = tests.FakeUser()
  220. user.username = "pingou"
  221. with tests.user_set(self.app.application, user):
  222. csrf_token = self.get_csrf()
  223. # Tag to the issue
  224. data = {"csrf_token": csrf_token, "tag": "dev"}
  225. output = self.app.post(
  226. "/test/issue/1/update", data=data, follow_redirects=True
  227. )
  228. self.assertEqual(output.status_code, 200)
  229. output_text = output.get_data(as_text=True)
  230. self.assertIn(
  231. "<title>Issue #1: Test issue - test - Pagure</title>",
  232. output_text,
  233. )
  234. self.assertIn(
  235. '<a class="btn btn-outline-secondary btn-sm border-0"'
  236. ' href="/test/issue/1/edit" title="Edit this issue">',
  237. output_text,
  238. )
  239. self.assertIn("</i> Issue tagged with: dev</div>", output_text)
  240. # After update, list tags
  241. self.session = pagure.lib.query.create_session(self.dbpath)
  242. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  243. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  244. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  245. self.assertEqual(repo.issues[0].tags_text, ["dev"])
  246. self.assertEqual(repo.issues[1].tags_text, [])
  247. # Check the board - Ticket added
  248. output = self.app.get("/test/boards/dev")
  249. self.assertEqual(output.status_code, 200)
  250. output_text = output.get_data(as_text=True)
  251. # There are 3 columns
  252. self.assertEqual(output_text.count("drag-inner-list"), 3)
  253. self.assertEqual(output_text.count("drag-inner"), 3)
  254. # One ticket
  255. self.assertEqual(output_text.count(" id_txt"), 1)
  256. self.assertEqual(output_text.count(" text-success"), 1)
  257. self.assertEqual(output_text.count(" text-danger"), 0)
  258. # Two (!) in the nav bar on the issues title + the ticket
  259. self.assertEqual(output_text.count("fa-exclamation-circle"), 2)
  260. @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
  261. @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
  262. def test_update_issue_add_tags_check_board_remove_tag_check_board(self):
  263. """Test the update_issue endpoint."""
  264. # Before update, list tags
  265. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  266. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  267. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  268. self.assertEqual(repo.issues[0].tags_text, [])
  269. user = tests.FakeUser()
  270. user.username = "pingou"
  271. with tests.user_set(self.app.application, user):
  272. csrf_token = self.get_csrf()
  273. # Tag to the issue
  274. data = {"csrf_token": csrf_token, "tag": "dev"}
  275. output = self.app.post(
  276. "/test/issue/1/update", data=data, follow_redirects=True
  277. )
  278. self.assertEqual(output.status_code, 200)
  279. output_text = output.get_data(as_text=True)
  280. self.assertIn(
  281. "<title>Issue #1: Test issue - test - Pagure</title>",
  282. output_text,
  283. )
  284. self.assertIn(
  285. '<a class="btn btn-outline-secondary btn-sm border-0"'
  286. ' href="/test/issue/1/edit" title="Edit this issue">',
  287. output_text,
  288. )
  289. self.assertIn("</i> Issue tagged with: dev</div>", output_text)
  290. # After update, list tags
  291. self.session = pagure.lib.query.create_session(self.dbpath)
  292. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  293. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  294. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  295. self.assertEqual(repo.issues[0].tags_text, ["dev"])
  296. self.assertEqual(repo.issues[1].tags_text, [])
  297. # Check the board - Ticket added
  298. output = self.app.get("/test/boards/dev")
  299. self.assertEqual(output.status_code, 200)
  300. output_text = output.get_data(as_text=True)
  301. # There are 3 columns
  302. self.assertEqual(output_text.count("drag-inner-list"), 3)
  303. self.assertEqual(output_text.count("drag-inner"), 3)
  304. # One ticket
  305. self.assertEqual(output_text.count(" id_txt"), 1)
  306. self.assertEqual(output_text.count(" text-success"), 1)
  307. self.assertEqual(output_text.count(" text-danger"), 0)
  308. # Two (!) in the nav bar on the issues title + the ticket
  309. self.assertEqual(output_text.count("fa-exclamation-circle"), 2)
  310. # Now remove the "dev" tag in favor of the "infra" one
  311. user = tests.FakeUser()
  312. user.username = "pingou"
  313. with tests.user_set(self.app.application, user):
  314. csrf_token = self.get_csrf()
  315. # Tag to the issue
  316. data = {"csrf_token": csrf_token, "tag": "infra"}
  317. output = self.app.post(
  318. "/test/issue/1/update", data=data, follow_redirects=True
  319. )
  320. self.assertEqual(output.status_code, 200)
  321. output_text = output.get_data(as_text=True)
  322. self.assertIn(
  323. "<title>Issue #1: Test issue - test - Pagure</title>",
  324. output_text,
  325. )
  326. self.assertIn(
  327. '<a class="btn btn-outline-secondary btn-sm border-0"'
  328. ' href="/test/issue/1/edit" title="Edit this issue">',
  329. output_text,
  330. )
  331. self.assertIn("</i> Issue tagged with: infra</div>", output_text)
  332. # After update, list tags
  333. self.session = pagure.lib.query.create_session(self.dbpath)
  334. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  335. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  336. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  337. self.assertEqual(repo.issues[0].tags_text, ["infra"])
  338. self.assertEqual(repo.issues[1].tags_text, [])
  339. # Check the board - Ticket added
  340. output = self.app.get("/test/boards/dev")
  341. self.assertEqual(output.status_code, 200)
  342. output_text = output.get_data(as_text=True)
  343. # There are 3 columns
  344. self.assertEqual(output_text.count("drag-inner-list"), 3)
  345. self.assertEqual(output_text.count("drag-inner"), 3)
  346. # 0 ticket
  347. self.assertEqual(output_text.count(" id_txt"), 0)
  348. self.assertEqual(output_text.count(" text-success"), 0)
  349. self.assertEqual(output_text.count(" text-danger"), 0)
  350. # One (!) in the nav bar on the issues title
  351. self.assertEqual(output_text.count("fa-exclamation-circle"), 1)
  352. def test_view_board_ticket_closed(self):
  353. headers = {"Content-Type": "application/json"}
  354. data = json.dumps({"2": {"status": "Done", "rank": 2}})
  355. user = tests.FakeUser()
  356. user.username = "pingou"
  357. with tests.user_set(self.app.application, user):
  358. output = self.app.post(
  359. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  360. )
  361. self.assertEqual(output.status_code, 200)
  362. data = json.loads(output.get_data(as_text=True))
  363. self.session = pagure.lib.query.create_session(self.dbpath)
  364. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  365. self.assertEqual(repo.issues[0].status, "Open")
  366. self.assertEqual(repo.issues[1].status, "Closed")
  367. self.assertEqual(repo.issues[1].close_status, "Fixed")
  368. # Check the board - Ticket added - as Done
  369. output = self.app.get("/test/boards/dev")
  370. self.assertEqual(output.status_code, 200)
  371. output_text = output.get_data(as_text=True)
  372. # There are 3 columns
  373. self.assertEqual(output_text.count("drag-inner-list"), 3)
  374. self.assertEqual(output_text.count("drag-inner"), 3)
  375. # One ticket
  376. self.assertEqual(output_text.count(" id_txt"), 1)
  377. self.assertEqual(output_text.count(" text-success"), 0)
  378. self.assertEqual(output_text.count(" text-danger"), 1)
  379. # Two (!) in the nav bar on the issues title + the ticket
  380. self.assertEqual(output_text.count("fa-exclamation-circle"), 2)
  381. def test_view_board_private_ticket(self):
  382. user = tests.FakeUser()
  383. user.username = "pingou"
  384. with tests.user_set(self.app.application, user):
  385. headers = {"Content-Type": "application/json"}
  386. data = json.dumps({"3": {"status": "Done", "rank": 2}})
  387. output = self.app.post(
  388. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  389. )
  390. self.assertEqual(output.status_code, 200)
  391. data = json.loads(output.get_data(as_text=True))
  392. self.session = pagure.lib.query.create_session(self.dbpath)
  393. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  394. self.assertEqual(repo.issues[0].status, "Open")
  395. self.assertEqual(len(repo.issues[0].boards_issues), 0)
  396. self.assertEqual(repo.issues[1].status, "Open")
  397. self.assertEqual(len(repo.issues[1].boards_issues), 0)
  398. self.assertEqual(repo.issues[2].status, "Closed")
  399. self.assertEqual(repo.issues[2].close_status, "Fixed")
  400. self.assertEqual(len(repo.issues[2].boards_issues), 1)
  401. # Check the board - Looks empty user not authenticated
  402. output = self.app.get("/test/boards/dev")
  403. self.assertEqual(output.status_code, 200)
  404. output_text = output.get_data(as_text=True)
  405. # There are 3 columns
  406. self.assertEqual(output_text.count("drag-inner-list"), 3)
  407. self.assertEqual(output_text.count("drag-inner"), 3)
  408. # 0 ticket
  409. self.assertEqual(output_text.count(" id_txt"), 0)
  410. self.assertEqual(output_text.count("text-success"), 0)
  411. self.assertEqual(output_text.count("text-danger"), 0)
  412. # 1 (!) in the nav bar on the issues title
  413. self.assertEqual(output_text.count("fa-exclamation-circle"), 1)
  414. self.assertEqual(output_text.count('title="Private ticket"'), 0)
  415. user = tests.FakeUser()
  416. user.username = "ralph"
  417. with tests.user_set(self.app.application, user):
  418. # Check the board - Looks empty user not allowed
  419. output = self.app.get("/test/boards/dev")
  420. self.assertEqual(output.status_code, 200)
  421. output_text = output.get_data(as_text=True)
  422. # There are 3 columns
  423. self.assertEqual(output_text.count("drag-inner-list"), 3)
  424. self.assertEqual(output_text.count("drag-inner"), 3)
  425. # 0 ticket
  426. self.assertEqual(output_text.count(" id_txt"), 0)
  427. self.assertEqual(output_text.count("text-success"), 0)
  428. self.assertEqual(output_text.count("text-danger"), 0)
  429. # 1 (!) in the nav bar on the issues title
  430. self.assertEqual(output_text.count("fa-exclamation-circle"), 2)
  431. self.assertEqual(output_text.count('title="Private ticket"'), 0)
  432. user = tests.FakeUser()
  433. user.username = "foo"
  434. with tests.user_set(self.app.application, user):
  435. # Check the board - 1 ticket
  436. output = self.app.get("/test/boards/dev")
  437. self.assertEqual(output.status_code, 200)
  438. output_text = output.get_data(as_text=True)
  439. # There are 3 columns
  440. self.assertEqual(output_text.count("drag-inner-list"), 3)
  441. self.assertEqual(output_text.count("drag-inner"), 3)
  442. # 1 ticket
  443. self.assertEqual(output_text.count(" id_txt"), 1)
  444. self.assertEqual(output_text.count(" text-success"), 0)
  445. self.assertEqual(output_text.count(" text-danger"), 1)
  446. # 2 (!) in the nav bar on the issues title
  447. self.assertEqual(output_text.count("fa-exclamation-circle"), 3)
  448. self.assertEqual(output_text.count('title="Private ticket"'), 1)
  449. user = tests.FakeUser()
  450. user.username = "pingou"
  451. with tests.user_set(self.app.application, user):
  452. # Check the board - 1 ticket
  453. output = self.app.get("/test/boards/dev")
  454. self.assertEqual(output.status_code, 200)
  455. output_text = output.get_data(as_text=True)
  456. # There are 3 columns
  457. self.assertEqual(output_text.count("drag-inner-list"), 3)
  458. self.assertEqual(output_text.count("drag-inner"), 3)
  459. # 1 ticket
  460. self.assertEqual(output_text.count(" id_txt"), 1)
  461. self.assertEqual(output_text.count(" text-success"), 0)
  462. self.assertEqual(output_text.count(" text-danger"), 1)
  463. # 2 (!) in the nav bar on the issues title
  464. self.assertEqual(output_text.count("fa-exclamation-circle"), 3)
  465. self.assertEqual(output_text.count('title="Private ticket"'), 1)
  466. @patch("pagure.lib.notify.send_email", new=MagicMock(return_value=True))
  467. def test_ticket_representation_in_git(self):
  468. user = tests.FakeUser()
  469. user.username = "pingou"
  470. with tests.user_set(self.app.application, user):
  471. csrf_token = self.get_csrf()
  472. # Tag to the issue
  473. data = {"csrf_token": csrf_token, "tag": "dev"}
  474. output = self.app.post(
  475. "/test/issue/1/update", data=data, follow_redirects=True
  476. )
  477. self.assertEqual(output.status_code, 200)
  478. output_text = output.get_data(as_text=True)
  479. self.assertIn(
  480. "<title>Issue #1: Test issue - test - Pagure</title>",
  481. output_text,
  482. )
  483. self.assertIn(
  484. '<a class="btn btn-outline-secondary btn-sm border-0"'
  485. ' href="/test/issue/1/edit" title="Edit this issue">',
  486. output_text,
  487. )
  488. self.assertIn("</i> Issue tagged with: dev</div>", output_text)
  489. # After update, list tags
  490. self.session = pagure.lib.query.create_session(self.dbpath)
  491. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  492. tags = pagure.lib.query.get_tags_of_project(self.session, repo)
  493. self.assertEqual([tag.tag for tag in tags], ["dev", "infra"])
  494. self.assertEqual(repo.issues[0].tags_text, ["dev"])
  495. self.assertEqual(repo.issues[1].tags_text, [])
  496. self.session = pagure.lib.query.create_session(self.dbpath)
  497. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  498. self.assertEqual(repo.issues[1].status, "Open")
  499. self.assertEqual(repo.issues[1].close_status, None)
  500. # Clone the repo so it isn't a bare repo
  501. pygit2.clone_repository(
  502. os.path.join(self.path, "repos", "tickets", "test.git"),
  503. os.path.join(self.path, "repos", "tickets", "test"),
  504. )
  505. exp = {
  506. "assignee": None,
  507. "blocks": [],
  508. "boards": [
  509. {
  510. "board": {
  511. "active": True,
  512. "name": "dev",
  513. "status": [
  514. {
  515. "bg_color": "#FFB300",
  516. "close": False,
  517. "close_status": None,
  518. "default": True,
  519. "name": "Backlog",
  520. },
  521. {
  522. "bg_color": "#ca0eef",
  523. "close": False,
  524. "close_status": None,
  525. "default": False,
  526. "name": "In Progress",
  527. },
  528. {
  529. "bg_color": "#34d240",
  530. "close": True,
  531. "close_status": "Fixed",
  532. "default": False,
  533. "name": "Done",
  534. },
  535. ],
  536. "tag": {
  537. "tag": "dev",
  538. "tag_color": "DeepBlueSky",
  539. "tag_description": "",
  540. },
  541. "full_url": "http://localhost.localdomain/test/boards/dev",
  542. },
  543. "rank": 1,
  544. "status": {
  545. "bg_color": "#FFB300",
  546. "close": False,
  547. "close_status": None,
  548. "default": True,
  549. "name": "Backlog",
  550. },
  551. }
  552. ],
  553. "close_status": None,
  554. "closed_at": None,
  555. "closed_by": None,
  556. "comments": [
  557. {
  558. "comment": "**Metadata Update from @pingou**:\n"
  559. "- Issue tagged with: dev",
  560. "date_created": "1594654596",
  561. "edited_on": None,
  562. "editor": None,
  563. "id": 1,
  564. "notification": True,
  565. "parent": None,
  566. "reactions": {},
  567. "user": {
  568. "default_email": "bar@pingou.com",
  569. "emails": ["bar@pingou.com", "foo@pingou.com"],
  570. "fullname": "PY C",
  571. "name": "pingou",
  572. "url_path": "user/pingou",
  573. "full_url": "http://localhost.localdomain/user/pingou",
  574. },
  575. }
  576. ],
  577. "content": "We should work on this",
  578. "custom_fields": [],
  579. "date_created": "1594654596",
  580. "depends": [],
  581. "full_url": "http://localhost.localdomain/test/issue/1",
  582. "id": 1,
  583. "last_updated": "1594654596",
  584. "milestone": None,
  585. "priority": None,
  586. "private": False,
  587. "related_prs": [],
  588. "status": "Open",
  589. "tags": ["dev"],
  590. "title": "Test issue",
  591. "user": {
  592. "default_email": "bar@pingou.com",
  593. "emails": ["bar@pingou.com", "foo@pingou.com"],
  594. "fullname": "PY C",
  595. "name": "pingou",
  596. "url_path": "user/pingou",
  597. "full_url": "http://localhost.localdomain/user/pingou",
  598. },
  599. }
  600. with open(
  601. os.path.join(
  602. self.path, "repos", "tickets", "test", repo.issues[0].uid
  603. )
  604. ) as stream:
  605. data = json.load(stream)
  606. # Make the date fix
  607. for idx, com in enumerate(data["comments"]):
  608. com["date_created"] = "1594654596"
  609. data["comments"][idx] = com
  610. data["date_created"] = "1594654596"
  611. data["last_updated"] = "1594654596"
  612. self.assertDictEqual(data, exp)
  613. if __name__ == "__main__":
  614. unittest.main(verbosity=2)