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.

115 lines
4.0 KiB

  1. from django.core import mail
  2. from django.conf import settings
  3. from hc.test import BaseTestCase
  4. from hc.accounts.models import Member
  5. class ProfileTestCase(BaseTestCase):
  6. def setUp(self):
  7. super(ProfileTestCase, self).setUp()
  8. self.url = "/projects/%s/settings/" % self.project.code
  9. def test_it_shows_api_keys(self):
  10. self.project.api_key_readonly = "R" * 32
  11. self.project.save()
  12. self.client.login(username="[email protected]", password="password")
  13. form = {"show_api_keys": "1"}
  14. r = self.client.post(self.url, form)
  15. self.assertEqual(r.status_code, 200)
  16. self.assertContains(r, "X" * 32)
  17. self.assertContains(r, "R" * 32)
  18. def test_it_creates_api_key(self):
  19. self.client.login(username="[email protected]", password="password")
  20. form = {"create_api_keys": "1"}
  21. r = self.client.post(self.url, form)
  22. self.assertEqual(r.status_code, 200)
  23. self.project.refresh_from_db()
  24. api_key = self.project.api_key
  25. self.assertTrue(len(api_key) > 10)
  26. self.assertFalse("b'" in api_key)
  27. def test_it_revokes_api_key(self):
  28. self.project.api_key_readonly = "R" * 32
  29. self.project.save()
  30. self.client.login(username="[email protected]", password="password")
  31. form = {"revoke_api_keys": "1"}
  32. r = self.client.post(self.url, form)
  33. assert r.status_code == 200
  34. self.project.refresh_from_db()
  35. self.assertEqual(self.project.api_key, "")
  36. self.assertEqual(self.project.api_key_readonly, "")
  37. def test_it_adds_team_member(self):
  38. self.client.login(username="[email protected]", password="password")
  39. form = {"invite_team_member": "1", "email": "[email protected]"}
  40. r = self.client.post(self.url, form)
  41. self.assertEqual(r.status_code, 200)
  42. members = self.project.member_set.all()
  43. self.assertEqual(members.count(), 2)
  44. member = Member.objects.get(project=self.project,
  45. user__email="[email protected]")
  46. profile = member.user.profile
  47. self.assertEqual(profile.current_project, self.project)
  48. # And an email should have been sent
  49. subj = ('You have been invited to join'
  50. ' [email protected] on %s' % settings.SITE_NAME)
  51. self.assertEqual(mail.outbox[0].subject, subj)
  52. def test_it_checks_team_size(self):
  53. self.profile.team_limit = 0
  54. self.profile.save()
  55. self.client.login(username="[email protected]", password="password")
  56. form = {"invite_team_member": "1", "email": "[email protected]"}
  57. r = self.client.post(self.url, form)
  58. self.assertEqual(r.status_code, 403)
  59. def test_it_removes_team_member(self):
  60. self.client.login(username="[email protected]", password="password")
  61. form = {"remove_team_member": "1", "email": "[email protected]"}
  62. r = self.client.post(self.url, form)
  63. self.assertEqual(r.status_code, 200)
  64. self.assertEqual(Member.objects.count(), 0)
  65. self.bobs_profile.refresh_from_db()
  66. self.assertEqual(self.bobs_profile.current_project, None)
  67. def test_it_checks_membership_when_removing_team_member(self):
  68. self.client.login(username="[email protected]", password="password")
  69. url = "/projects/%s/settings/" % self.charlies_project.code
  70. form = {"remove_team_member": "1", "email": "[email protected]"}
  71. r = self.client.post(url, form)
  72. self.assertEqual(r.status_code, 400)
  73. self.profile.refresh_from_db()
  74. self.assertIsNotNone(self.profile.current_project)
  75. def test_it_sets_project_name(self):
  76. self.client.login(username="[email protected]", password="password")
  77. form = {"set_project_name": "1", "name": "Alpha Team"}
  78. r = self.client.post(self.url, form)
  79. self.assertEqual(r.status_code, 200)
  80. self.project.refresh_from_db()
  81. self.assertEqual(self.project.name, "Alpha Team")