1
0

test_pagure_flask_api_boards.py 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  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. import pygit2
  14. from mock import patch, MagicMock
  15. sys.path.insert(
  16. 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
  17. )
  18. import pagure.api
  19. import pagure.flask_app
  20. import pagure.lib.query
  21. import tests
  22. def set_projects_up(self):
  23. tests.create_projects(self.session)
  24. tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
  25. tests.add_content_git_repo(os.path.join(self.path, "repos", "test.git"))
  26. tests.create_tokens(self.session)
  27. tests.create_tokens_acl(self.session)
  28. tag = pagure.lib.model.TagColored(
  29. tag="dev", tag_color="DeepBlueSky", project_id=1
  30. )
  31. self.session.add(tag)
  32. tag = pagure.lib.model.TagColored(
  33. tag="infra", tag_color="DeepGreen", project_id=1
  34. )
  35. self.session.add(tag)
  36. self.session.commit()
  37. def set_up_board(self):
  38. headers = {
  39. "Authorization": "token aaabbbcccddd",
  40. "Content-Type": "application/json",
  41. }
  42. data = json.dumps({"dev": {"active": True, "tag": "dev"}})
  43. output = self.app.post("/api/0/test/boards", headers=headers, data=data)
  44. self.assertEqual(output.status_code, 200)
  45. data = json.loads(output.get_data(as_text=True))
  46. self.assertDictEqual(
  47. data,
  48. {
  49. "boards": [
  50. {
  51. "active": True,
  52. "name": "dev",
  53. "status": [],
  54. "tag": {
  55. "tag": "dev",
  56. "tag_color": "DeepBlueSky",
  57. "tag_description": "",
  58. },
  59. }
  60. ]
  61. },
  62. )
  63. class PagureFlaskApiBoardstests(tests.SimplePagureTest):
  64. """ Tests for flask API Boards controller of pagure """
  65. maxDiff = None
  66. def setUp(self):
  67. super(PagureFlaskApiBoardstests, self).setUp()
  68. set_projects_up(self)
  69. def test_api_boards_view_no_project(self):
  70. output = self.app.get("/api/0/invalid/boards")
  71. self.assertEqual(output.status_code, 404)
  72. data = json.loads(output.get_data(as_text=True))
  73. self.assertDictEqual(
  74. data, {"error": "Project not found", "error_code": "ENOPROJECT"}
  75. )
  76. def test_api_boards_view_empty(self):
  77. output = self.app.get("/api/0/test/boards")
  78. self.assertEqual(output.status_code, 200)
  79. data = json.loads(output.get_data(as_text=True))
  80. self.assertDictEqual(data, {"boards": [], "total_requests": 0})
  81. def test_api_board_create_no_token(self):
  82. headers = {}
  83. data = {}
  84. output = self.app.post(
  85. "/api/0/test/boards", headers=headers, data=data
  86. )
  87. self.assertEqual(output.status_code, 401)
  88. data = json.loads(output.get_data(as_text=True))
  89. self.assertDictEqual(
  90. data,
  91. {
  92. "error": "Invalid or expired token. Please visit "
  93. "http://localhost.localdomain/settings#nav-api-tab to get or renew "
  94. "your API token.",
  95. "error_code": "EINVALIDTOK",
  96. "errors": "Invalid token",
  97. },
  98. )
  99. def test_api_board_create_expired_token(self):
  100. headers = {"Authorization": "token expired_token"}
  101. data = {}
  102. output = self.app.post(
  103. "/api/0/test/boards", headers=headers, data=data
  104. )
  105. self.assertEqual(output.status_code, 401)
  106. data = json.loads(output.get_data(as_text=True))
  107. self.assertDictEqual(
  108. data,
  109. {
  110. "error": "Invalid or expired token. Please visit "
  111. "http://localhost.localdomain/settings#nav-api-tab to get or renew "
  112. "your API token.",
  113. "error_code": "EINVALIDTOK",
  114. "errors": "Expired token",
  115. },
  116. )
  117. def test_api_board_create_invalid_token_project(self):
  118. headers = {"Authorization": "token aaabbbcccddd"}
  119. data = {}
  120. output = self.app.post(
  121. "/api/0/test2/boards", headers=headers, data=data
  122. )
  123. self.assertEqual(output.status_code, 401)
  124. data = json.loads(output.get_data(as_text=True))
  125. self.assertDictEqual(
  126. data,
  127. {
  128. "error": "Invalid or expired token. Please visit "
  129. "http://localhost.localdomain/settings#nav-api-tab to get or renew "
  130. "your API token.",
  131. "error_code": "EINVALIDTOK",
  132. },
  133. )
  134. def test_api_board_create_no_data(self):
  135. headers = {"Authorization": "token aaabbbcccddd"}
  136. data = {}
  137. output = self.app.post(
  138. "/api/0/test/boards", headers=headers, data=data
  139. )
  140. self.assertEqual(output.status_code, 400)
  141. data = json.loads(output.get_data(as_text=True))
  142. self.assertDictEqual(
  143. data,
  144. {
  145. "error": "Invalid or incomplete input submitted",
  146. "error_code": "EINVALIDREQ",
  147. "errors": "No (JSON) data provided",
  148. },
  149. )
  150. def test_api_board_create_no_contenttype(self):
  151. headers = {"Authorization": "token aaabbbcccddd"}
  152. data = {"name": "board", "active": True, "Tag": "not found"}
  153. output = self.app.post(
  154. "/api/0/test/boards", headers=headers, data=data
  155. )
  156. self.assertEqual(output.status_code, 400)
  157. data = json.loads(output.get_data(as_text=True))
  158. self.assertDictEqual(
  159. data,
  160. {
  161. "error": "Invalid or incomplete input submitted",
  162. "error_code": "EINVALIDREQ",
  163. "errors": "No (JSON) data provided",
  164. },
  165. )
  166. def test_api_board_create_html_data(self):
  167. headers = {
  168. "Authorization": "token aaabbbcccddd",
  169. "Content-Type": "application/json",
  170. }
  171. data = {"name": "board", "active": True, "tag": "not found"}
  172. output = self.app.post(
  173. "/api/0/test/boards", headers=headers, data=data
  174. )
  175. self.assertEqual(output.status_code, 400)
  176. self.assertIn(
  177. "The browser (or proxy) sent a request that this server could not understand.",
  178. output.get_data(as_text=True),
  179. )
  180. def test_api_board_create_invalid_json(self):
  181. headers = {
  182. "Authorization": "token aaabbbcccddd",
  183. "Content-Type": "application/json",
  184. }
  185. data = json.dumps(
  186. {"name": "board", "active": True, "tag": "not found"}
  187. )
  188. output = self.app.post(
  189. "/api/0/test/boards", headers=headers, data=data
  190. )
  191. self.assertEqual(output.status_code, 400)
  192. data = json.loads(output.get_data(as_text=True))
  193. self.assertDictEqual(
  194. data,
  195. {
  196. "error": "Invalid or incomplete input submitted",
  197. "error_code": "EINVALIDREQ",
  198. "errors": "No tag associated with at least one of the boards",
  199. },
  200. )
  201. def test_api_board_create_invalid_tag(self):
  202. headers = {
  203. "Authorization": "token aaabbbcccddd",
  204. "Content-Type": "application/json",
  205. }
  206. data = json.dumps({"dev": {"active": True, "tag": "not found"}})
  207. output = self.app.post(
  208. "/api/0/test/boards", headers=headers, data=data
  209. )
  210. self.assertEqual(output.status_code, 400)
  211. data = json.loads(output.get_data(as_text=True))
  212. self.assertDictEqual(
  213. data,
  214. {
  215. "error": "No tag found with the name not found",
  216. "error_code": "ENOCODE",
  217. },
  218. )
  219. def test_api_board_create(self):
  220. headers = {
  221. "Authorization": "token aaabbbcccddd",
  222. "Content-Type": "application/json",
  223. }
  224. data = json.dumps({"dev": {"active": True, "tag": "dev"}})
  225. output = self.app.post(
  226. "/api/0/test/boards", headers=headers, data=data
  227. )
  228. self.assertEqual(output.status_code, 200)
  229. data = json.loads(output.get_data(as_text=True))
  230. self.assertDictEqual(
  231. data,
  232. {
  233. "boards": [
  234. {
  235. "active": True,
  236. "name": "dev",
  237. "status": [],
  238. "tag": {
  239. "tag": "dev",
  240. "tag_color": "DeepBlueSky",
  241. "tag_description": "",
  242. },
  243. }
  244. ]
  245. },
  246. )
  247. def test_api_board_edit_board_delete_board(self):
  248. headers = {
  249. "Authorization": "token aaabbbcccddd",
  250. "Content-Type": "application/json",
  251. }
  252. # Add 2 boards to the project
  253. data = json.dumps(
  254. {
  255. "dev": {"active": True, "tag": "dev"},
  256. "infra": {"active": True, "tag": "infra"},
  257. }
  258. )
  259. output = self.app.post(
  260. "/api/0/test/boards", headers=headers, data=data
  261. )
  262. self.assertEqual(output.status_code, 200)
  263. data = json.loads(output.get_data(as_text=True))
  264. self.assertDictEqual(
  265. data,
  266. {
  267. "boards": [
  268. {
  269. "active": True,
  270. "name": "dev",
  271. "status": [],
  272. "tag": {
  273. "tag": "dev",
  274. "tag_color": "DeepBlueSky",
  275. "tag_description": "",
  276. },
  277. },
  278. {
  279. "active": True,
  280. "name": "infra",
  281. "status": [],
  282. "tag": {
  283. "tag": "infra",
  284. "tag_color": "DeepGreen",
  285. "tag_description": "",
  286. },
  287. },
  288. ]
  289. },
  290. )
  291. # Remove one of the 2 boards
  292. data = json.dumps({"dev": {"active": True, "tag": "dev"},})
  293. output = self.app.post(
  294. "/api/0/test/boards", headers=headers, data=data
  295. )
  296. self.assertEqual(output.status_code, 200)
  297. data = json.loads(output.get_data(as_text=True))
  298. self.assertDictEqual(
  299. data,
  300. {
  301. "boards": [
  302. {
  303. "active": True,
  304. "name": "dev",
  305. "status": [],
  306. "tag": {
  307. "tag": "dev",
  308. "tag_color": "DeepBlueSky",
  309. "tag_description": "",
  310. },
  311. }
  312. ]
  313. },
  314. )
  315. # Removing the last board doesn't work (no JSON data provided)
  316. data = json.dumps({})
  317. output = self.app.post(
  318. "/api/0/test/boards", headers=headers, data=data
  319. )
  320. self.assertEqual(output.status_code, 400)
  321. def test_api_board_delete_board(self):
  322. headers = {
  323. "Authorization": "token aaabbbcccddd",
  324. "Content-Type": "application/json",
  325. }
  326. data = json.dumps({"name": ["dev"]})
  327. output = self.app.post(
  328. "/api/0/test/boards/delete", headers=headers, data=data
  329. )
  330. self.assertEqual(output.status_code, 200)
  331. data = json.loads(output.get_data(as_text=True))
  332. self.assertDictEqual(data, {"boards": []})
  333. def test_api_board_api_board_status_no_board(self):
  334. headers = {
  335. "Authorization": "token aaabbbcccddd",
  336. "Content-Type": "application/json",
  337. }
  338. data = json.dumps({"foo": "bar"})
  339. output = self.app.post(
  340. "/api/0/test/boards/invalid/status", headers=headers, data=data
  341. )
  342. self.assertEqual(output.status_code, 404)
  343. data = json.loads(output.get_data(as_text=True))
  344. self.assertDictEqual(
  345. data,
  346. {
  347. "error": "Invalid or incomplete input submitted",
  348. "error_code": "EINVALIDREQ",
  349. "errors": "Board not found",
  350. },
  351. )
  352. class PagureFlaskApiBoardsWithBoardtests(tests.SimplePagureTest):
  353. """ Tests for flask API Boards controller of pagure for the tests
  354. requiring a pre-existing board.
  355. """
  356. maxDiff = None
  357. def setUp(self):
  358. super(PagureFlaskApiBoardsWithBoardtests, self).setUp()
  359. set_projects_up(self)
  360. set_up_board(self)
  361. def test_api_board_edit_board(self):
  362. headers = {
  363. "Authorization": "token aaabbbcccddd",
  364. "Content-Type": "application/json",
  365. }
  366. # Make the board inactive
  367. data = json.dumps({"dev": {"active": False, "tag": "dev"}})
  368. output = self.app.post(
  369. "/api/0/test/boards", headers=headers, data=data
  370. )
  371. self.assertEqual(output.status_code, 200)
  372. data = json.loads(output.get_data(as_text=True))
  373. self.assertDictEqual(
  374. data,
  375. {
  376. "boards": [
  377. {
  378. "active": False,
  379. "name": "dev",
  380. "status": [],
  381. "tag": {
  382. "tag": "dev",
  383. "tag_color": "DeepBlueSky",
  384. "tag_description": "",
  385. },
  386. }
  387. ]
  388. },
  389. )
  390. def test_api_board_edit_board_invalid_tag(self):
  391. headers = {
  392. "Authorization": "token aaabbbcccddd",
  393. "Content-Type": "application/json",
  394. }
  395. # Associate the existing board with an invalid tag
  396. data = json.dumps({"dev": {"active": True, "tag": "invalid"},})
  397. output = self.app.post(
  398. "/api/0/test/boards", headers=headers, data=data
  399. )
  400. self.assertEqual(output.status_code, 400)
  401. data = json.loads(output.get_data(as_text=True))
  402. self.assertDictEqual(
  403. data,
  404. {
  405. "error": "No tag found with the name invalid",
  406. "error_code": "ENOCODE",
  407. },
  408. )
  409. def test_api_board_delete_invalid_json_input(self):
  410. headers = {
  411. "Authorization": "token aaabbbcccddd",
  412. "Content-Type": "application/json",
  413. }
  414. # Remove this board
  415. data = json.dumps({})
  416. output = self.app.post(
  417. "/api/0/test/boards/delete", headers=headers, data=data
  418. )
  419. self.assertEqual(output.status_code, 400)
  420. data = json.loads(output.get_data(as_text=True))
  421. self.assertDictEqual(
  422. data,
  423. {
  424. "error": "Invalid or incomplete input submitted",
  425. "error_code": "EINVALIDREQ",
  426. "errors": {"name": ["This field is required"]},
  427. },
  428. )
  429. def test_api_board_delete_invalid_html_input(self):
  430. headers = {
  431. "Authorization": "token aaabbbcccddd",
  432. }
  433. # Remove the board
  434. headers = {
  435. "Authorization": "token aaabbbcccddd",
  436. }
  437. data = {}
  438. output = self.app.post(
  439. "/api/0/test/boards/delete", headers=headers, data=data
  440. )
  441. self.assertEqual(output.status_code, 400)
  442. data = json.loads(output.get_data(as_text=True))
  443. self.assertDictEqual(
  444. data,
  445. {
  446. "error": "Invalid or incomplete input submitted",
  447. "error_code": "EINVALIDREQ",
  448. "errors": {"name": ["This field is required"]},
  449. },
  450. )
  451. def test_api_board_delete_json_input(self):
  452. headers = {
  453. "Authorization": "token aaabbbcccddd",
  454. "Content-Type": "application/json",
  455. }
  456. # Remove the board
  457. data = json.dumps({"name": ["dev"]})
  458. output = self.app.post(
  459. "/api/0/test/boards/delete", headers=headers, data=data
  460. )
  461. self.assertEqual(output.status_code, 200)
  462. data = json.loads(output.get_data(as_text=True))
  463. self.assertDictEqual(
  464. data, {"boards": []},
  465. )
  466. def test_api_board_delete_html_input(self):
  467. headers = {
  468. "Authorization": "token aaabbbcccddd",
  469. }
  470. # Remove the board
  471. data = {"name": ["dev"]}
  472. output = self.app.post(
  473. "/api/0/test/boards/delete", headers=headers, data=data
  474. )
  475. self.assertEqual(output.status_code, 200)
  476. data = json.loads(output.get_data(as_text=True))
  477. self.assertDictEqual(
  478. data, {"boards": []},
  479. )
  480. def test_api_board_api_board_status_no_data(self):
  481. headers = {
  482. "Authorization": "token aaabbbcccddd",
  483. "Content-Type": "application/json",
  484. }
  485. data = json.dumps({})
  486. output = self.app.post(
  487. "/api/0/test/boards/dev/status", headers=headers, data=data
  488. )
  489. self.assertEqual(output.status_code, 400)
  490. data = json.loads(output.get_data(as_text=True))
  491. self.assertDictEqual(
  492. data,
  493. {
  494. "error": "Invalid or incomplete input submitted",
  495. "error_code": "EINVALIDREQ",
  496. "errors": "No (JSON) data provided",
  497. },
  498. )
  499. def test_api_board_api_board_status_invalid_tag_name(self):
  500. headers = {
  501. "Authorization": "token aaabbbcccddd",
  502. "Content-Type": "application/json",
  503. }
  504. data = json.dumps(
  505. {
  506. "-Triaged": {
  507. "close": False,
  508. "close_status": "",
  509. "bg_color": "#ca0dcd",
  510. "default": True,
  511. "rank": 1,
  512. }
  513. }
  514. )
  515. output = self.app.post(
  516. "/api/0/test/boards/dev/status", headers=headers, data=data
  517. )
  518. self.assertEqual(output.status_code, 400)
  519. data = json.loads(output.get_data(as_text=True))
  520. self.assertDictEqual(
  521. data,
  522. {
  523. "error": "Invalid or incomplete input submitted",
  524. "error_code": "EINVALIDREQ",
  525. "errors": {
  526. "name": [
  527. "Invalid status name provided, it should match: "
  528. "^[a-zA-Z0-9][a-zA-Z0-9-_ .:]+$."
  529. ]
  530. },
  531. },
  532. )
  533. def test_api_board_api_board_status_missing_rank(self):
  534. headers = {
  535. "Authorization": "token aaabbbcccddd",
  536. "Content-Type": "application/json",
  537. }
  538. data = json.dumps(
  539. {
  540. "Triaged": {
  541. "close": False,
  542. "close_status": "",
  543. "bg_color": "#ca0dcd",
  544. "default": True,
  545. }
  546. }
  547. )
  548. output = self.app.post(
  549. "/api/0/test/boards/dev/status", headers=headers, data=data
  550. )
  551. self.assertEqual(output.status_code, 400)
  552. data = json.loads(output.get_data(as_text=True))
  553. self.assertDictEqual(
  554. data,
  555. {
  556. "error": "Invalid or incomplete input submitted",
  557. "error_code": "EINVALIDREQ",
  558. "errors": "The 'rank' and 'default' fields are mandatory.",
  559. },
  560. )
  561. def test_api_board_api_board_status_missing_default(self):
  562. headers = {
  563. "Authorization": "token aaabbbcccddd",
  564. "Content-Type": "application/json",
  565. }
  566. data = json.dumps(
  567. {
  568. "Triaged": {
  569. "close": False,
  570. "close_status": "",
  571. "bg_color": "#ca0dcd",
  572. "rank": 1,
  573. }
  574. }
  575. )
  576. output = self.app.post(
  577. "/api/0/test/boards/dev/status", headers=headers, data=data
  578. )
  579. self.assertEqual(output.status_code, 400)
  580. data = json.loads(output.get_data(as_text=True))
  581. self.assertDictEqual(
  582. data,
  583. {
  584. "error": "Invalid or incomplete input submitted",
  585. "error_code": "EINVALIDREQ",
  586. "errors": "The 'rank' and 'default' fields are mandatory.",
  587. },
  588. )
  589. def test_api_board_api_board_status_no_default(self):
  590. headers = {
  591. "Authorization": "token aaabbbcccddd",
  592. "Content-Type": "application/json",
  593. }
  594. data = json.dumps(
  595. {
  596. "Triaged": {
  597. "close": False,
  598. "close_status": "",
  599. "bg_color": "#ca0dcd",
  600. "default": False,
  601. "rank": 1,
  602. }
  603. }
  604. )
  605. output = self.app.post(
  606. "/api/0/test/boards/dev/status", headers=headers, data=data
  607. )
  608. self.assertEqual(output.status_code, 400)
  609. data = json.loads(output.get_data(as_text=True))
  610. self.assertDictEqual(
  611. data,
  612. {
  613. "error": "Invalid or incomplete input submitted",
  614. "error_code": "EINVALIDREQ",
  615. "errors": "There must be one and only one default.",
  616. },
  617. )
  618. def test_api_board_api_board_status_multiple_default(self):
  619. headers = {
  620. "Authorization": "token aaabbbcccddd",
  621. "Content-Type": "application/json",
  622. }
  623. data = json.dumps(
  624. {
  625. "Backlog": {
  626. "close": False,
  627. "close_status": "",
  628. "bg_color": "#FFB300",
  629. "default": True,
  630. "rank": 1,
  631. },
  632. "Triaged": {
  633. "close": False,
  634. "close_status": "",
  635. "bg_color": "#ca0dcd",
  636. "default": True,
  637. "rank": 1,
  638. },
  639. }
  640. )
  641. output = self.app.post(
  642. "/api/0/test/boards/dev/status", headers=headers, data=data
  643. )
  644. self.assertEqual(output.status_code, 400)
  645. data = json.loads(output.get_data(as_text=True))
  646. self.assertDictEqual(
  647. data,
  648. {
  649. "error": "Invalid or incomplete input submitted",
  650. "error_code": "EINVALIDREQ",
  651. "errors": "There must be one and only one default.",
  652. },
  653. )
  654. def test_api_board_api_board_status(self):
  655. headers = {
  656. "Authorization": "token aaabbbcccddd",
  657. "Content-Type": "application/json",
  658. }
  659. data = json.dumps(
  660. {
  661. "Backlog": {
  662. "close": False,
  663. "close_status": "",
  664. "bg_color": "#FFB300",
  665. "default": True,
  666. "rank": 1,
  667. },
  668. "Triaged": {
  669. "close": False,
  670. "close_status": "",
  671. "bg_color": "#ca0dcd",
  672. "default": False,
  673. "rank": 2,
  674. },
  675. "Done": {
  676. "close": True,
  677. "close_status": "Fixed",
  678. "bg_color": "#34d240",
  679. "default": False,
  680. "rank": 4,
  681. },
  682. " ": {
  683. "close": True,
  684. "close_status": "Fixed",
  685. "bg_color": "#34d240",
  686. "default": False,
  687. "rank": 5,
  688. },
  689. }
  690. )
  691. output = self.app.post(
  692. "/api/0/test/boards/dev/status", headers=headers, data=data
  693. )
  694. self.assertEqual(output.status_code, 200)
  695. data = json.loads(output.get_data(as_text=True))
  696. self.assertDictEqual(
  697. data,
  698. {
  699. "board": {
  700. "active": True,
  701. "name": "dev",
  702. "status": [
  703. {
  704. "bg_color": "#FFB300",
  705. "close": False,
  706. "close_status": None,
  707. "default": True,
  708. "name": "Backlog",
  709. },
  710. {
  711. "bg_color": "#ca0dcd",
  712. "close": False,
  713. "close_status": None,
  714. "default": False,
  715. "name": "Triaged",
  716. },
  717. {
  718. "name": "Done",
  719. "close": True,
  720. "close_status": "Fixed",
  721. "default": False,
  722. "bg_color": "#34d240",
  723. },
  724. ],
  725. "tag": {
  726. "tag": "dev",
  727. "tag_color": "DeepBlueSky",
  728. "tag_description": "",
  729. },
  730. }
  731. },
  732. )
  733. def test_api_board_api_board_status_no_close_status(self):
  734. headers = {
  735. "Authorization": "token aaabbbcccddd",
  736. "Content-Type": "application/json",
  737. }
  738. data = json.dumps(
  739. {
  740. "Backlog": {
  741. "close": False,
  742. "close_status": None,
  743. "bg_color": "#FFB300",
  744. "default": True,
  745. "rank": 1,
  746. },
  747. "Triaged": {
  748. "close": False,
  749. "close_status": None,
  750. "bg_color": "#ca0dcd",
  751. "default": False,
  752. "rank": 2,
  753. },
  754. "Done": {
  755. "close": True,
  756. "close_status": None,
  757. "bg_color": "#34d240",
  758. "default": False,
  759. "rank": 4,
  760. },
  761. " ": {
  762. "close": True,
  763. "close_status": None,
  764. "bg_color": "#34d240",
  765. "default": False,
  766. "rank": 5,
  767. },
  768. }
  769. )
  770. output = self.app.post(
  771. "/api/0/test/boards/dev/status", headers=headers, data=data
  772. )
  773. self.assertEqual(output.status_code, 200)
  774. data = json.loads(output.get_data(as_text=True))
  775. self.assertDictEqual(
  776. data,
  777. {
  778. "board": {
  779. "active": True,
  780. "name": "dev",
  781. "status": [
  782. {
  783. "bg_color": "#FFB300",
  784. "close": False,
  785. "close_status": None,
  786. "default": True,
  787. "name": "Backlog",
  788. },
  789. {
  790. "bg_color": "#ca0dcd",
  791. "close": False,
  792. "close_status": None,
  793. "default": False,
  794. "name": "Triaged",
  795. },
  796. {
  797. "name": "Done",
  798. "close": True,
  799. "close_status": None,
  800. "default": False,
  801. "bg_color": "#34d240",
  802. },
  803. ],
  804. "tag": {
  805. "tag": "dev",
  806. "tag_color": "DeepBlueSky",
  807. "tag_description": "",
  808. },
  809. }
  810. },
  811. )
  812. def test_api_board_api_board_status_adding_removing(self):
  813. headers = {
  814. "Authorization": "token aaabbbcccddd",
  815. "Content-Type": "application/json",
  816. }
  817. data = json.dumps(
  818. {
  819. "Backlog": {
  820. "close": False,
  821. "close_status": "",
  822. "bg_color": "#FFB300",
  823. "default": True,
  824. "rank": 1,
  825. },
  826. "Triaged": {
  827. "close": False,
  828. "close_status": "",
  829. "bg_color": "#ca0dcd",
  830. "default": False,
  831. "rank": 2,
  832. },
  833. "Done": {
  834. "close": True,
  835. "close_status": "Fixed",
  836. "bg_color": "#34d240",
  837. "default": False,
  838. "rank": 4,
  839. },
  840. " ": {
  841. "close": True,
  842. "close_status": "Fixed",
  843. "bg_color": "#34d240",
  844. "default": False,
  845. "rank": 5,
  846. },
  847. }
  848. )
  849. output = self.app.post(
  850. "/api/0/test/boards/dev/status", headers=headers, data=data
  851. )
  852. self.assertEqual(output.status_code, 200)
  853. data = json.loads(output.get_data(as_text=True))
  854. self.assertDictEqual(
  855. data,
  856. {
  857. "board": {
  858. "active": True,
  859. "name": "dev",
  860. "status": [
  861. {
  862. "bg_color": "#FFB300",
  863. "close": False,
  864. "close_status": None,
  865. "default": True,
  866. "name": "Backlog",
  867. },
  868. {
  869. "bg_color": "#ca0dcd",
  870. "close": False,
  871. "close_status": None,
  872. "default": False,
  873. "name": "Triaged",
  874. },
  875. {
  876. "name": "Done",
  877. "close": True,
  878. "close_status": "Fixed",
  879. "default": False,
  880. "bg_color": "#34d240",
  881. },
  882. ],
  883. "tag": {
  884. "tag": "dev",
  885. "tag_color": "DeepBlueSky",
  886. "tag_description": "",
  887. },
  888. }
  889. },
  890. )
  891. data = json.dumps(
  892. {
  893. "Backlog": {
  894. "close": False,
  895. "close_status": "",
  896. "bg_color": "#FFB300",
  897. "default": True,
  898. "rank": 1,
  899. },
  900. "In Progress": {
  901. "close": False,
  902. "close_status": "",
  903. "bg_color": "#ca0eef",
  904. "default": False,
  905. "rank": 2,
  906. },
  907. "Done": {
  908. "close": True,
  909. "close_status": "Fixed",
  910. "bg_color": "#34d240",
  911. "default": False,
  912. "rank": 4,
  913. },
  914. }
  915. )
  916. output = self.app.post(
  917. "/api/0/test/boards/dev/status", headers=headers, data=data
  918. )
  919. self.assertEqual(output.status_code, 200)
  920. data = json.loads(output.get_data(as_text=True))
  921. self.assertDictEqual(
  922. data,
  923. {
  924. "board": {
  925. "active": True,
  926. "name": "dev",
  927. "status": [
  928. {
  929. "bg_color": "#FFB300",
  930. "close": False,
  931. "close_status": None,
  932. "default": True,
  933. "name": "Backlog",
  934. },
  935. {
  936. "bg_color": "#ca0eef",
  937. "close": False,
  938. "close_status": None,
  939. "default": False,
  940. "name": "In Progress",
  941. },
  942. {
  943. "name": "Done",
  944. "close": True,
  945. "close_status": "Fixed",
  946. "default": False,
  947. "bg_color": "#34d240",
  948. },
  949. ],
  950. "tag": {
  951. "tag": "dev",
  952. "tag_color": "DeepBlueSky",
  953. "tag_description": "",
  954. },
  955. }
  956. },
  957. )
  958. class PagureFlaskApiBoardsWithBoardAndIssuetests(tests.SimplePagureTest):
  959. """ Tests for flask API Boards controller of pagure for the tests
  960. requiring a pre-existing board and issues.
  961. """
  962. maxDiff = None
  963. def setUp(self):
  964. super(PagureFlaskApiBoardsWithBoardAndIssuetests, self).setUp()
  965. set_projects_up(self)
  966. set_up_board(self)
  967. # Set up the ticket repo
  968. tests.create_projects_git(
  969. os.path.join(self.path, "repos", "tickets"), bare=True
  970. )
  971. # Set up some status to the board
  972. headers = {
  973. "Authorization": "token aaabbbcccddd",
  974. "Content-Type": "application/json",
  975. }
  976. data = json.dumps(
  977. {
  978. "Backlog": {
  979. "close": False,
  980. "close_status": "",
  981. "bg_color": "#FFB300",
  982. "default": True,
  983. "rank": 1,
  984. },
  985. "In Progress": {
  986. "close": False,
  987. "close_status": "",
  988. "bg_color": "#ca0eef",
  989. "default": False,
  990. "rank": 2,
  991. },
  992. "Done": {
  993. "close": True,
  994. "close_status": "Fixed",
  995. "bg_color": "#34d240",
  996. "default": False,
  997. "rank": 4,
  998. },
  999. }
  1000. )
  1001. output = self.app.post(
  1002. "/api/0/test/boards/dev/status", headers=headers, data=data
  1003. )
  1004. self.assertEqual(output.status_code, 200)
  1005. # Create two issues to play with
  1006. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  1007. msg = pagure.lib.query.new_issue(
  1008. session=self.session,
  1009. repo=repo,
  1010. title="Test issue",
  1011. content="We should work on this",
  1012. user="pingou",
  1013. )
  1014. self.session.commit()
  1015. self.assertEqual(msg.title, "Test issue")
  1016. self.assertEqual(repo.open_tickets, 1)
  1017. self.assertEqual(repo.open_tickets_public, 1)
  1018. msg = pagure.lib.query.new_issue(
  1019. session=self.session,
  1020. repo=repo,
  1021. title="Test issue #2",
  1022. content="We should work on this for the second time",
  1023. user="foo",
  1024. status="Open",
  1025. )
  1026. self.session.commit()
  1027. self.assertEqual(msg.title, "Test issue #2")
  1028. self.assertEqual(repo.open_tickets, 2)
  1029. self.assertEqual(repo.open_tickets_public, 2)
  1030. self.tickets_uid = [t.uid for t in repo.issues]
  1031. def test_api_board_ticket_add_status_invalid_board(self):
  1032. headers = {
  1033. "Authorization": "token aaabbbcccddd",
  1034. "Content-Type": "application/json",
  1035. }
  1036. data = json.dumps({"12": {"status": "In Progress", "rank": 2,}})
  1037. output = self.app.post(
  1038. "/api/0/test/boards/invalid/add_issue", headers=headers, data=data
  1039. )
  1040. self.assertEqual(output.status_code, 404)
  1041. data = json.loads(output.get_data(as_text=True))
  1042. self.assertDictEqual(
  1043. data,
  1044. {
  1045. "error": "Invalid or incomplete input submitted",
  1046. "error_code": "EINVALIDREQ",
  1047. "errors": "Board not found",
  1048. },
  1049. )
  1050. def test_api_board_ticket_add_status_no_data(self):
  1051. headers = {
  1052. "Authorization": "token aaabbbcccddd",
  1053. "Content-Type": "application/json",
  1054. }
  1055. data = json.dumps({})
  1056. output = self.app.post(
  1057. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  1058. )
  1059. self.assertEqual(output.status_code, 400)
  1060. data = json.loads(output.get_data(as_text=True))
  1061. self.assertDictEqual(
  1062. data,
  1063. {
  1064. "error": "Invalid or incomplete input submitted",
  1065. "error_code": "EINVALIDREQ",
  1066. "errors": "No (JSON) data provided",
  1067. },
  1068. )
  1069. def test_api_board_ticket_add_status_no_rank(self):
  1070. headers = {
  1071. "Authorization": "token aaabbbcccddd",
  1072. "Content-Type": "application/json",
  1073. }
  1074. data = json.dumps({"12": {"status": "In Progress"}})
  1075. output = self.app.post(
  1076. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  1077. )
  1078. self.assertEqual(output.status_code, 400)
  1079. data = json.loads(output.get_data(as_text=True))
  1080. self.assertDictEqual(
  1081. data,
  1082. {
  1083. "error": "Invalid or incomplete input submitted",
  1084. "error_code": "EINVALIDREQ",
  1085. "errors": "The 'rank' and 'status' fields are mandatory.",
  1086. },
  1087. )
  1088. def test_api_board_ticket_add_status_no_status(self):
  1089. headers = {
  1090. "Authorization": "token aaabbbcccddd",
  1091. "Content-Type": "application/json",
  1092. }
  1093. data = json.dumps({"12": {"rank": 2,}})
  1094. output = self.app.post(
  1095. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  1096. )
  1097. self.assertEqual(output.status_code, 400)
  1098. data = json.loads(output.get_data(as_text=True))
  1099. self.assertDictEqual(
  1100. data,
  1101. {
  1102. "error": "Invalid or incomplete input submitted",
  1103. "error_code": "EINVALIDREQ",
  1104. "errors": "The 'rank' and 'status' fields are mandatory.",
  1105. },
  1106. )
  1107. def test_api_board_ticket_add_status_invalid_ticket_id(self):
  1108. headers = {
  1109. "Authorization": "token aaabbbcccddd",
  1110. "Content-Type": "application/json",
  1111. }
  1112. data = json.dumps({"12": {"status": "In Progress", "rank": 2}})
  1113. output = self.app.post(
  1114. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  1115. )
  1116. self.assertEqual(output.status_code, 400)
  1117. data = json.loads(output.get_data(as_text=True))
  1118. self.assertDictEqual(
  1119. data,
  1120. {
  1121. "error": "No ticket found with this identifier",
  1122. "error_code": "ENOCODE",
  1123. },
  1124. )
  1125. def test_api_board_ticket_add_status(self):
  1126. headers = {
  1127. "Authorization": "token aaabbbcccddd",
  1128. "Content-Type": "application/json",
  1129. }
  1130. data = json.dumps(
  1131. {
  1132. "2": {"status": "In Progress", "rank": 2},
  1133. " ": {"status": "In Progress", "rank": 4},
  1134. }
  1135. )
  1136. output = self.app.post(
  1137. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  1138. )
  1139. self.assertEqual(output.status_code, 200)
  1140. data = json.loads(output.get_data(as_text=True))
  1141. self.assertDictEqual(
  1142. data,
  1143. {
  1144. "board": {
  1145. "active": True,
  1146. "name": "dev",
  1147. "status": [
  1148. {
  1149. "bg_color": "#FFB300",
  1150. "close": False,
  1151. "close_status": None,
  1152. "default": True,
  1153. "name": "Backlog",
  1154. },
  1155. {
  1156. "bg_color": "#ca0eef",
  1157. "close": False,
  1158. "close_status": None,
  1159. "default": False,
  1160. "name": "In Progress",
  1161. },
  1162. {
  1163. "bg_color": "#34d240",
  1164. "close": True,
  1165. "close_status": "Fixed",
  1166. "default": False,
  1167. "name": "Done",
  1168. },
  1169. ],
  1170. "tag": {
  1171. "tag": "dev",
  1172. "tag_color": "DeepBlueSky",
  1173. "tag_description": "",
  1174. },
  1175. }
  1176. },
  1177. )
  1178. def test_api_board_ticket_update_status_invalid_board(self):
  1179. headers = {
  1180. "Authorization": "token aaabbbcccddd",
  1181. "Content-Type": "application/json",
  1182. }
  1183. data = json.dumps({"12": {"status": "In Progress", "rank": 2,}})
  1184. output = self.app.post(
  1185. "/api/0/test/boards/invalid/update_issue",
  1186. headers=headers,
  1187. data=data,
  1188. )
  1189. self.assertEqual(output.status_code, 404)
  1190. data = json.loads(output.get_data(as_text=True))
  1191. self.assertDictEqual(
  1192. data,
  1193. {
  1194. "error": "Invalid or incomplete input submitted",
  1195. "error_code": "EINVALIDREQ",
  1196. "errors": "Board not found",
  1197. },
  1198. )
  1199. def test_api_board_ticket_update_status_no_data(self):
  1200. headers = {
  1201. "Authorization": "token aaabbbcccddd",
  1202. "Content-Type": "application/json",
  1203. }
  1204. data = json.dumps({})
  1205. output = self.app.post(
  1206. "/api/0/test/boards/dev/update_issue", headers=headers, data=data
  1207. )
  1208. self.assertEqual(output.status_code, 400)
  1209. data = json.loads(output.get_data(as_text=True))
  1210. self.assertDictEqual(
  1211. data,
  1212. {
  1213. "error": "Invalid or incomplete input submitted",
  1214. "error_code": "EINVALIDREQ",
  1215. "errors": "No (JSON) data provided",
  1216. },
  1217. )
  1218. def test_api_board_ticket_update_status_no_rank(self):
  1219. headers = {
  1220. "Authorization": "token aaabbbcccddd",
  1221. "Content-Type": "application/json",
  1222. }
  1223. data = json.dumps({"12": {"status": "In Progress"}})
  1224. output = self.app.post(
  1225. "/api/0/test/boards/dev/update_issue", headers=headers, data=data
  1226. )
  1227. self.assertEqual(output.status_code, 400)
  1228. data = json.loads(output.get_data(as_text=True))
  1229. self.assertDictEqual(
  1230. data,
  1231. {
  1232. "error": "Invalid or incomplete input submitted",
  1233. "error_code": "EINVALIDREQ",
  1234. "errors": "The 'rank' and 'status' fields are mandatory.",
  1235. },
  1236. )
  1237. def test_api_board_ticket_update_status_no_status(self):
  1238. headers = {
  1239. "Authorization": "token aaabbbcccddd",
  1240. "Content-Type": "application/json",
  1241. }
  1242. data = json.dumps({"12": {"rank": 2,}})
  1243. output = self.app.post(
  1244. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  1245. )
  1246. self.assertEqual(output.status_code, 400)
  1247. data = json.loads(output.get_data(as_text=True))
  1248. self.assertDictEqual(
  1249. data,
  1250. {
  1251. "error": "Invalid or incomplete input submitted",
  1252. "error_code": "EINVALIDREQ",
  1253. "errors": "The 'rank' and 'status' fields are mandatory.",
  1254. },
  1255. )
  1256. def test_api_board_ticket_update_status_invalid_ticket_id(self):
  1257. headers = {
  1258. "Authorization": "token aaabbbcccddd",
  1259. "Content-Type": "application/json",
  1260. }
  1261. data = json.dumps({"12": {"status": "In Progress", "rank": 2}})
  1262. output = self.app.post(
  1263. "/api/0/test/boards/dev/update_issue", headers=headers, data=data
  1264. )
  1265. self.assertEqual(output.status_code, 400)
  1266. data = json.loads(output.get_data(as_text=True))
  1267. self.assertDictEqual(
  1268. data,
  1269. {
  1270. "error": "No ticket found with this identifier",
  1271. "error_code": "ENOCODE",
  1272. },
  1273. )
  1274. def test_api_board_ticket_update_status(self):
  1275. headers = {
  1276. "Authorization": "token aaabbbcccddd",
  1277. "Content-Type": "application/json",
  1278. }
  1279. data = json.dumps(
  1280. {
  1281. self.tickets_uid[1]: {"status": "In Progress", "rank": 2},
  1282. " ": {"status": "In Progress", "rank": 4},
  1283. }
  1284. )
  1285. output = self.app.post(
  1286. "/api/0/test/boards/dev/update_issue", headers=headers, data=data
  1287. )
  1288. self.assertEqual(output.status_code, 200)
  1289. data = json.loads(output.get_data(as_text=True))
  1290. self.assertDictEqual(
  1291. data,
  1292. {
  1293. "board": {
  1294. "active": True,
  1295. "name": "dev",
  1296. "status": [
  1297. {
  1298. "bg_color": "#FFB300",
  1299. "close": False,
  1300. "close_status": None,
  1301. "default": True,
  1302. "name": "Backlog",
  1303. },
  1304. {
  1305. "bg_color": "#ca0eef",
  1306. "close": False,
  1307. "close_status": None,
  1308. "default": False,
  1309. "name": "In Progress",
  1310. },
  1311. {
  1312. "bg_color": "#34d240",
  1313. "close": True,
  1314. "close_status": "Fixed",
  1315. "default": False,
  1316. "name": "Done",
  1317. },
  1318. ],
  1319. "tag": {
  1320. "tag": "dev",
  1321. "tag_color": "DeepBlueSky",
  1322. "tag_description": "",
  1323. },
  1324. }
  1325. },
  1326. )
  1327. def test_api_board_ticket_update_status_close_re_opend(self):
  1328. headers = {
  1329. "Authorization": "token aaabbbcccddd",
  1330. "Content-Type": "application/json",
  1331. }
  1332. data = json.dumps(
  1333. {self.tickets_uid[1]: {"status": "Done", "rank": 2},}
  1334. )
  1335. output = self.app.post(
  1336. "/api/0/test/boards/dev/update_issue", headers=headers, data=data
  1337. )
  1338. self.assertEqual(output.status_code, 200)
  1339. data = json.loads(output.get_data(as_text=True))
  1340. self.session = pagure.lib.query.create_session(self.dbpath)
  1341. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  1342. self.assertEqual(repo.issues[1].status, "Closed")
  1343. self.assertEqual(repo.issues[1].close_status, "Fixed")
  1344. data = json.dumps(
  1345. {self.tickets_uid[1]: {"status": "In Progress", "rank": 2},}
  1346. )
  1347. output = self.app.post(
  1348. "/api/0/test/boards/dev/update_issue", headers=headers, data=data
  1349. )
  1350. self.assertEqual(output.status_code, 200)
  1351. data = json.loads(output.get_data(as_text=True))
  1352. self.session = pagure.lib.query.create_session(self.dbpath)
  1353. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  1354. self.assertEqual(repo.issues[0].status, "Open")
  1355. self.assertEqual(repo.issues[1].status, "Open")
  1356. self.assertEqual(repo.issues[1].close_status, None)
  1357. @patch("pagure.lib.notify.send_email", new=MagicMock(return_value=True))
  1358. def test_ticket_representation_in_git(self):
  1359. headers = {
  1360. "Authorization": "token aaabbbcccddd",
  1361. "Content-Type": "application/json",
  1362. }
  1363. data = json.dumps({"2": {"status": "In Progress", "rank": 2},})
  1364. output = self.app.post(
  1365. "/api/0/test/boards/dev/add_issue", headers=headers, data=data
  1366. )
  1367. self.assertEqual(output.status_code, 200)
  1368. self.session = pagure.lib.query.create_session(self.dbpath)
  1369. repo = pagure.lib.query.get_authorized_project(self.session, "test")
  1370. self.assertEqual(repo.issues[1].status, "Open")
  1371. self.assertEqual(repo.issues[1].close_status, None)
  1372. # Clone the repo so it isn't a bare repo
  1373. pygit2.clone_repository(
  1374. os.path.join(self.path, "repos", "tickets", "test.git"),
  1375. os.path.join(self.path, "repos", "tickets", "test"),
  1376. )
  1377. exp = {
  1378. "assignee": None,
  1379. "blocks": [],
  1380. "boards": [
  1381. {
  1382. "board": {
  1383. "active": True,
  1384. "name": "dev",
  1385. "status": [
  1386. {
  1387. "bg_color": "#FFB300",
  1388. "close": False,
  1389. "close_status": None,
  1390. "default": True,
  1391. "name": "Backlog",
  1392. },
  1393. {
  1394. "bg_color": "#ca0eef",
  1395. "close": False,
  1396. "close_status": None,
  1397. "default": False,
  1398. "name": "In Progress",
  1399. },
  1400. {
  1401. "bg_color": "#34d240",
  1402. "close": True,
  1403. "close_status": "Fixed",
  1404. "default": False,
  1405. "name": "Done",
  1406. },
  1407. ],
  1408. "tag": {
  1409. "tag": "dev",
  1410. "tag_color": "DeepBlueSky",
  1411. "tag_description": "",
  1412. },
  1413. },
  1414. "rank": 2,
  1415. "status": {
  1416. "bg_color": "#ca0eef",
  1417. "close": False,
  1418. "close_status": None,
  1419. "default": False,
  1420. "name": "In Progress",
  1421. },
  1422. }
  1423. ],
  1424. "close_status": None,
  1425. "closed_at": None,
  1426. "closed_by": None,
  1427. "comments": [
  1428. {
  1429. "comment": "Issue tagged with: dev",
  1430. "date_created": "1594654596",
  1431. "edited_on": None,
  1432. "editor": None,
  1433. "id": 1,
  1434. "notification": True,
  1435. "parent": None,
  1436. "reactions": {},
  1437. "user": {
  1438. "default_email": "bar@pingou.com",
  1439. "emails": ["bar@pingou.com", "foo@pingou.com"],
  1440. "fullname": "PY C",
  1441. "name": "pingou",
  1442. "url_path": "user/pingou",
  1443. },
  1444. }
  1445. ],
  1446. "content": "We should work on this for the second time",
  1447. "custom_fields": [],
  1448. "date_created": "1594654596",
  1449. "depends": [],
  1450. "id": 2,
  1451. "last_updated": "1594654596",
  1452. "milestone": None,
  1453. "priority": None,
  1454. "private": False,
  1455. "related_prs": [],
  1456. "status": "Open",
  1457. "tags": ["dev"],
  1458. "title": "Test issue #2",
  1459. "user": {
  1460. "default_email": "foo@bar.com",
  1461. "emails": ["foo@bar.com"],
  1462. "fullname": "foo bar",
  1463. "name": "foo",
  1464. "url_path": "user/foo",
  1465. },
  1466. }
  1467. with open(
  1468. os.path.join(
  1469. self.path, "repos", "tickets", "test", repo.issues[1].uid
  1470. )
  1471. ) as stream:
  1472. data = json.load(stream)
  1473. # Make the date fix
  1474. for idx, com in enumerate(data["comments"]):
  1475. com["date_created"] = "1594654596"
  1476. data["comments"][idx] = com
  1477. data["date_created"] = "1594654596"
  1478. data["last_updated"] = "1594654596"
  1479. self.assertDictEqual(data, exp)
  1480. if __name__ == "__main__":
  1481. unittest.main(verbosity=2)