Ejemplo n.º 1
0
    def test_update_user_on_authorize_callback(self):
        """Should only update specific field on authorize callback"""
        user = UserFactory()

        old_slug = user.slug

        with self.mock_authorize(slug=user.slug, is_superuser=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())

            user.reload()
            self.assertEqual(user.slug, old_slug)
            self.assertEqual(user.first_name, profile["first_name"])
            self.assertEqual(user.last_name, profile["last_name"])
            self.assertEqual(user.email, profile["email"])
            self.assertEqual(user.avatar_url, profile["profile"]["avatar"])

        self.assertEqual(len(User.objects), 1)
Ejemplo n.º 2
0
    def test_with_valid_user_self(self):
        Ownable, OwnableForm = self.factory()
        user = UserFactory()

        login_user(user)

        form = OwnableForm(MultiDict({
            'owner': str(user.id)
        }))

        self.assertEqual(form.owner.data, user)

        form.validate()
        self.assertEqual(form.errors, {})

        ownable = Ownable()
        form.populate_obj(ownable)
        self.assertEqual(ownable.owner, user)
Ejemplo n.º 3
0
    def test_with_organization_object_from_json(self):
        Ownable, OwnableForm = self.factory()
        user = UserFactory()
        member = Member(user=user, role='editor')
        org = OrganizationFactory(members=[member])

        login_user(user)

        form = OwnableForm.from_json({'organization': {'id': str(org.id)}})

        self.assertEqual(form.organization.data, org)

        form.validate()
        self.assertEqual(form.errors, {})

        ownable = Ownable()
        form.populate_obj(ownable)
        self.assertIsNone(ownable.owner)
        self.assertEqual(ownable.organization, org)
Ejemplo n.º 4
0
    def test_with_initial_and_both_member(self):
        Ownable, OwnableForm = self.factory()
        user = UserFactory()
        org = OrganizationFactory(members=[Member(user=user, role='editor')])
        neworg = OrganizationFactory(
            members=[Member(user=user, role='editor')])
        ownable = Ownable(organization=org)

        form = OwnableForm(MultiDict({'organization': str(neworg.id)}),
                           ownable)

        self.assertEqual(form.organization.data, neworg)

        login_user(user)
        form.validate()
        self.assertEqual(form.errors, {})

        form.populate_obj(ownable)
        self.assertIsNone(ownable.owner)
        self.assertEqual(ownable.organization, neworg)
Ejemplo n.º 5
0
    def test_admin_can_set_organization(self):
        Ownable, OwnableForm = self.factory()
        user = UserFactory()
        org = OrganizationFactory()
        ownable = Ownable(owner=user)

        login_user(AdminFactory())

        form = OwnableForm(MultiDict({'organization': str(org.id)}), ownable)

        self.assertEqual(form.owner.data, user)
        self.assertEqual(form.organization.data, org)

        self.assertTrue(form.validate())
        self.assertEqual(form.errors, {})

        self.assertIsNone(form.owner.data)
        self.assertEqual(form.organization.data, org)

        form.populate_obj(ownable)
        self.assertIsNone(ownable.owner)
        self.assertEqual(ownable.organization, org)