test_pagure_flask_ui_repo_flag_commit.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2017 - 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 sys
  10. import os
  11. from mock import patch
  12. import pygit2
  13. sys.path.insert(0, os.path.join(os.path.dirname(
  14. os.path.abspath(__file__)), '..'))
  15. import pagure.lib.query
  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.get_data(as_text=True))
  36. self.assertIn(
  37. '#commit-overview-collapse',
  38. output.get_data(as_text=True))
  39. self.assertIn('Merged by Alice Author', output.get_data(as_text=True))
  40. self.assertIn('Committed by Cecil Committer', output.get_data(as_text=True))
  41. def test_view_commit_pending_flag(self):
  42. """ Test the view_commit endpoint with a pending flag. """
  43. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  44. msg = pagure.lib.query.add_commit_flag(
  45. session=self.session,
  46. repo=repo,
  47. commit_hash=self.commit.oid.hex,
  48. username='simple-koji-ci',
  49. status='pending',
  50. percent=None,
  51. comment='Build is running',
  52. url='https://koji.fp.o/koji...',
  53. uid='uid',
  54. user='foo',
  55. token='aaabbbcccddd'
  56. )
  57. self.session.commit()
  58. self.assertEqual(msg, ('Flag added', 'uid'))
  59. # View first commit
  60. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  61. self.assertEqual(output.status_code, 200)
  62. output_text = output.get_data(as_text=True)
  63. self.assertIn(
  64. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  65. output_text)
  66. self.assertIn(
  67. '#commit-overview-collapse',
  68. output_text)
  69. self.assertIn('Merged by Alice Author', output_text)
  70. self.assertIn('Committed by Cecil Committer', output_text)
  71. self.assertIn(
  72. '<span>\n <a '
  73. 'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
  74. '\n </span>', output_text)
  75. self.assertIn(
  76. '<div class="pull-xs-right">\n '
  77. '<span class="badge badge-info">pending</span>'
  78. '\n </div>', output_text)
  79. self.assertIn(
  80. '<span>Build is running</span>', output_text)
  81. def test_view_commit_success_flag(self):
  82. """ Test the view_commit endpoint with a successful flag. """
  83. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  84. msg = pagure.lib.query.add_commit_flag(
  85. session=self.session,
  86. repo=repo,
  87. commit_hash=self.commit.oid.hex,
  88. username='simple-koji-ci',
  89. status='success',
  90. percent=100,
  91. comment='Build passed',
  92. url='https://koji.fp.o/koji...',
  93. uid='uid',
  94. user='foo',
  95. token='aaabbbcccddd'
  96. )
  97. self.session.commit()
  98. self.assertEqual(msg, ('Flag added', 'uid'))
  99. # View first commit
  100. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  101. self.assertEqual(output.status_code, 200)
  102. output_text = output.get_data(as_text=True)
  103. self.assertIn(
  104. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  105. output_text)
  106. self.assertIn(
  107. '#commit-overview-collapse',
  108. output_text)
  109. self.assertIn('Merged by Alice Author', output_text)
  110. self.assertIn('Committed by Cecil Committer', output_text)
  111. self.assertIn(
  112. '<span>\n <a '
  113. 'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
  114. '\n </span>', output_text)
  115. self.assertIn(
  116. '<div class="pull-xs-right">\n '
  117. '<span class="badge badge-success">success (100%)</span>'
  118. '\n </div>', output_text)
  119. self.assertIn(
  120. '<span>Build passed</span>', output_text)
  121. def test_view_commit_error_flag(self):
  122. """ Test the view_commit endpoint with a error flag. """
  123. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  124. msg = pagure.lib.query.add_commit_flag(
  125. session=self.session,
  126. repo=repo,
  127. commit_hash=self.commit.oid.hex,
  128. username='simple-koji-ci',
  129. status='error',
  130. percent=None,
  131. comment='Build errored',
  132. url='https://koji.fp.o/koji...',
  133. uid='uid',
  134. user='foo',
  135. token='aaabbbcccddd'
  136. )
  137. self.session.commit()
  138. self.assertEqual(msg, ('Flag added', 'uid'))
  139. # View first commit
  140. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  141. self.assertEqual(output.status_code, 200)
  142. output_text = output.get_data(as_text=True)
  143. self.assertIn(
  144. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  145. output_text)
  146. self.assertIn(
  147. '#commit-overview-collapse',
  148. output_text)
  149. self.assertIn('Merged by Alice Author', output_text)
  150. self.assertIn('Committed by Cecil Committer', output_text)
  151. self.assertIn(
  152. '<span>\n <a '
  153. 'href="https://koji.fp.o/koji...">simple-koji-ci</a>'
  154. '\n </span>', output_text)
  155. self.assertIn(
  156. '<div class="pull-xs-right">\n '
  157. '<span class="badge badge-danger">error</span>'
  158. '\n </div>', output_text)
  159. self.assertIn(
  160. '<span>Build errored</span>', output_text)
  161. def test_view_commit_failure_flag(self):
  162. """ Test the view_commit endpoint with a failure flag. """
  163. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  164. msg = pagure.lib.query.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. output_text = output.get_data(as_text=True)
  183. self.assertIn(
  184. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  185. output_text)
  186. self.assertIn(
  187. '#commit-overview-collapse',
  188. output_text)
  189. self.assertIn('Merged by Alice Author', output_text)
  190. self.assertIn('Committed by Cecil Committer', output_text)
  191. self.assertIn(
  192. '<span>\n <a href="https://koji.fp.o/koji...">'
  193. 'simple-koji-ci</a>\n </span>', output_text)
  194. self.assertIn(
  195. '<div class="pull-xs-right">\n '
  196. '<span class="badge badge-danger">failure</span>'
  197. '\n </div>', output_text)
  198. self.assertIn(
  199. '<span>Build failed</span>', output_text)
  200. def test_view_commit_canceled_flag(self):
  201. """ Test the view_commit endpoint with a canceled flag. """
  202. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  203. msg = pagure.lib.query.add_commit_flag(
  204. session=self.session,
  205. repo=repo,
  206. commit_hash=self.commit.oid.hex,
  207. username='simple-koji-ci',
  208. status='canceled',
  209. percent=None,
  210. comment='Build canceled',
  211. url='https://koji.fp.o/koji...',
  212. uid='uid',
  213. user='foo',
  214. token='aaabbbcccddd'
  215. )
  216. self.session.commit()
  217. self.assertEqual(msg, ('Flag added', 'uid'))
  218. # View first commit
  219. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  220. self.assertEqual(output.status_code, 200)
  221. output_text = output.get_data(as_text=True)
  222. self.assertIn(
  223. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  224. output_text)
  225. self.assertIn(
  226. '#commit-overview-collapse',
  227. output_text)
  228. self.assertIn('Merged by Alice Author', output_text)
  229. self.assertIn('Committed by Cecil Committer', output_text)
  230. self.assertIn(
  231. '<span>\n <a href="https://koji.fp.o/koji...">'
  232. 'simple-koji-ci</a>\n </span>', output_text)
  233. self.assertIn(
  234. '<div class="pull-xs-right">\n '
  235. '<span class="badge badge-warning">canceled</span>'
  236. '\n </div>', output_text)
  237. self.assertIn(
  238. '<span>Build canceled</span>', output_text)
  239. @patch.dict('pagure.config.config',
  240. {
  241. 'FLAG_STATUSES_LABELS':
  242. {
  243. 'status1': 'badge-warning',
  244. 'otherstatus': 'badge-success',
  245. },
  246. })
  247. def test_view_commit_with_custom_flags(self):
  248. """ Test the view_commit endpoint while having custom flags. """
  249. repo = pagure.lib.query.get_authorized_project(self.session, 'test')
  250. msg = pagure.lib.query.add_commit_flag(
  251. session=self.session,
  252. repo=repo,
  253. commit_hash=self.commit.oid.hex,
  254. username='simple-koji-ci',
  255. status='status1',
  256. percent=None,
  257. comment='Build canceled',
  258. url='https://koji.fp.o/koji...',
  259. uid='uid',
  260. user='foo',
  261. token='aaabbbcccddd'
  262. )
  263. self.session.commit()
  264. self.assertEqual(msg, ('Flag added', 'uid'))
  265. # View first commit
  266. output = self.app.get('/test/c/%s' % self.commit.oid.hex)
  267. self.assertEqual(output.status_code, 200)
  268. output_text = output.get_data(as_text=True)
  269. self.assertIn(
  270. '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
  271. output_text)
  272. self.assertIn(
  273. '#commit-overview-collapse',
  274. output_text)
  275. self.assertIn('Merged by Alice Author', output_text)
  276. self.assertIn('Committed by Cecil Committer', output_text)
  277. self.assertIn(
  278. '<span>\n <a href="https://koji.fp.o/koji...">'
  279. 'simple-koji-ci</a>\n </span>', output_text)
  280. self.assertIn(
  281. '<div class="pull-xs-right">\n '
  282. '<span class="badge badge-warning">status1</span>'
  283. '\n </div>', output_text)
  284. self.assertIn(
  285. '<span>Build canceled</span>', output_text)
  286. if __name__ == '__main__':
  287. unittest.main(verbosity=2)