test_deploys.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import datetime
  2. from django.test.client import RequestFactory
  3. from django.urls import reverse
  4. from fixtures.apidocs_test_case import APIDocsTestCase
  5. from sentry.models import Deploy, Environment
  6. class ReleaseDeploysDocs(APIDocsTestCase):
  7. def setUp(self):
  8. project = self.create_project(name="foo")
  9. release = self.create_release(project=project, version="1")
  10. Deploy.objects.create(
  11. environment_id=Environment.objects.create(
  12. organization_id=project.organization_id, name="production"
  13. ).id,
  14. organization_id=project.organization_id,
  15. release=release,
  16. date_finished=datetime.datetime.utcnow() - datetime.timedelta(days=1),
  17. )
  18. Deploy.objects.create(
  19. environment_id=Environment.objects.create(
  20. organization_id=project.organization_id, name="staging"
  21. ).id,
  22. organization_id=project.organization_id,
  23. release=release,
  24. )
  25. self.url = reverse(
  26. "sentry-api-0-organization-release-deploys",
  27. kwargs={"organization_slug": project.organization.slug, "version": release.version},
  28. )
  29. self.login_as(user=self.user)
  30. def test_get(self):
  31. response = self.client.get(self.url)
  32. request = RequestFactory().get(self.url)
  33. self.validate_schema(request, response)
  34. def test_post(self):
  35. data = {
  36. "name": "foo",
  37. "environment": "production",
  38. "url": "https://www.example.com",
  39. }
  40. response = self.client.post(self.url, data)
  41. request = RequestFactory().post(self.url, data)
  42. self.validate_schema(request, response)