test_group_details.py 3.6 KB

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