test_group_details.py 3.6 KB

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