test_users.py 1.9 KB

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