test_pagure_flask_ui_plugins_default_hook.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2016 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. __requires__ = ['SQLAlchemy >= 0.8']
  8. import pkg_resources
  9. import json
  10. import unittest
  11. import shutil
  12. import sys
  13. import os
  14. import pygit2
  15. from mock import patch
  16. sys.path.insert(0, os.path.join(os.path.dirname(
  17. os.path.abspath(__file__)), '..'))
  18. import pagure.lib
  19. import tests
  20. class PagureFlaskPluginDefaultHooktests(tests.Modeltests):
  21. """ Tests for default_hook plugin of pagure """
  22. def setUp(self):
  23. """ Set up the environnment, ran before every tests. """
  24. super(PagureFlaskPluginDefaultHooktests, self).setUp()
  25. pagure.APP.config['TESTING'] = True
  26. pagure.SESSION = self.session
  27. pagure.ui.SESSION = self.session
  28. pagure.ui.app.SESSION = self.session
  29. pagure.ui.plugins.SESSION = self.session
  30. pagure.ui.repo.SESSION = self.session
  31. pagure.ui.filters.SESSION = self.session
  32. pagure.APP.config['GIT_FOLDER'] = self.path
  33. pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
  34. self.path, 'tickets')
  35. pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
  36. self.path, 'requests')
  37. pagure.APP.config['DOCS_FOLDER'] = os.path.join(
  38. self.path, 'docs')
  39. self.app = pagure.APP.test_client()
  40. def test_plugin_default_ui(self):
  41. """ Test the default hook plugin on/off endpoint. """
  42. tests.create_projects(self.session)
  43. tests.create_projects_git(self.path)
  44. user = tests.FakeUser(username='pingou')
  45. with tests.user_set(pagure.APP, user):
  46. output = self.app.get('/test/settings/default')
  47. self.assertEqual(output.status_code, 403)
  48. def test_plugin_default_install(self):
  49. """ Check that the default plugin is correctly installed when a
  50. project is created.
  51. """
  52. msg = pagure.lib.new_project(
  53. self.session,
  54. user='pingou',
  55. name='test',
  56. blacklist=[],
  57. allowed_prefix=[],
  58. gitfolder=self.path,
  59. docfolder=os.path.join(self.path, 'docs'),
  60. ticketfolder=os.path.join(self.path, 'tickets'),
  61. requestfolder=os.path.join(self.path, 'requests'),
  62. description=None,
  63. url=None, avatar_email=None,
  64. parent_id=None,
  65. add_readme=False,
  66. userobj=None,
  67. prevent_40_chars=False,
  68. namespace=None
  69. )
  70. self.assertEqual(msg, 'Project "test" created')
  71. self.assertTrue(os.path.exists(os.path.join(
  72. self.path, 'test.git', 'hooks', 'post-receive.default')))
  73. self.assertTrue(os.path.exists(os.path.join(
  74. self.path, 'test.git', 'hooks', 'post-receive')))
  75. if __name__ == '__main__':
  76. SUITE = unittest.TestLoader().loadTestsFromTestCase(
  77. PagureFlaskPluginDefaultHooktests)
  78. unittest.TextTestRunner(verbosity=2).run(SUITE)