test_deploys.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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={
  43. "organization_id_or_slug": project.organization.slug,
  44. "version": release.version,
  45. },
  46. )
  47. self.login_as(user=self.user)
  48. def test_get(self):
  49. response = self.client.get(self.url)
  50. request = RequestFactory().get(self.url)
  51. self.validate_schema(request, response)
  52. def test_post(self):
  53. data = {
  54. "name": "foo",
  55. "environment": "production",
  56. "url": "https://www.example.com",
  57. }
  58. response = self.client.post(self.url, data)
  59. request = RequestFactory().post(self.url, data)
  60. self.validate_schema(request, response)