test_organization_releases.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from datetime import UTC, datetime
  2. import pytest
  3. from django.test.client import RequestFactory
  4. from django.urls import reverse
  5. from fixtures.apidocs_test_case import APIDocsTestCase
  6. from sentry.models.release import Release
  7. pytestmark = pytest.mark.sentry_metrics
  8. class OrganizationReleasesDocsTest(APIDocsTestCase):
  9. def setUp(self):
  10. user = self.create_user(is_staff=False, is_superuser=False)
  11. org = self.create_organization(owner=user, name="blah")
  12. org2 = self.create_organization(owner=user, name="bloop")
  13. team1 = self.create_team(organization=org)
  14. team2 = self.create_team(organization=org)
  15. self.create_team_membership(team1, user=user)
  16. self.create_team_membership(team2, user=user)
  17. self.project1 = self.create_project(teams=[team1], organization=org)
  18. self.project2 = self.create_project(teams=[team2], organization=org2)
  19. self.project3 = self.create_project(teams=[team1], organization=org)
  20. self.login_as(user=user)
  21. release1 = Release.objects.create(
  22. organization_id=org.id,
  23. version="1",
  24. date_added=datetime(2013, 8, 13, 3, 8, 24, 880386, tzinfo=UTC),
  25. )
  26. release1.add_project(self.project1)
  27. release2 = Release.objects.create(
  28. organization_id=org2.id,
  29. version="2",
  30. date_added=datetime(2013, 8, 14, 3, 8, 24, 880386, tzinfo=UTC),
  31. )
  32. release2.add_project(self.project2)
  33. self.url = reverse(
  34. "sentry-api-0-organization-releases", kwargs={"organization_slug": org.slug}
  35. )
  36. def test_get(self):
  37. response = self.client.get(self.url)
  38. request = RequestFactory().get(self.url)
  39. self.validate_schema(request, response)
  40. def test_post(self):
  41. data = {"version": "1.2.1", "projects": [self.project3.slug]}
  42. response = self.client.post(self.url, data)
  43. request = RequestFactory().post(self.url, data)
  44. self.validate_schema(request, response)