test_nested_views.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from django.urls import reverse
  2. from model_bakery import baker
  3. from glitchtip.test_utils.test_case import GlitchTipTestCase
  4. from organizations_ext.models import OrganizationUserRole
  5. class ProjectTeamViewTestCase(GlitchTipTestCase):
  6. def setUp(self):
  7. self.create_user_and_project()
  8. self.url = reverse(
  9. "project-teams-list",
  10. kwargs={"project_pk": self.organization.slug + "/" + self.project.slug},
  11. )
  12. def test_project_team_list(self):
  13. res = self.client.get(self.url)
  14. self.assertContains(res, self.team.slug)
  15. def test_project_team_add_project(self):
  16. new_project = baker.make("projects.Project", organization=self.organization)
  17. url = reverse(
  18. "project-teams-list",
  19. kwargs={"project_pk": self.organization.slug + "/" + new_project.slug},
  20. )
  21. self.assertFalse(new_project.team_set.exists())
  22. res = self.client.post(url + self.team.slug + "/")
  23. self.assertContains(res, new_project.slug, status_code=201)
  24. self.assertTrue(new_project.team_set.exists())
  25. def test_project_team_add_project_no_perms(self):
  26. """User must be manager or above to manage project teams"""
  27. new_project = baker.make("projects.Project", organization=self.organization)
  28. user = baker.make("users.user")
  29. self.client.force_login(user)
  30. self.organization.add_user(user, OrganizationUserRole.MEMBER)
  31. url = reverse(
  32. "project-teams-list",
  33. kwargs={"project_pk": self.organization.slug + "/" + new_project.slug},
  34. )
  35. self.client.post(url + self.team.slug + "/")
  36. self.assertFalse(new_project.team_set.exists())
  37. def test_project_team_remove_project(self):
  38. url = reverse(
  39. "project-teams-list",
  40. kwargs={"project_pk": self.organization.slug + "/" + self.project.slug},
  41. )
  42. self.assertTrue(self.project.team_set.exists())
  43. res = self.client.delete(url + self.team.slug + "/")
  44. self.assertContains(res, self.project.slug)
  45. self.assertFalse(self.project.team_set.exists())