def setUp(self): super(BaseTestCase, self).setUp() # Alice is a normal user for tests. Alice has team access enabled. self.alice = User(username="******", email="*****@*****.**") self.alice.set_password("password") self.alice.save() self.profile = Profile(user=self.alice, api_key="abc") self.profile.sms_limit = 50 self.profile.save() # Bob is on Alice's team and should have access to her stuff self.bob = User(username="******", email="*****@*****.**") self.bob.set_password("password") self.bob.save() self.bobs_profile = Profile(user=self.bob) self.bobs_profile.current_team = self.profile self.bobs_profile.save() Member.objects.create(team=self.profile, user=self.bob) # Charlie should have no access to Alice's stuff self.charlie = User(username="******", email="*****@*****.**") self.charlie.set_password("password") self.charlie.save() Profile.objects.create(user=self.charlie)
def setUp(self): super().setUp() self.csrf_client = Client(enforce_csrf_checks=True) # Alice is a normal user for tests. Alice has team access enabled. self.alice = User(username="******", email="*****@*****.**") self.alice.set_password("password") self.alice.save() self.project = Project(owner=self.alice, api_key="X" * 32) self.project.name = "Alices Project" self.project.badge_key = self.alice.username self.project.ping_key = "p" * 22 self.project.save() self.profile = Profile(user=self.alice) self.profile.sms_limit = 50 self.profile.save() # Bob is on Alice's team and should have access to her stuff self.bob = User(username="******", email="*****@*****.**") self.bob.set_password("password") self.bob.save() self.bobs_project = Project(owner=self.bob) self.bobs_project.badge_key = self.bob.username self.bobs_project.save() self.bobs_profile = Profile(user=self.bob) self.bobs_profile.save() self.bobs_membership = Member.objects.create(user=self.bob, project=self.project, role=Member.Role.REGULAR) # Charlie should have no access to Alice's stuff self.charlie = User(username="******", email="*****@*****.**") self.charlie.set_password("password") self.charlie.save() self.charlies_project = Project(owner=self.charlie) self.charlies_project.badge_key = self.charlie.username self.charlies_project.save() self.charlies_profile = Profile(user=self.charlie) self.charlies_profile.save() self.channels_url = "/projects/%s/integrations/" % self.project.code
def setUp(self): super(BaseTestCase, self).setUp() # Alice is a normal user for tests. Alice has team access enabled. self.alice = User(username="******", email="*****@*****.**") self.alice.set_password("password") self.alice.save() self.project = Project(owner=self.alice, api_key="X" * 32) self.project.name = "Alice's Project" self.project.badge_key = self.alice.username self.project.save() self.profile = Profile(user=self.alice) self.profile.sms_limit = 50 self.profile.current_project = self.project self.profile.save() # Bob is on Alice's team and should have access to her stuff self.bob = User(username="******", email="*****@*****.**") self.bob.set_password("password") self.bob.save() self.bobs_project = Project(owner=self.bob) self.bobs_project.badge_key = self.bob.username self.bobs_project.save() self.bobs_profile = Profile(user=self.bob) self.bobs_profile.current_project = self.project self.bobs_profile.save() Member.objects.create(user=self.bob, project=self.project) # Charlie should have no access to Alice's stuff self.charlie = User(username="******", email="*****@*****.**") self.charlie.set_password("password") self.charlie.save() self.charlies_project = Project(owner=self.charlie) self.charlies_project.badge_key = self.charlie.username self.charlies_project.save() self.charlies_profile = Profile(user=self.charlie) self.charlies_profile.current_project = self.charlies_project self.charlies_profile.save() self.channels_url = "/projects/%s/integrations/" % self.project.code
def _make_user(email): username = str(uuid.uuid4())[:30] user = User(username=username, email=email) user.set_unusable_password() user.save() profile = Profile(user=user) profile.save() channel = Channel() channel.user = user channel.kind = "email" channel.value = email channel.email_verified = True channel.save() return user
def __call__(self, request): if request.user.is_authenticated: teams_q = Profile.objects.filter(member__user_id=request.user.id) teams_q = teams_q.select_related("user") request.teams = list(teams_q) try: profile = request.user.profile except Profile.DoesNotExist: profile = Profile(user=request.user) profile.save() if profile.current_team: request.team = profile.current_team else: request.team = profile return self.get_response(request)
def test_it_creates_and_revokes(self): self.profile = Profile(user=self.bob, api_key="token12345") self.assertEqual(len(self.profile.api_key), 10) self.profile = Profile(user=self.bob, api_key="") self.assertEqual(len(self.profile.api_key), 0)
def setUp(self): super(CheckTokenTestCase, self).setUp() self.profile = Profile(user=self.alice) self.profile.token = make_password("secret-token") self.profile.save()
def setUp(self): super(CreateCheckTestCase, self).setUp() self.profile = Profile(user=self.alice, api_key="abc") self.profile.save()