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.

44 lines
1.5 KiB

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