test_api.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. from django.test import TestCase
  2. from django.urls import reverse
  3. from model_bakery import baker
  4. from glitchtip.test_utils.test_case import GlitchTipTestCaseMixin
  5. from ..models import EnvironmentProject
  6. class EnvironmentTestCase(GlitchTipTestCaseMixin, TestCase):
  7. def setUp(self):
  8. self.create_logged_in_user()
  9. self.url = reverse("api:list_environments", args=[self.organization.slug])
  10. def test_environments(self):
  11. environment = baker.make(
  12. "environments.Environment", organization=self.organization
  13. )
  14. baker.make(
  15. "environments.EnvironmentProject",
  16. environment=environment,
  17. project=self.project,
  18. )
  19. other_environment = baker.make("environments.Environment")
  20. baker.make(
  21. "environments.EnvironmentProject",
  22. environment=other_environment,
  23. project=self.project,
  24. )
  25. res = self.client.get(self.url)
  26. self.assertContains(res, environment.name)
  27. self.assertNotContains(res, other_environment.name)
  28. def test_hide_environments(self):
  29. environment_project1 = baker.make(
  30. "environments.EnvironmentProject",
  31. project=self.project,
  32. environment__organization=self.organization,
  33. is_hidden=False,
  34. )
  35. environment_project2 = baker.make(
  36. "environments.EnvironmentProject",
  37. project=self.project,
  38. environment__organization=self.organization,
  39. is_hidden=True,
  40. )
  41. res = self.client.get(self.url + "?visibility=visible")
  42. self.assertContains(res, environment_project1.environment.name)
  43. self.assertNotContains(res, environment_project2.environment.name)
  44. class EnvironmentProjectTestCase(GlitchTipTestCaseMixin, TestCase):
  45. def setUp(self):
  46. self.create_logged_in_user()
  47. def test_environment_projects(self):
  48. url = reverse(
  49. "api:list_environment_projects",
  50. args=[self.organization.slug, self.project.slug],
  51. )
  52. environment_project = baker.make(
  53. "environments.EnvironmentProject",
  54. project=self.project,
  55. environment__organization=self.organization,
  56. )
  57. other_environment_project = baker.make("environments.EnvironmentProject")
  58. another_environment_project = baker.make(
  59. "environments.EnvironmentProject",
  60. environment__organization=self.organization,
  61. )
  62. res = self.client.get(url)
  63. self.assertContains(res, environment_project.environment.name)
  64. self.assertNotContains(res, other_environment_project.environment.name)
  65. self.assertNotContains(res, another_environment_project.environment.name)
  66. def test_make_hidden(self):
  67. environment_project = baker.make(
  68. "environments.EnvironmentProject",
  69. is_hidden=False,
  70. project=self.project,
  71. environment__organization=self.organization,
  72. )
  73. detail_url = reverse(
  74. "api:update_environment_project",
  75. args=[
  76. self.organization.slug,
  77. self.project.slug,
  78. environment_project.environment.name,
  79. ],
  80. )
  81. data = {"name": environment_project.environment.name, "isHidden": True}
  82. res = self.client.put(detail_url, data, content_type="application/json")
  83. self.assertContains(res, "true")
  84. self.assertTrue(EnvironmentProject.objects.filter(is_hidden=True).exists())