1
0

test_pagure_flask_ui_plugins_unsigned.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2016-2018 - 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. sys.path.insert(0, os.path.join(os.path.dirname(
  12. os.path.abspath(__file__)), '..'))
  13. import tests
  14. class PagureFlaskPluginUnsignedtests(tests.SimplePagureTest):
  15. """ Tests for Block pushes with unsigned commit plugin of pagure """
  16. def test_plugin_unsigned(self):
  17. """ Test the noff plugin on/off endpoint. """
  18. tests.create_projects(self.session)
  19. tests.create_projects_git(os.path.join(self.path, 'repos'))
  20. user = tests.FakeUser(username='pingou')
  21. with tests.user_set(self.app.application, user):
  22. output = self.app.get(
  23. '/test/settings/Block Un-Signed commits')
  24. self.assertEqual(output.status_code, 200)
  25. output_text = output.get_data(as_text=True)
  26. self.assertIn(
  27. '<title>Settings Block Un-Signed commits - test - '
  28. 'Pagure</title>', output_text)
  29. self.assertTrue(
  30. '<input class="form-check-input mt-2" id="active" name="active" '
  31. 'type="checkbox" value="y">' in output_text)
  32. csrf_token = output_text.split(
  33. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  34. data = {}
  35. output = self.app.post(
  36. '/test/settings/Block Un-Signed commits', data=data)
  37. self.assertEqual(output.status_code, 200)
  38. output_text = output.get_data(as_text=True)
  39. self.assertIn(
  40. '<title>Settings Block Un-Signed commits - test - '
  41. 'Pagure</title>', output_text)
  42. self.assertTrue(
  43. '<input class="form-check-input mt-2" id="active" name="active" '
  44. 'type="checkbox" value="y">' in output_text)
  45. data['csrf_token'] = csrf_token
  46. # With the git repo
  47. output = self.app.post(
  48. '/test/settings/Block Un-Signed commits',
  49. data=data, follow_redirects=True)
  50. self.assertEqual(output.status_code, 200)
  51. output_text = output.get_data(as_text=True)
  52. self.assertIn(
  53. '<h5 class="pl-2 font-weight-bold text-muted">'
  54. 'Project Settings</h5>\n', output_text)
  55. self.assertTrue(
  56. 'Hook Block Un-Signed '
  57. 'commits deactivated' in output_text)
  58. output = self.app.get(
  59. '/test/settings/Block Un-Signed commits')
  60. self.assertEqual(output.status_code, 200)
  61. output_text = output.get_data(as_text=True)
  62. self.assertIn(
  63. '<title>Settings Block Un-Signed commits - test - '
  64. 'Pagure</title>', output_text)
  65. self.assertTrue(
  66. '<input class="form-check-input mt-2" id="active" name="active" '
  67. 'type="checkbox" value="y">' in output_text)
  68. self.assertFalse(os.path.exists(os.path.join(
  69. self.path, 'repos', 'test.git', 'hooks',
  70. 'pre-receive.pagureunsignedcommit')))
  71. # Activate the hook
  72. data = {'csrf_token': csrf_token, 'active': 'y'}
  73. output = self.app.post(
  74. '/test/settings/Block Un-Signed commits',
  75. data=data, follow_redirects=True)
  76. self.assertEqual(output.status_code, 200)
  77. output_text = output.get_data(as_text=True)
  78. self.assertIn(
  79. '<h5 class="pl-2 font-weight-bold text-muted">'
  80. 'Project Settings</h5>\n', output_text)
  81. self.assertNotIn(
  82. 'Hook activated',
  83. output_text)
  84. # De-Activate hook
  85. data = {'csrf_token': csrf_token}
  86. output = self.app.post(
  87. '/test/settings/Block Un-Signed commits',
  88. data=data, follow_redirects=True)
  89. self.assertEqual(output.status_code, 200)
  90. output_text = output.get_data(as_text=True)
  91. self.assertIn(
  92. '<h5 class="pl-2 font-weight-bold text-muted">'
  93. 'Project Settings</h5>\n', output_text)
  94. self.assertTrue(
  95. 'Hook Block Un-Signed '
  96. 'commits deactivated' in output_text)
  97. output = self.app.get(
  98. '/test/settings/Block Un-Signed commits')
  99. output_text = output.get_data(as_text=True)
  100. self.assertIn(
  101. '<title>Settings Block Un-Signed commits - test - '
  102. 'Pagure</title>', output_text)
  103. self.assertIn(
  104. '<input class="form-check-input mt-2" id="active" name="active" '
  105. 'type="checkbox" value="y">', output_text)
  106. self.assertFalse(os.path.exists(os.path.join(
  107. self.path, 'repos', 'test.git', 'hooks',
  108. 'pre-receive.pagureunsignedcommit')))
  109. if __name__ == '__main__':
  110. unittest.main(verbosity=2)