You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.7 KiB

6 years ago
  1. from hc.test import BaseTestCase
  2. from hc.api.models import Check
  3. class SwitchTeamTestCase(BaseTestCase):
  4. def test_it_switches(self):
  5. self.bobs_profile.current_project = None
  6. self.bobs_profile.save()
  7. c = Check(user=self.alice, name="This belongs to Alice",
  8. project=self.project)
  9. c.save()
  10. self.client.login(username="[email protected]", password="password")
  11. url = "/accounts/switch_team/%s/" % self.alice.username
  12. r = self.client.get(url, follow=True)
  13. self.assertContains(r, "This belongs to Alice")
  14. self.bobs_profile.refresh_from_db()
  15. self.assertEqual(self.bobs_profile.current_project, self.project)
  16. def test_it_checks_team_membership(self):
  17. self.client.login(username="[email protected]", password="password")
  18. url = "/accounts/switch_team/%s/" % self.alice.username
  19. r = self.client.get(url)
  20. self.assertEqual(r.status_code, 403)
  21. def test_it_switches_to_own_team(self):
  22. self.client.login(username="[email protected]", password="password")
  23. url = "/accounts/switch_team/%s/" % self.alice.username
  24. r = self.client.get(url, follow=True)
  25. self.assertEqual(r.status_code, 200)
  26. def test_it_handles_invalid_username(self):
  27. self.client.login(username="[email protected]", password="password")
  28. url = "/accounts/switch_team/dave/"
  29. r = self.client.get(url)
  30. self.assertEqual(r.status_code, 403)
  31. def test_it_requires_login(self):
  32. url = "/accounts/switch_team/%s/" % self.alice.username
  33. r = self.client.get(url)
  34. expected_url = "/accounts/login/?next=/accounts/switch_team/alice/"
  35. self.assertRedirects(r, expected_url)