test_pagure_flask_ui_repo_flag_commit.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2017 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. import unittest
  8. import sys
  9. import os
  10. from mock import patch
  11. import pygit2
  12. sys.path.insert(0, os.path.join(os.path.dirname(
  13. os.path.abspath(__file__)), '..'))
  14. import pagure
  15. import pagure.lib
  16. import tests
  17. class ViewCommitFlagtests(tests.SimplePagureTest):
  18. """ Tests for the UI related to commit flags """
  19. def setUp(self):
  20. """ Set up the environnment, ran before every tests. """
  21. super(ViewCommitFlagtests, self).setUp()
  22. tests.create_projects(self.session)
  23. tests.create_tokens(self.session)
  24. # Add a README to the git repo - First commit
  25. tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
  26. repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
  27. self.commit = repo.revparse_single('HEAD')
  28. def test_view_commit_no_flag(self):
  29. """ Test the view_commit endpoint. """
  30. # View first commit
  31. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  32. self.assertEqual(output.status_code, 200)
  33. self.assertIn(
  34. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  35. output.data)
  36. self.assertIn(
  37. '<div class="list-group" id="diff_list" style="display:none;">',
  38. output.data)
  39. self.assertIn(' Merged by Alice Author\n', output.data)
  40. self.assertIn(' Committed by Cecil Committer\n', output.data)
  41. self.assertIn('''<section class="list-group" id="flag_list">
  42. <div class="card" id="pr_flags">
  43. <ul class="list-group list-group-flush">
  44. </ul>
  45. </div>
  46. </section>''', output.data)
  47. def test_view_commit_pending_flag(self):
  48. """ Test the view_commit endpoint with a pending flag. """
  49. repo = pagure.lib.get_authorized_project(self.session, 'test')
  50. msg = pagure.lib.add_commit_flag(
  51. session=self.session,
  52. repo=repo,
  53. commit_hash=self.commit.oid.hex,
  54. username='simple-koji-ci',
  55. status='pending',
  56. percent=None,
  57. comment='Build is running',
  58. url='https://koji.fp.o/koji...',
  59. uid='uid',
  60. user='foo',
  61. token='aaabbbcccddd'
  62. )
  63. self.session.commit()
  64. self.assertEqual(msg, ('Flag added', 'uid'))
  65. # View first commit
  66. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  67. self.assertEqual(output.status_code, 200)
  68. self.assertIn(
  69. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  70. output.data)
  71. self.assertIn(
  72. '<div class="list-group" id="diff_list" style="display:none;">',
  73. output.data)
  74. self.assertIn(' Merged by Alice Author\n', output.data)
  75. self.assertIn(' Committed by Cecil Committer\n', output.data)
  76. self.assertIn(
  77. '<span>\n <a href="https://koji.fp.o/koji...">'
  78. 'simple-koji-ci</a>\n </span>', output.data)
  79. self.assertIn(
  80. '<div class="pull-xs-right">\n '
  81. '<span class="label label-info">pending'
  82. '</span>\n </div>', output.data)
  83. self.assertIn(
  84. '<span>Build is running</span>', output.data)
  85. def test_view_commit_success_flag(self):
  86. """ Test the view_commit endpoint with a successful flag. """
  87. repo = pagure.lib.get_authorized_project(self.session, 'test')
  88. msg = pagure.lib.add_commit_flag(
  89. session=self.session,
  90. repo=repo,
  91. commit_hash=self.commit.oid.hex,
  92. username='simple-koji-ci',
  93. status='success',
  94. percent=100,
  95. comment='Build passed',
  96. url='https://koji.fp.o/koji...',
  97. uid='uid',
  98. user='foo',
  99. token='aaabbbcccddd'
  100. )
  101. self.session.commit()
  102. self.assertEqual(msg, ('Flag added', 'uid'))
  103. # View first commit
  104. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  105. self.assertEqual(output.status_code, 200)
  106. self.assertIn(
  107. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  108. output.data)
  109. self.assertIn(
  110. '<div class="list-group" id="diff_list" style="display:none;">',
  111. output.data)
  112. self.assertIn(' Merged by Alice Author\n', output.data)
  113. self.assertIn(' Committed by Cecil Committer\n', output.data)
  114. self.assertIn(
  115. '<span>\n <a href="https://koji.fp.o/koji...">'
  116. 'simple-koji-ci</a>\n </span>', output.data)
  117. self.assertIn(
  118. '<div class="pull-xs-right">\n '
  119. '<span class="label label-success">success (100%)'
  120. '</span>\n </div>', output.data)
  121. self.assertIn(
  122. '<span>Build passed</span>', output.data)
  123. def test_view_commit_error_flag(self):
  124. """ Test the view_commit endpoint with a error flag. """
  125. repo = pagure.lib.get_authorized_project(self.session, 'test')
  126. msg = pagure.lib.add_commit_flag(
  127. session=self.session,
  128. repo=repo,
  129. commit_hash=self.commit.oid.hex,
  130. username='simple-koji-ci',
  131. status='error',
  132. percent=None,
  133. comment='Build errored',
  134. url='https://koji.fp.o/koji...',
  135. uid='uid',
  136. user='foo',
  137. token='aaabbbcccddd'
  138. )
  139. self.session.commit()
  140. self.assertEqual(msg, ('Flag added', 'uid'))
  141. # View first commit
  142. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  143. self.assertEqual(output.status_code, 200)
  144. self.assertIn(
  145. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  146. output.data)
  147. self.assertIn(
  148. '<div class="list-group" id="diff_list" style="display:none;">',
  149. output.data)
  150. self.assertIn(' Merged by Alice Author\n', output.data)
  151. self.assertIn(' Committed by Cecil Committer\n', output.data)
  152. self.assertIn(
  153. '<span>\n <a href="https://koji.fp.o/koji...">'
  154. 'simple-koji-ci</a>\n </span>', output.data)
  155. self.assertIn(
  156. '<div class="pull-xs-right">\n '
  157. '<span class="label label-danger">error'
  158. '</span>\n </div>', output.data)
  159. self.assertIn(
  160. '<span>Build errored</span>', output.data)
  161. def test_view_commit_failure_flag(self):
  162. """ Test the view_commit endpoint with a failure flag. """
  163. repo = pagure.lib.get_authorized_project(self.session, 'test')
  164. msg = pagure.lib.add_commit_flag(
  165. session=self.session,
  166. repo=repo,
  167. commit_hash=self.commit.oid.hex,
  168. username='simple-koji-ci',
  169. status='failure',
  170. percent=None,
  171. comment='Build failed',
  172. url='https://koji.fp.o/koji...',
  173. uid='uid',
  174. user='foo',
  175. token='aaabbbcccddd'
  176. )
  177. self.session.commit()
  178. self.assertEqual(msg, ('Flag added', 'uid'))
  179. # View first commit
  180. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  181. self.assertEqual(output.status_code, 200)
  182. self.assertIn(
  183. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  184. output.data)
  185. self.assertIn(
  186. '<div class="list-group" id="diff_list" style="display:none;">',
  187. output.data)
  188. self.assertIn(' Merged by Alice Author\n', output.data)
  189. self.assertIn(' Committed by Cecil Committer\n', output.data)
  190. self.assertIn(
  191. '<span>\n <a href="https://koji.fp.o/koji...">'
  192. 'simple-koji-ci</a>\n </span>', output.data)
  193. self.assertIn(
  194. '<div class="pull-xs-right">\n '
  195. '<span class="label label-danger">failure'
  196. '</span>\n </div>', output.data)
  197. self.assertIn(
  198. '<span>Build failed</span>', output.data)
  199. def test_view_commit_canceled_flag(self):
  200. """ Test the view_commit endpoint with a canceled flag. """
  201. repo = pagure.lib.get_authorized_project(self.session, 'test')
  202. msg = pagure.lib.add_commit_flag(
  203. session=self.session,
  204. repo=repo,
  205. commit_hash=self.commit.oid.hex,
  206. username='simple-koji-ci',
  207. status='canceled',
  208. percent=None,
  209. comment='Build canceled',
  210. url='https://koji.fp.o/koji...',
  211. uid='uid',
  212. user='foo',
  213. token='aaabbbcccddd'
  214. )
  215. self.session.commit()
  216. self.assertEqual(msg, ('Flag added', 'uid'))
  217. # View first commit
  218. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  219. self.assertEqual(output.status_code, 200)
  220. self.assertIn(
  221. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  222. output.data)
  223. self.assertIn(
  224. '<div class="list-group" id="diff_list" style="display:none;">',
  225. output.data)
  226. self.assertIn(' Merged by Alice Author\n', output.data)
  227. self.assertIn(' Committed by Cecil Committer\n', output.data)
  228. self.assertIn(
  229. '<span>\n <a href="https://koji.fp.o/koji...">'
  230. 'simple-koji-ci</a>\n </span>', output.data)
  231. self.assertIn(
  232. '<div class="pull-xs-right">\n '
  233. '<span class="label label-warning">canceled'
  234. '</span>\n </div>', output.data)
  235. self.assertIn(
  236. '<span>Build canceled</span>', output.data)
  237. @patch.dict('pagure.config.config',
  238. {
  239. 'FLAG_STATUSES_LABELS':
  240. {
  241. 'status1': 'label-warning',
  242. 'otherstatus': 'label-success',
  243. },
  244. })
  245. def test_view_commit_with_custom_flags(self):
  246. """ Test the view_commit endpoint while having custom flags. """
  247. repo = pagure.lib.get_authorized_project(self.session, 'test')
  248. msg = pagure.lib.add_commit_flag(
  249. session=self.session,
  250. repo=repo,
  251. commit_hash=self.commit.oid.hex,
  252. username='simple-koji-ci',
  253. status='status1',
  254. percent=None,
  255. comment='Build canceled',
  256. url='https://koji.fp.o/koji...',
  257. uid='uid',
  258. user='foo',
  259. token='aaabbbcccddd'
  260. )
  261. self.session.commit()
  262. self.assertEqual(msg, ('Flag added', 'uid'))
  263. # View first commit
  264. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  265. self.assertEqual(output.status_code, 200)
  266. self.assertIn(
  267. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  268. output.data)
  269. self.assertIn(
  270. '<div class="list-group" id="diff_list" style="display:none;">',
  271. output.data)
  272. self.assertIn(' Merged by Alice Author\n', output.data)
  273. self.assertIn(' Committed by Cecil Committer\n', output.data)
  274. self.assertIn(
  275. '<span>\n <a href="https://koji.fp.o/koji...">'
  276. 'simple-koji-ci</a>\n </span>', output.data)
  277. self.assertIn(
  278. '<div class="pull-xs-right">\n '
  279. '<span class="label label-warning">status1'
  280. '</span>\n </div>', output.data)
  281. self.assertIn(
  282. '<span>Build canceled</span>', output.data)
  283. if __name__ == '__main__':
  284. unittest.main(verbosity=2)