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.

62 lines
2.1 KiB

5 years ago
5 years ago
  1. from django.contrib.auth.models import User
  2. from django.core.signing import TimestampSigner
  3. from django.test import Client, TestCase
  4. from hc.accounts.models import Member, Profile, Project
  5. class BaseTestCase(TestCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.csrf_client = Client(enforce_csrf_checks=True)
  9. # Alice is a normal user for tests. Alice has team access enabled.
  10. self.alice = User(username="alice", email="[email protected]")
  11. self.alice.set_password("password")
  12. self.alice.save()
  13. self.project = Project(owner=self.alice, api_key="X" * 32)
  14. self.project.name = "Alices Project"
  15. self.project.badge_key = self.alice.username
  16. self.project.ping_key = "p" * 22
  17. self.project.save()
  18. self.profile = Profile(user=self.alice)
  19. self.profile.sms_limit = 50
  20. self.profile.save()
  21. # Bob is on Alice's team and should have access to her stuff
  22. self.bob = User(username="bob", email="[email protected]")
  23. self.bob.set_password("password")
  24. self.bob.save()
  25. self.bobs_project = Project(owner=self.bob)
  26. self.bobs_project.badge_key = self.bob.username
  27. self.bobs_project.save()
  28. self.bobs_profile = Profile(user=self.bob)
  29. self.bobs_profile.save()
  30. self.bobs_membership = Member.objects.create(
  31. user=self.bob, project=self.project, role=Member.Role.REGULAR
  32. )
  33. # Charlie should have no access to Alice's stuff
  34. self.charlie = User(username="charlie", email="[email protected]")
  35. self.charlie.set_password("password")
  36. self.charlie.save()
  37. self.charlies_project = Project(owner=self.charlie)
  38. self.charlies_project.badge_key = self.charlie.username
  39. self.charlies_project.save()
  40. self.charlies_profile = Profile(user=self.charlie)
  41. self.charlies_profile.save()
  42. self.channels_url = "/projects/%s/integrations/" % self.project.code
  43. def set_sudo_flag(self):
  44. session = self.client.session
  45. session["sudo"] = TimestampSigner().sign("active")
  46. session.save()