test_hooks.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from sentry.apidocs.hooks import custom_postprocessing_hook
  2. from sentry.testutils.cases import TestCase
  3. class FixIssueRoutesTest(TestCase):
  4. def test_issue_route_fixes(self):
  5. BEFORE = {
  6. "components": {"schemas": {}},
  7. "paths": {
  8. "/api/0/organizations/{organization_id_or_slug}/{var}/{issue_id}/": {
  9. "get": {
  10. "tags": ["Events"],
  11. "description": "Get issues",
  12. "operationId": "get issue",
  13. "parameters": [
  14. {
  15. "in": "path",
  16. "name": "organization_id_or_slug",
  17. "schema": {"type": "string"},
  18. "description": "The ID or slug of the organization the resource belongs to.",
  19. "required": True,
  20. },
  21. {
  22. "in": "path",
  23. "name": "var",
  24. "schema": {"type": "string"},
  25. "description": "Issues or groups",
  26. "required": True,
  27. },
  28. ],
  29. }
  30. },
  31. "/api/0/{var}/{issue_id}/": {
  32. "get": {
  33. "tags": ["Events"],
  34. "description": "Get issues",
  35. "operationId": "get issue",
  36. "parameters": [
  37. {
  38. "in": "path",
  39. "name": "var",
  40. "schema": {"type": "string"},
  41. "description": "Issues or groups",
  42. "required": True,
  43. },
  44. ],
  45. }
  46. },
  47. "/api/0/some/path/": {
  48. "get": {
  49. "tags": ["Events"],
  50. "description": "Something else",
  51. "operationId": "get something",
  52. "parameters": [],
  53. }
  54. },
  55. },
  56. }
  57. # Issue route with /organizations/{organization_id_or_slug}/ should be removed
  58. # Issue route with /{var}/{issue_id}/ should be renamed to /issues/{issue_id}/
  59. # "var" and "organization_id_or_slug" path parameters should be removed
  60. AFTER = {
  61. "paths": {
  62. "/api/0/issues/{issue_id}/": {
  63. "get": {
  64. "tags": ["Events"],
  65. "description": "Get issues",
  66. "operationId": "get issue",
  67. "parameters": [],
  68. }
  69. },
  70. "/api/0/some/path/": {
  71. "get": {
  72. "tags": ["Events"],
  73. "description": "Something else",
  74. "operationId": "get something",
  75. "parameters": [],
  76. }
  77. },
  78. },
  79. "components": {"schemas": {}},
  80. }
  81. assert custom_postprocessing_hook(BEFORE, None) == AFTER