test_deploys.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. from sentry.models.releaseprojectenvironment import ReleaseProjectEnvironment
  8. class ReleaseDeploysDocs(APIDocsTestCase):
  9. def setUp(self):
  10. project = self.create_project(name="foo")
  11. release = self.create_release(project=project, version="1")
  12. release.add_project(project)
  13. prod_deploy = Deploy.objects.create(
  14. environment_id=Environment.objects.create(
  15. organization_id=project.organization_id, name="production"
  16. ).id,
  17. organization_id=project.organization_id,
  18. release=release,
  19. date_finished=datetime.datetime.now(datetime.UTC) - datetime.timedelta(days=1),
  20. )
  21. staging_deploy = Deploy.objects.create(
  22. environment_id=Environment.objects.create(
  23. organization_id=project.organization_id, name="staging"
  24. ).id,
  25. organization_id=project.organization_id,
  26. release=release,
  27. )
  28. ReleaseProjectEnvironment.objects.create(
  29. project=project,
  30. release_id=release.id,
  31. environment_id=prod_deploy.environment_id,
  32. last_deploy_id=prod_deploy.id,
  33. )
  34. ReleaseProjectEnvironment.objects.create(
  35. project=project,
  36. release_id=release.id,
  37. environment_id=staging_deploy.environment_id,
  38. last_deploy_id=staging_deploy.id,
  39. )
  40. self.url = reverse(
  41. "sentry-api-0-organization-release-deploys",
  42. kwargs={"organization_slug": project.organization.slug, "version": release.version},
  43. )
  44. self.login_as(user=self.user)
  45. def test_get(self):
  46. response = self.client.get(self.url)
  47. request = RequestFactory().get(self.url)
  48. self.validate_schema(request, response)
  49. def test_post(self):
  50. data = {
  51. "name": "foo",
  52. "environment": "production",
  53. "url": "https://www.example.com",
  54. }
  55. response = self.client.post(self.url, data)
  56. request = RequestFactory().post(self.url, data)
  57. self.validate_schema(request, response)