test_deploys.py 1.7 KB

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