コード例 #1
0
    def test_org_admin_can_accept_transfer(self):
        owner = UserFactory()
        admin = UserFactory()
        org = OrganizationFactory(members=[Member(user=admin, role='admin')])
        subject = VisibleDatasetFactory(owner=owner)
        transfer = TransferFactory(owner=owner, recipient=org, subject=subject)

        owner.reload()  # Needs updated metrics
        assert owner.get_metrics()['datasets'] == 1

        org.reload()  # Needs updated metrics
        assert org.get_metrics()['datasets'] == 0

        admin.reload()  # Needs updated metrics
        assert admin.get_metrics()['datasets'] == 0

        login_user(admin)
        transfer = accept_transfer(transfer)

        assert transfer.status == 'accepted'

        subject.reload()
        assert subject.organization == org
        assert subject.owner is None

        org.reload()
        assert org.get_metrics()['datasets'] == 1

        admin.reload()
        assert admin.get_metrics()['datasets'] == 0

        owner.reload()
        assert owner.get_metrics()['datasets'] == 0
コード例 #2
0
    def test_recipient_user_can_accept_transfer(self):
        owner = UserFactory()
        recipient = UserFactory()
        subject = VisibleDatasetFactory(owner=owner)
        transfer = TransferFactory(owner=owner,
                                   recipient=recipient,
                                   subject=subject)

        owner.reload()  # Needs updated metrics
        assert owner.get_metrics()['datasets'] == 1

        recipient.reload()  # Needs updated metrics
        assert recipient.get_metrics()['datasets'] == 0

        login_user(recipient)
        transfer = accept_transfer(transfer)

        assert transfer.status == 'accepted'

        subject.reload()
        assert subject.owner == recipient

        recipient.reload()
        assert recipient.get_metrics()['datasets'] == 1

        owner.reload()
        assert owner.get_metrics()['datasets'] == 0
コード例 #3
0
ファイル: test_user_api.py プロジェクト: revolunet/udata
    def test_follow_user(self):
        '''It should follow an user on POST'''
        user = self.login()
        to_follow = UserFactory()

        response = self.post(url_for('api.user_followers', id=to_follow.id))
        self.assert201(response)

        to_follow.count_followers()
        self.assertEqual(to_follow.get_metrics()['followers'], 1)

        nb_followers = Follow.objects.followers(to_follow).count()

        self.assertEqual(response.json['followers'], nb_followers)
        self.assertEqual(Follow.objects.following(to_follow).count(), 0)
        self.assertEqual(nb_followers, 1)
        self.assertIsInstance(
            Follow.objects.followers(to_follow).first(), Follow)
        self.assertEqual(Follow.objects.following(user).count(), 1)
        self.assertEqual(Follow.objects.followers(user).count(), 0)