test_group_details.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from django.test.client import RequestFactory
  2. from django.urls import reverse
  3. from fixtures.apidocs_test_case import APIDocsTestCase
  4. from sentry.testutils import SCIMTestCase
  5. from sentry.testutils.silo import region_silo_test
  6. @region_silo_test
  7. class SCIMTeamDetailsDocs(APIDocsTestCase, SCIMTestCase):
  8. def setUp(self):
  9. super().setUp()
  10. self.member = self.create_member(user=self.create_user(), organization=self.organization)
  11. self.team = self.create_team(
  12. organization=self.organization, members=[self.user, self.member.user]
  13. )
  14. self.url = reverse(
  15. "sentry-api-0-organization-scim-team-details",
  16. kwargs={"organization_slug": self.organization.slug, "team_id": self.team.id},
  17. )
  18. def test_get(self):
  19. response = self.client.get(self.url)
  20. request = RequestFactory().get(self.url)
  21. self.validate_schema(request, response)
  22. def test_delete(self):
  23. response = self.client.delete(self.url)
  24. request = RequestFactory().delete(self.url)
  25. self.validate_schema(request, response)
  26. def test_patch_rename(self):
  27. patch_data = {
  28. "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
  29. "Operations": [
  30. {
  31. "op": "replace",
  32. "value": {
  33. "id": self.team.id,
  34. "displayName": "newName",
  35. },
  36. }
  37. ],
  38. }
  39. response = self.client.patch(self.url, patch_data)
  40. request = RequestFactory().patch(self.url, patch_data)
  41. self.validate_schema(request, response)
  42. def test_patch_replace(self):
  43. newmember = self.create_member(user=self.create_user(), organization=self.organization)
  44. patch_data = {
  45. "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
  46. "Operations": [
  47. {
  48. "op": "replace",
  49. "path": "members",
  50. "value": [
  51. {
  52. "value": newmember.id,
  53. "display": "test2.user@okta.local",
  54. },
  55. ],
  56. }
  57. ],
  58. }
  59. response = self.client.patch(self.url, patch_data)
  60. request = RequestFactory().patch(self.url, patch_data)
  61. self.validate_schema(request, response)
  62. def test_patch_add_member(self):
  63. newmember = self.create_member(user=self.create_user(), organization=self.organization)
  64. patch_data = {
  65. "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
  66. "Operations": [
  67. {
  68. "op": "add",
  69. "path": "members",
  70. "value": [
  71. {
  72. "value": newmember.id,
  73. "display": newmember.email,
  74. }
  75. ],
  76. },
  77. ],
  78. }
  79. response = self.client.patch(self.url, patch_data)
  80. request = RequestFactory().patch(self.url, patch_data)
  81. self.validate_schema(request, response)
  82. def test_patch_remove_member(self):
  83. patch_data = {
  84. "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
  85. "Operations": [
  86. {
  87. "op": "remove",
  88. "path": f'members[value eq "{self.member.id}"]',
  89. }
  90. ],
  91. }
  92. response = self.client.patch(self.url, patch_data)
  93. request = RequestFactory().patch(self.url, patch_data)
  94. self.validate_schema(request, response)