def test_auto_activiate_if_qualified_after_signup(self, mock_vouched): """Users qualified after sign-up should be auto-activated on sign-in""" mock_vouched.return_value = False sociallogin = SocialLogin(user=self.user) self.user.is_active = True user_signed_up.send(sender=self.user.__class__, request=None, user=self.user) self.assertEqual(False, self.user.is_active) pre_social_login.send(sender=SocialLogin, request=None, sociallogin=sociallogin) self.assertEqual(False, self.user.is_active) profile = UserProfile.objects.get_profile(self.user) self.assertEqual(True, profile.invite_pending) mock_vouched.return_value = True pre_social_login.send(sender=SocialLogin, request=None, sociallogin=sociallogin) self.assertEqual(True, self.user.is_active) profile = UserProfile.objects.get_profile(self.user) self.assertEqual(False, profile.invite_pending)
def test_auto_activate_after_settings_change(self, mock_vouched): """Pending invitations should be auto-activated on sign-in after invite mode turned off""" mock_vouched.return_value = False sociallogin = SocialLogin(user=self.user) with self.settings(ACCOUNT_INVITE_ONLY_MODE=True): self.user.is_active = True user_signed_up.send(sender=self.user.__class__, request=None, user=self.user) self.assertEqual(False, self.user.is_active) profile = UserProfile.objects.get_profile(self.user) self.assertEqual(True, profile.invite_pending) pre_social_login.send(sender=SocialLogin, request=None, sociallogin=sociallogin) self.assertEqual(False, self.user.is_active) profile = UserProfile.objects.get_profile(self.user) self.assertEqual(True, profile.invite_pending) with self.settings(ACCOUNT_INVITE_ONLY_MODE=False): pre_social_login.send(sender=SocialLogin, request=None, sociallogin=sociallogin) self.assertEqual(True, self.user.is_active) profile = UserProfile.objects.get_profile(self.user) self.assertEqual(False, profile.invite_pending)
def test_pre_social_login(self): """Test the pre-social-login Allauth signal handling.""" mock_obj = mock.Mock() discord_login = SocialLogin(self.django_user, self.social_user) github_login = SocialLogin(self.django_user, self.social_user_github) unmapped_login = SocialLogin(self.django_user, self.social_unmapped) with mock.patch.object(AllauthSignalListener, "_apply_groups", mock_obj): AllauthSignalListener() # Don't attempt to apply groups if the user doesn't have a linked Discord account pre_social_login.send(SocialLogin, sociallogin=github_login) mock_obj.assert_not_called() # Don't attempt to apply groups if the user hasn't joined the Discord server pre_social_login.send(SocialLogin, sociallogin=unmapped_login) mock_obj.assert_not_called() # Attempt to apply groups if everything checks out pre_social_login.send(SocialLogin, sociallogin=discord_login) mock_obj.assert_called_with(self.discord_user, self.social_user)