test_pagure_flask_api_plugins_view.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2019 - Copyright Red Hat Inc
  4. Authors:
  5. Michal Konecny <mkonecny@redhat.com>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import unittest
  9. import sys
  10. import os
  11. import json
  12. from mock import patch
  13. sys.path.insert(
  14. 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
  15. )
  16. import tests # noqa: E402
  17. class PagureFlaskApiPluginViewtests(tests.Modeltests):
  18. """ Tests for the flask API of pagure for viewing plugins
  19. """
  20. def test_view_plugin(self):
  21. """ Test viewing every plugin available in pagure.
  22. """
  23. output = self.app.get("/api/0/_plugins")
  24. self.assertEqual(output.status_code, 200)
  25. data = json.loads(output.get_data(as_text=True))
  26. self.assertEqual(
  27. data,
  28. {
  29. "plugins": [
  30. {"Block Un-Signed commits": []},
  31. {"Block non fast-forward pushes": ["branches"]},
  32. {"Fedmsg": []},
  33. {
  34. "IRC": [
  35. "server",
  36. "port",
  37. "room",
  38. "nick",
  39. "nick_pass",
  40. "join",
  41. "ssl",
  42. ]
  43. },
  44. {"Mail": ["mail_to"]},
  45. {"Mirroring": ["target", "public_key", "last_log"]},
  46. {"Pagure": []},
  47. {
  48. "Pagure CI": [
  49. "ci_type",
  50. "ci_url",
  51. "ci_job",
  52. "active_commit",
  53. "active_pr",
  54. ]
  55. },
  56. {"Pagure requests": []},
  57. {"Pagure tickets": []},
  58. {"Prevent creating new branches by git push": []},
  59. {"Read the Doc": ["api_url", "api_token", "branches"]},
  60. ],
  61. "total_plugins": 12,
  62. },
  63. )
  64. @patch.dict("pagure.config.config", {"DISABLED_PLUGINS": ["IRC"]})
  65. def test_view_plugin_disabled(self):
  66. """ Test viewing every plugin available in pagure with one plugin disabled.
  67. """
  68. output = self.app.get("/api/0/_plugins")
  69. self.assertEqual(output.status_code, 200)
  70. data = json.loads(output.get_data(as_text=True))
  71. self.assertEqual(
  72. data,
  73. {
  74. "plugins": [
  75. {"Block Un-Signed commits": []},
  76. {"Block non fast-forward pushes": ["branches"]},
  77. {"Fedmsg": []},
  78. {"Mail": ["mail_to"]},
  79. {"Mirroring": ["target", "public_key", "last_log"]},
  80. {"Pagure": []},
  81. {
  82. "Pagure CI": [
  83. "ci_type",
  84. "ci_url",
  85. "ci_job",
  86. "active_commit",
  87. "active_pr",
  88. ]
  89. },
  90. {"Pagure requests": []},
  91. {"Pagure tickets": []},
  92. {"Prevent creating new branches by git push": []},
  93. {"Read the Doc": ["api_url", "api_token", "branches"]},
  94. ],
  95. "total_plugins": 12,
  96. },
  97. )
  98. if __name__ == "__main__":
  99. unittest.main(verbosity=2)