test_pagure_flask_ui_plugins_irc.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2015-2016 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. __requires__ = ['SQLAlchemy >= 0.8']
  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 pagure.lib
  14. import tests
  15. class PagureFlaskPluginIRCtests(tests.SimplePagureTest):
  16. """ Tests for pagure_hook plugin of pagure """
  17. def test_plugin_mail(self):
  18. """ Test the irc plugin on/off endpoint. """
  19. tests.create_projects(self.session)
  20. tests.create_projects_git(os.path.join(self.path, 'repos'))
  21. user = tests.FakeUser(username='pingou')
  22. with tests.user_set(self.app.application, user):
  23. output = self.app.get('/test/settings/IRC')
  24. self.assertEqual(output.status_code, 200)
  25. self.assertIn(
  26. '<div class="projectinfo m-t-1 m-b-1">\n'
  27. 'test project #1 </div>', output.data)
  28. self.assertTrue('<h3>IRC settings</h3>' in output.data)
  29. self.assertTrue(
  30. '<input class="form-control" id="active" name="active" '
  31. 'type="checkbox" value="y">' in output.data)
  32. csrf_token = output.data.split(
  33. 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
  34. data = {}
  35. output = self.app.post('/test/settings/IRC', data=data)
  36. self.assertEqual(output.status_code, 200)
  37. self.assertIn(
  38. '<div class="projectinfo m-t-1 m-b-1">\n'
  39. 'test project #1 </div>', output.data)
  40. self.assertTrue('<h3>IRC settings</h3>' in output.data)
  41. self.assertTrue(
  42. '<input class="form-control" id="active" name="active" '
  43. 'type="checkbox" value="y">' in output.data)
  44. self.assertFalse(os.path.exists(os.path.join(
  45. self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
  46. data['csrf_token'] = csrf_token
  47. # With the git repo
  48. output = self.app.post(
  49. '/test/settings/IRC', data=data, follow_redirects=True)
  50. self.assertEqual(output.status_code, 200)
  51. self.assertIn(
  52. '<section class="settings">\n <h3>Settings for test</h3>',
  53. output.data)
  54. self.assertTrue(
  55. '</button>\n Hook IRC deactivated' in output.data)
  56. output = self.app.get('/test/settings/IRC')
  57. self.assertEqual(output.status_code, 200)
  58. self.assertIn(
  59. '<div class="projectinfo m-t-1 m-b-1">\n'
  60. 'test project #1 </div>', output.data)
  61. self.assertTrue('<h3>IRC settings</h3>' in output.data)
  62. self.assertTrue(
  63. '<input class="form-control" id="active" name="active" '
  64. 'type="checkbox" value="y">' in output.data)
  65. self.assertFalse(os.path.exists(os.path.join(
  66. self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
  67. # Activate hook
  68. data = {
  69. 'csrf_token': csrf_token,
  70. 'active': 'y',
  71. 'server': 'irc.freenode.net',
  72. 'port': 6667,
  73. 'room': '#fedora-apps',
  74. }
  75. output = self.app.post(
  76. '/test/settings/IRC', data=data, follow_redirects=True)
  77. self.assertEqual(output.status_code, 200)
  78. self.assertIn(
  79. '<section class="settings">\n <h3>Settings for test</h3>',
  80. output.data)
  81. self.assertTrue(
  82. '</button>\n Hook IRC activated' in output.data)
  83. output = self.app.get('/test/settings/IRC')
  84. self.assertEqual(output.status_code, 200)
  85. self.assertIn(
  86. '<div class="projectinfo m-t-1 m-b-1">\n'
  87. 'test project #1 </div>', output.data)
  88. self.assertTrue('<h3>IRC settings</h3>' in output.data)
  89. self.assertTrue(
  90. '<input checked class="form-control" id="active" name="active" '
  91. 'type="checkbox" value="y">' in output.data)
  92. # TODO: Fix this
  93. #self.assertTrue(os.path.exists(os.path.join(
  94. #self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
  95. # De-Activate hook
  96. data = {'csrf_token': csrf_token}
  97. output = self.app.post('/test/settings/IRC', data=data, follow_redirects=True)
  98. self.assertEqual(output.status_code, 200)
  99. self.assertIn(
  100. '<section class="settings">\n <h3>Settings for test</h3>',
  101. output.data)
  102. self.assertTrue(
  103. '</button>\n Hook IRC deactivated' in output.data)
  104. output = self.app.get('/test/settings/IRC')
  105. self.assertEqual(output.status_code, 200)
  106. self.assertIn(
  107. '<div class="projectinfo m-t-1 m-b-1">\n'
  108. 'test project #1 </div>', output.data)
  109. self.assertTrue('<h3>IRC settings</h3>' in output.data)
  110. self.assertTrue(
  111. '<input class="form-control" id="active" name="active" '
  112. 'type="checkbox" value="y">' in output.data)
  113. self.assertFalse(os.path.exists(os.path.join(
  114. self.path, 'repos', 'test.git', 'hooks', 'post-receive.irc')))
  115. if __name__ == '__main__':
  116. unittest.main(verbosity=2)