1
0

test_pagure_flask_ui_boards.py 27 KB

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