test_pagure_flask_ui_plugins_default_hook.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 test_plugin_default_ui(self):
  23. """ Test the default hook plugin on/off endpoint. """
  24. tests.create_projects(self.session)
  25. tests.create_projects_git(os.path.join(self.path, 'repos'))
  26. user = tests.FakeUser(username='pingou')
  27. with tests.user_set(self.app.application, user):
  28. output = self.app.get('/test/settings/default')
  29. self.assertEqual(output.status_code, 403)
  30. def test_plugin_default_install(self):
  31. """ Check that the default plugin is correctly installed when a
  32. project is created.
  33. """
  34. task = pagure.lib.new_project(
  35. self.session,
  36. user='pingou',
  37. name='test',
  38. blacklist=[],
  39. allowed_prefix=[],
  40. gitfolder=os.path.join(self.path, 'repos'),
  41. docfolder=os.path.join(self.path, 'docs'),
  42. ticketfolder=os.path.join(self.path, 'tickets'),
  43. requestfolder=os.path.join(self.path, 'requests'),
  44. description=None,
  45. url=None, avatar_email=None,
  46. parent_id=None,
  47. add_readme=False,
  48. userobj=None,
  49. prevent_40_chars=False,
  50. namespace=None
  51. )
  52. self.assertEqual(task.get(),
  53. {'endpoint': 'ui_ns.view_repo',
  54. 'repo': 'test',
  55. 'namespace': None})
  56. self.assertTrue(os.path.exists(os.path.join(
  57. self.path, 'repos', 'test.git', 'hooks', 'post-receive.default')))
  58. self.assertTrue(os.path.exists(os.path.join(
  59. self.path, 'repos', 'test.git', 'hooks', 'post-receive')))
  60. if __name__ == '__main__':
  61. unittest.main(verbosity=2)