当前位置: 首页>>代码示例>>Python>>正文


Python ProjectFactory.get_admin_contributors方法代码示例

本文整理汇总了Python中tests.factories.ProjectFactory.get_admin_contributors方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.get_admin_contributors方法的具体用法?Python ProjectFactory.get_admin_contributors怎么用?Python ProjectFactory.get_admin_contributors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.factories.ProjectFactory的用法示例。


在下文中一共展示了ProjectFactory.get_admin_contributors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestRemoveContributor

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_admin_contributors [as 别名]
class TestRemoveContributor(AdminTestCase):
    def setUp(self):
        super(TestRemoveContributor, self).setUp()
        self.user = AuthUserFactory()
        self.node = ProjectFactory(creator=self.user)
        self.user_2 = AuthUserFactory()
        self.node.add_contributor(self.user_2)
        self.node.save()
        self.view = NodeRemoveContributorView()
        self.request = RequestFactory().post('/fake_path')

    def test_get_object(self):
        view = setup_log_view(self.view, self.request, node_id=self.node._id,
                              user_id=self.user._id)
        node, user = view.get_object()
        nt.assert_is_instance(node, Node)
        nt.assert_is_instance(user, User)

    @mock.patch('admin.nodes.views.Node.remove_contributor')
    def test_remove_contributor(self, mock_remove_contributor):
        user_id = self.user_2._id
        node_id = self.node._id
        view = setup_log_view(self.view, self.request, node_id=node_id,
                              user_id=user_id)
        view.delete(self.request)
        mock_remove_contributor.assert_called_with(self.user_2, None, log=False)

    def test_integration_remove_contributor(self):
        nt.assert_in(self.user_2, self.node.contributors)
        view = setup_log_view(self.view, self.request, node_id=self.node._id,
                              user_id=self.user_2._id)
        count = OSFLogEntry.objects.count()
        view.delete(self.request)
        nt.assert_not_in(self.user_2, self.node.contributors)
        nt.assert_equal(OSFLogEntry.objects.count(), count + 1)

    def test_do_not_remove_last_admin(self):
        nt.assert_equal(
            len(list(self.node.get_admin_contributors(self.node.contributors))),
            1
        )
        view = setup_log_view(self.view, self.request, node_id=self.node._id,
                              user_id=self.user._id)
        count = OSFLogEntry.objects.count()
        view.delete(self.request)
        self.node.reload()  # Reloads instance to show that nothing was removed
        nt.assert_equal(len(list(self.node.contributors)), 2)
        nt.assert_equal(
            len(list(self.node.get_admin_contributors(self.node.contributors))),
            1
        )
        nt.assert_equal(OSFLogEntry.objects.count(), count)

    def test_no_log(self):
        view = setup_log_view(self.view, self.request, node_id=self.node._id,
                              user_id=self.user_2._id)
        view.delete(self.request)
        nt.assert_not_equal(self.node.logs[-1].action, NodeLog.CONTRIB_REMOVED)
开发者ID:545zhou,项目名称:osf.io,代码行数:60,代码来源:test_views.py


注:本文中的tests.factories.ProjectFactory.get_admin_contributors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。