def test_raise_if_banned(self): """pipeline raises if user's IP is banned""" Ban.objects.create(banned_value=self.user.username, check_type=Ban.USERNAME) try: validate_user_not_banned(MockStrategy(), {}, GithubOAuth2, self.user) self.fail("validate_ip_not_banned should raise SocialAuthBanned") except SocialAuthBanned as e: self.assertEqual(e.ban.user, self.user) self.assertTrue(isinstance(e.ban, BanCache))
def test_exclude_staff(self): """pipeline excludes staff from bans""" self.user.is_staff = True self.user.save() Ban.objects.create(banned_value=self.user.username, check_type=Ban.USERNAME) result = validate_user_not_banned(MockStrategy(), {}, GithubOAuth2, self.user) self.assertIsNone(result)
def test_skip_if_user_not_set(self): """pipeline step is skipped if no user was passed""" result = validate_user_not_banned(None, {}, GithubOAuth2) self.assertIsNone(result)