tests.py 3.5 KB

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