test_users.py 2.0 KB

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