test_pagure_flask_api_plugins_view.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. def test_view_plugin(self):
  20. """Test viewing every plugin available in pagure."""
  21. output = self.app.get("/api/0/_plugins")
  22. self.assertEqual(output.status_code, 200)
  23. data = json.loads(output.get_data(as_text=True))
  24. self.assertEqual(
  25. data,
  26. {
  27. "plugins": [
  28. {"Block Un-Signed commits": []},
  29. {"Block non fast-forward pushes": ["branches"]},
  30. {"Fedmsg": []},
  31. {
  32. "IRC": [
  33. "server",
  34. "port",
  35. "room",
  36. "nick",
  37. "nick_pass",
  38. "join",
  39. "ssl",
  40. ]
  41. },
  42. {"Mail": ["mail_to"]},
  43. {"Mirroring": ["target", "public_key", "last_log"]},
  44. {"Pagure": []},
  45. {
  46. "Pagure CI": [
  47. "ci_type",
  48. "ci_url",
  49. "ci_job",
  50. "active_commit",
  51. "active_pr",
  52. ]
  53. },
  54. {"Pagure requests": []},
  55. {"Pagure tickets": []},
  56. {"Prevent creating new branches by git push": []},
  57. {"Read the Doc": ["api_url", "api_token", "branches"]},
  58. ],
  59. "total_plugins": 12,
  60. },
  61. )
  62. @patch.dict("pagure.config.config", {"DISABLED_PLUGINS": ["IRC"]})
  63. def test_view_plugin_disabled(self):
  64. """Test viewing every plugin available in pagure with one plugin disabled."""
  65. output = self.app.get("/api/0/_plugins")
  66. self.assertEqual(output.status_code, 200)
  67. data = json.loads(output.get_data(as_text=True))
  68. self.assertEqual(
  69. data,
  70. {
  71. "plugins": [
  72. {"Block Un-Signed commits": []},
  73. {"Block non fast-forward pushes": ["branches"]},
  74. {"Fedmsg": []},
  75. {"Mail": ["mail_to"]},
  76. {"Mirroring": ["target", "public_key", "last_log"]},
  77. {"Pagure": []},
  78. {
  79. "Pagure CI": [
  80. "ci_type",
  81. "ci_url",
  82. "ci_job",
  83. "active_commit",
  84. "active_pr",
  85. ]
  86. },
  87. {"Pagure requests": []},
  88. {"Pagure tickets": []},
  89. {"Prevent creating new branches by git push": []},
  90. {"Read the Doc": ["api_url", "api_token", "branches"]},
  91. ],
  92. "total_plugins": 12,
  93. },
  94. )
  95. if __name__ == "__main__":
  96. unittest.main(verbosity=2)