test_group_details.py 3.7 KB

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