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.

49 lines
1.9 KiB

  1. from hc.test import BaseTestCase
  2. from hc.accounts.models import Member, Project
  3. from hc.api.models import Check, Channel
  4. class ProjectModelTestCase(BaseTestCase):
  5. def test_num_checks_available_handles_multiple_projects(self):
  6. # One check in Alice's primary project:
  7. Check.objects.create(project=self.project)
  8. # One check in Alice's secondary project:
  9. p2 = Project.objects.create(owner=self.alice)
  10. Check.objects.create(project=p2)
  11. self.assertEqual(self.project.num_checks_available(), 18)
  12. def test_it_handles_zero_broken_channels(self):
  13. Channel.objects.create(kind="webhook", last_error="", project=self.project)
  14. self.assertFalse(self.project.have_channel_issues())
  15. def test_it_handles_one_broken_channel(self):
  16. Channel.objects.create(kind="webhook", last_error="x", project=self.project)
  17. self.assertTrue(self.project.have_channel_issues())
  18. def test_it_handles_no_channels(self):
  19. # It's an issue if the project has no channels at all:
  20. self.assertTrue(self.project.have_channel_issues())
  21. def test_it_allows_third_user(self):
  22. # Alice is the owner, and Bob is invited -- there is space for the third user:
  23. self.assertTrue(self.project.can_invite_new_users())
  24. def test_it_allows_same_user_in_multiple_projects(self):
  25. p2 = Project.objects.create(owner=self.alice)
  26. Member.objects.create(user=self.bob, project=p2)
  27. # Bob's membership in two projects counts as one seat,
  28. # one seat should be still free:
  29. self.assertTrue(self.project.can_invite_new_users())
  30. def test_it_checks_team_limit(self):
  31. p2 = Project.objects.create(owner=self.alice)
  32. Member.objects.create(user=self.charlie, project=p2)
  33. # Alice and Bob are in one project, Charlie is in another,
  34. # so no seats left:
  35. self.assertFalse(self.project.can_invite_new_users())