test_member_index.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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(email="test.user@okta.local"),
  36. organization=self.organization,
  37. role="member",
  38. invite_status=1,
  39. )
  40. post_data = {
  41. "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
  42. "userName": "test.user@okta.local",
  43. "name": {"givenName": "Test", "familyName": "User"},
  44. "emails": [{"primary": True, "value": "test.user@okta.local", "type": "work"}],
  45. "displayName": "Test User",
  46. "locale": "en-US",
  47. "externalId": "00ujl29u0le5T6Aj10h7",
  48. "groups": [],
  49. "password": "1mz050nq",
  50. "active": True,
  51. }
  52. response = self.client.post(self.url, post_data)
  53. request = RequestFactory().post(self.url, post_data)
  54. self.validate_schema(request, response)