test_users.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from datetime import timedelta
  2. from django.test.client import RequestFactory
  3. from django.urls import reverse
  4. from django.utils import timezone
  5. from fixtures.apidocs_test_case import APIDocsTestCase
  6. from sentry.testutils.cases import SnubaTestCase
  7. from sentry.testutils.helpers.datetime import before_now
  8. from sentry.utils.eventuser import EventUser
  9. class ProjectUsersDocs(APIDocsTestCase, SnubaTestCase):
  10. def setUp(self):
  11. super().setUp()
  12. self.project = self.create_project(date_added=(timezone.now() - timedelta(hours=2)))
  13. timestamp = before_now(hours=1).isoformat()
  14. self.url = reverse(
  15. "sentry-api-0-project-users",
  16. kwargs={
  17. "organization_id_or_slug": self.organization.slug,
  18. "project_id_or_slug": self.project.slug,
  19. },
  20. )
  21. self.event1 = self.store_event(
  22. project_id=self.project.id,
  23. data={
  24. "user": {
  25. "id": 1,
  26. "email": "foo@example.com",
  27. "username": "foobar",
  28. "ip_address": "127.0.0.1",
  29. },
  30. "event_id": "b" * 32,
  31. "timestamp": timestamp,
  32. },
  33. )
  34. self.euser1 = EventUser.from_event(self.event1)
  35. self.event2 = self.store_event(
  36. project_id=self.project.id,
  37. data={
  38. "user": {
  39. "id": 2,
  40. "email": "bar@example.com",
  41. "username": "baz",
  42. "ip_address": "192.168.0.1",
  43. },
  44. "event_id": "c" * 32,
  45. "timestamp": timestamp,
  46. },
  47. )
  48. self.euser2 = EventUser.from_event(self.event2)
  49. self.login_as(user=self.user)
  50. def test_get(self):
  51. response = self.client.get(self.url)
  52. request = RequestFactory().get(self.url)
  53. self.validate_schema(request, response)