test_member_index.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 SCIMMemberIndexDocs(APIDocsTestCase, SCIMTestCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.member = self.create_member(user=self.create_user(), organization=self.organization)
  9. self.url = reverse(
  10. "sentry-api-0-organization-scim-member-index",
  11. kwargs={"organization_slug": self.organization.slug},
  12. )
  13. def test_get(self):
  14. response = self.client.get(self.url)
  15. request = RequestFactory().get(self.url)
  16. self.validate_schema(request, response)
  17. def test_post(self):
  18. post_data = {
  19. "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
  20. "userName": "test.user@okta.local",
  21. "name": {"givenName": "Test", "familyName": "User"},
  22. "emails": [{"primary": True, "value": "test.user@okta.local", "type": "work"}],
  23. "displayName": "Test User",
  24. "locale": "en-US",
  25. "externalId": "00ujl29u0le5T6Aj10h7",
  26. "groups": [],
  27. "password": "1mz050nq",
  28. "active": True,
  29. }
  30. response = self.client.post(self.url, post_data)
  31. request = RequestFactory().post(self.url, post_data)
  32. self.validate_schema(request, response)
  33. def test_post_member_exists_but_not_accepted(self):
  34. self.create_member(
  35. user=self.create_user(),
  36. organization=self.organization,
  37. email="test.user@okta.local",
  38. role="member",
  39. invite_status=1,
  40. )
  41. post_data = {
  42. "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
  43. "userName": "test.user@okta.local",
  44. "name": {"givenName": "Test", "familyName": "User"},
  45. "emails": [{"primary": True, "value": "test.user@okta.local", "type": "work"}],
  46. "displayName": "Test User",
  47. "locale": "en-US",
  48. "externalId": "00ujl29u0le5T6Aj10h7",
  49. "groups": [],
  50. "password": "1mz050nq",
  51. "active": True,
  52. }
  53. response = self.client.post(self.url, post_data)
  54. request = RequestFactory().post(self.url, post_data)
  55. self.validate_schema(request, response)