Esempio n. 1
0
    def test_log_inactive_user_on_authorize_callback(self):
        """Should log the user with the admin role in on authorize callback"""
        user = UserFactory(active=False)

        with self.mock_authorize(slug=user.slug, is_active=True) as (profile, client):
            response = self.get(url_for("youckan.authorized", code="code"), client=client)
            self.assertRedirects(response, url_for("site.home"))
            self.assertIn("youckan.token", session)
            self.assertTrue(current_user.is_authenticated())
            self.assertTrue(current_user.is_active())

        self.assertEqual(len(User.objects), 1)
Esempio n. 2
0
    def test_fetch_token_and_create_user_on_authorize_callback(self):
        """Should create the user on authorize callback"""
        with self.mock_authorize() as (profile, client):
            response = self.get(url_for("youckan.authorized", code="code"), client=client)

            self.assertRedirects(response, url_for("site.home"))
            self.assertIn("youckan.token", session)
            self.assertTrue(current_user.is_authenticated())
            self.assertTrue(current_user.is_active())
            self.assertEqual(current_user.slug, profile["slug"])
            self.assertEqual(current_user.first_name, profile["first_name"])
            self.assertEqual(current_user.last_name, profile["last_name"])
            self.assertEqual(current_user.email, profile["email"])
            self.assertEqual(current_user.has_role("admin"), profile["is_superuser"])
            self.assertEqual(current_user.avatar_url, profile["profile"]["avatar"])

        self.assertEqual(len(User.objects), 1)