test_api.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from django.shortcuts import reverse
  2. from model_bakery import baker
  3. from organizations_ext.models import OrganizationUserRole
  4. from glitchtip.test_utils.test_case import GlitchTipTestCase
  5. from ..models import Release
  6. class ReleaseAPITestCase(GlitchTipTestCase):
  7. def setUp(self):
  8. self.create_user_and_project()
  9. def test_list(self):
  10. url = reverse(
  11. "organization-releases-list",
  12. kwargs={"organization_slug": self.organization.slug},
  13. )
  14. release1 = baker.make("releases.Release", organization=self.organization)
  15. release2 = baker.make("releases.Release")
  16. organization2 = baker.make("organizations_ext.Organization")
  17. organization2.add_user(self.user, OrganizationUserRole.ADMIN)
  18. release3 = baker.make("releases.Release", organization=organization2)
  19. res = self.client.get(url)
  20. self.assertContains(res, release1.version)
  21. self.assertNotContains(res, release2.version) # User not in org
  22. self.assertNotContains(res, release3.version) # Filtered our by url
  23. def test_retrieve(self):
  24. release = baker.make("releases.Release", organization=self.organization)
  25. url = reverse(
  26. "organization-releases-detail",
  27. kwargs={
  28. "organization_slug": self.organization.slug,
  29. "version": release.version,
  30. },
  31. )
  32. res = self.client.get(url)
  33. self.assertContains(res, release.version)
  34. def test_finalize(self):
  35. release = baker.make("releases.Release", organization=self.organization)
  36. url = reverse(
  37. "organization-releases-detail",
  38. kwargs={
  39. "organization_slug": release.organization.slug,
  40. "version": release.version,
  41. },
  42. )
  43. data = {"projects": ["fun"], "dateReleased": "2021-09-04T14:08:57.388525996Z"}
  44. res = self.client.put(url, data)
  45. self.assertEqual(res.status_code, 200)
  46. self.assertEqual(res.data["dateReleased"], "2021-09-04T14:08:57.388525Z")
  47. def test_destroy(self):
  48. release1 = baker.make("releases.Release", organization=self.organization)
  49. url = reverse(
  50. "organization-releases-detail",
  51. kwargs={
  52. "organization_slug": release1.organization.slug,
  53. "version": release1.version,
  54. },
  55. )
  56. res = self.client.delete(url)
  57. self.assertEqual(res.status_code, 204)
  58. self.assertEqual(Release.objects.all().count(), 0)
  59. release2 = baker.make("releases.Release")
  60. url = reverse(
  61. "organization-releases-detail",
  62. kwargs={
  63. "organization_slug": release2.organization.slug,
  64. "version": release2.version,
  65. },
  66. )
  67. res = self.client.delete(url)
  68. self.assertEqual(res.status_code, 404)
  69. self.assertEqual(Release.objects.all().count(), 1)