Ejemplo n.º 1
0
 def setUp(self):
     self.user = UserFactory()
     self.public_node = ProjectFactory(creator=self.user, is_public=True)
     self.private_node = ProjectFactory(creator=self.user, is_public=False)
     self.request = RequestFactory().post('/fake_path')
     self.view = views.SpamUserDeleteView
     self.view = setup_log_view(self.view, self.request, guid=self.user._id)
Ejemplo n.º 2
0
    def test_confirm_preprint_as_ham(self):
        view = views.PreprintConfirmHamView()
        view = setup_log_view(view, self.request, guid=self.preprint._id)
        view.delete(self.request)

        self.preprint.refresh_from_db()
        assert self.preprint.spam_status == 4
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 def setUp(self):
     super(TestNodeDeleteView, self).setUp()
     self.node = ProjectFactory()
     self.request = RequestFactory().post('/fake_path')
     self.view = NodeDeleteView()
     self.view = setup_log_view(self.view, self.request,
                                guid=self.node._id)
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
    def test_confirm_node_as_ham(self):
        view = NodeConfirmHamView()
        view = setup_log_view(view, self.request, guid=self.node._id)
        view.post(self.request)

        self.node.refresh_from_db()
        nt.assert_true(self.node.spam_status == 4)
Ejemplo n.º 7
0
    def test_confirm_registration_as_ham(self):
        view = NodeConfirmHamView()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        view.delete(self.request)

        self.registration.refresh_from_db()
        nt.assert_true(self.registration.spam_status == 4)
Ejemplo n.º 8
0
    def test_confirm_preprint_as_ham(self):
        view = views.PreprintConfirmHamView()
        view = setup_log_view(view, self.request, guid=self.preprint._id)
        view.delete(self.request)

        self.preprint.refresh_from_db()
        assert self.preprint.spam_status == 4
Ejemplo n.º 9
0
    def test_confirm_registration_as_ham(self):
        view = NodeConfirmHamView()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        view.delete(self.request)

        self.registration.refresh_from_db()
        nt.assert_true(self.registration.spam_status == 4)
Ejemplo n.º 10
0
 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, guid=node_id,
                           user_id=user_id)
     view.delete(self.request)
     mock_remove_contributor.assert_called_with(self.user_2, None, log=False)
Ejemplo n.º 11
0
    def test_reindex_preprint_elastic(self, mock_update_search, preprint, req):
        count = AdminLogEntry.objects.count()
        view = views.PreprintReindexElastic()
        view = setup_log_view(view, req, guid=preprint._id)
        view.delete(req)

        assert mock_update_search.called
        assert AdminLogEntry.objects.count() == count + 1
Ejemplo n.º 12
0
 def test_no_log(self):
     view = setup_log_view(self.view(),
                           self.request,
                           guid=self.preprint._id,
                           user_id=self.user_2.id)
     view.post(self.request)
     assert self.preprint.logs.latest(
     ).action != PreprintLog.CONTRIB_REMOVED
Ejemplo n.º 13
0
 def test_get_object(self):
     view = setup_log_view(self.view(),
                           self.request,
                           guid=self.preprint._id,
                           user_id=self.user._id)
     preprint, user = view.get_object()
     assert isinstance(preprint, Preprint)
     assert isinstance(user, OSFUser)
Ejemplo n.º 14
0
 def test_integration_remove_contributor(self):
     assert self.user_2 in self.preprint.contributors
     view = setup_log_view(self.view(), self.request, guid=self.preprint._id,
                           user_id=self.user_2._id)
     count = AdminLogEntry.objects.count()
     view.delete(self.request)
     assert self.user_2 not in self.preprint.contributors
     assert AdminLogEntry.objects.count() == count + 1
Ejemplo n.º 15
0
    def test_reindex_node_elastic(self, mock_update_search):
        count = AdminLogEntry.objects.count()
        view = NodeReindexElastic()
        view = setup_log_view(view, self.request, guid=self.node._id)
        view.delete(self.request)

        nt.assert_true(mock_update_search.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 16
0
 def test_integration_remove_contributor(self):
     assert self.user_2 in self.preprint.contributors
     view = setup_log_view(self.view(), self.request, guid=self.preprint._id,
                           user_id=self.user_2._id)
     count = AdminLogEntry.objects.count()
     view.delete(self.request)
     assert self.user_2 not in self.preprint.contributors
     assert AdminLogEntry.objects.count() == count + 1
Ejemplo n.º 17
0
    def test_reindex_preprint_elastic(self, mock_update_search, preprint, req):
        count = AdminLogEntry.objects.count()
        view = views.PreprintReindexElastic()
        view = setup_log_view(view, req, guid=preprint._id)
        view.delete(req)

        assert mock_update_search.called
        assert AdminLogEntry.objects.count() == count + 1
Ejemplo n.º 18
0
    def test_reindex_node_elastic(self):
        count = AdminLogEntry.objects.count()
        view = NodeReindexElastic()
        view = setup_log_view(view, self.request, guid=self.node._id)
        view.delete(self.request)

        nt.assert_true(self.mock_reindex_elastic.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 19
0
 def test_integration_remove_contributor(self):
     nt.assert_in(self.user_2, self.node.contributors)
     view = setup_log_view(self.view(), self.request, guid=self.node._id,
                           user_id=self.user_2._id)
     count = AdminLogEntry.objects.count()
     view.delete(self.request)
     nt.assert_not_in(self.user_2, self.node.contributors)
     nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 20
0
    def setUp(self):
        self.user = UserFactory()
        self.request = RequestFactory().post('/fake_path')
        self.view = views.HamUserRestoreView
        self.view = setup_log_view(self.view, self.request, guid=self.user._id)

        self.spam_confirmed, created = Tag.objects.get_or_create(name='spam_confirmed')
        self.ham_confirmed, created = Tag.objects.get_or_create(name='ham_confirmed')
Ejemplo n.º 21
0
 def test_no_log(self):
     view = setup_log_view(self.view(),
                           self.request,
                           guid=self.node._id,
                           user_id=self.user_2.id)
     view.post(self.request)
     nt.assert_not_equal(self.node.logs.latest().action,
                         NodeLog.CONTRIB_REMOVED)
Ejemplo n.º 22
0
    def test_reindex_registration_elastic(self, mock_update_node):
        count = AdminLogEntry.objects.count()
        view = NodeReindexElastic()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        view.post(self.request)

        nt.assert_true(mock_update_node.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 23
0
    def test_reindex_registration_elastic(self, mock_update_node):
        count = AdminLogEntry.objects.count()
        view = NodeReindexElastic()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        view.delete(self.request)

        nt.assert_true(mock_update_node.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 24
0
 def test_get_object(self):
     view = setup_log_view(self.view(),
                           self.request,
                           guid=self.node._id,
                           user_id=self.user._id)
     node, user = view.get_object()
     nt.assert_is_instance(node, Node)
     nt.assert_is_instance(user, OSFUser)
Ejemplo n.º 25
0
    def test_reindex_user_elastic(self, mock_reindex_elastic):
        count = AdminLogEntry.objects.count()
        view = views.UserReindexElastic()
        view = setup_log_view(view, self.request, guid=self.user._id)
        view.delete(self.request)

        nt.assert_true(mock_reindex_elastic.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 26
0
 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 = AdminLogEntry.objects.count()
     view.delete(self.request)
     nt.assert_not_in(self.user_2, self.node.contributors)
     nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 27
0
    def setUp(self):
        super(TestRemove2Factor, self).setUp()
        self.user = AuthUserFactory()
        self.request = RequestFactory().post('/fake_path')
        self.view = views.User2FactorDeleteView
        self.setup_view = setup_log_view(self.view(), self.request, guid=self.user._id)

        self.url = reverse('users:remove2factor', kwargs={'guid': self.user._id})
Ejemplo n.º 28
0
 def setUp(self):
     super(TestNodeDeleteView, self).setUp()
     self.node = ProjectFactory()
     self.request = RequestFactory().post('/fake_path')
     self.plain_view = NodeDeleteView
     self.view = setup_log_view(self.plain_view(),
                                self.request,
                                guid=self.node._id)
     self.url = reverse('nodes:remove', kwargs={'guid': self.node._id})
Ejemplo n.º 29
0
    def test_reindex_registration_share(self):
        count = AdminLogEntry.objects.count()
        view = NodeReindexShare()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        view.delete(self.request)

        nt.assert_false(self.mock_reindex_node.called)
        nt.assert_true(self.mock_reindex_registration.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 30
0
    def setUp(self):
        super(TestNodeDeleteView, self).setUp()
        self.node = ProjectFactory()
        self.request = RequestFactory().post('/fake_path')
        self.plain_view = NodeDeleteView
        self.view = setup_log_view(self.plain_view(), self.request,
                                   guid=self.node._id)

        self.url = reverse('nodes:remove', kwargs={'guid': self.node._id})
Ejemplo n.º 31
0
 def test_remove_contributor(self):
     user_id = self.user_2.id
     node_id = self.node._id
     view = setup_log_view(self.view(),
                           self.request,
                           guid=node_id,
                           user_id=user_id)
     view.post(self.request)
     assert not self.node.contributors.filter(id=user_id)
Ejemplo n.º 32
0
    def test_confirm_preprint_as_ham(self, mock_akismet):
        request = RequestFactory().post('/fake_path')
        user = AuthUserFactory()
        preprint = PreprintFactory(creator=user)
        view = views.PreprintConfirmHamView()
        view = setup_log_view(view, request, guid=preprint._id)
        view.post(request)

        preprint.refresh_from_db()
        assert preprint.spam_status == 4
Ejemplo n.º 33
0
    def test_reindex_registration_share(self, mock_update_share, mock_format_registration, mock_format_node):
        count = AdminLogEntry.objects.count()
        view = NodeReindexShare()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        view.delete(self.request)

        nt.assert_true(mock_update_share.called)
        nt.assert_false(mock_format_node.called)
        nt.assert_true(mock_format_registration.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 34
0
    def test_confirm_registration_as_ham(self):
        view = NodeConfirmHamView()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        resp = view.post(self.request)

        nt.assert_true(resp.status_code == 302)

        self.registration.refresh_from_db()
        nt.assert_false(self.registration.is_public)
        nt.assert_true(self.registration.spam_status == 4)
    def test_post_id(self):
        request = RequestFactory().post('/fake_path',
                                        data={
                                            'id': self.group._id,
                                            'name': ''
                                        })
        view = setup_log_view(self.view, request)

        redirect = view.post(request)
        assert redirect.url == '/osf_groups/{}/'.format(self.group._id)
    def test_post_name(self):
        request = RequestFactory().post('/fake_path',
                                        data={
                                            'id': '',
                                            'name': 'Brian'
                                        })
        view = setup_log_view(self.view, request)

        redirect = view.post(request)
        assert redirect.url == '/osf_groups/?name=Brian'
Ejemplo n.º 37
0
    def setUp(self):
        super(TestPreprintDeleteView, self).setUp()
        self.user = AuthUserFactory()
        self.preprint = PreprintFactory(creator=self.user)
        self.request = RequestFactory().post('/fake_path')
        self.plain_view = views.PreprintDeleteView
        self.view = setup_log_view(self.plain_view(), self.request,
                                   guid=self.preprint._id)

        self.url = reverse('preprints:remove', kwargs={'guid': self.preprint._id})
Ejemplo n.º 38
0
    def test_get_default_queryset(self):
        view = setup_log_view(self.view, self.request)

        queryset = view.get_queryset()

        nt.assert_equal(len(queryset), 3)

        nt.assert_in(self.group, queryset)
        nt.assert_in(self.group2, queryset)
        nt.assert_in(self.group3, queryset)
Ejemplo n.º 39
0
    def test_get_queryset_by_name(self):
        request = RequestFactory().post('/fake_path/?name=Brian')
        view = setup_log_view(self.view, request)

        queryset = view.get_queryset()

        nt.assert_equal(len(queryset), 2)

        nt.assert_in(self.group, queryset)
        nt.assert_in(self.group2, queryset)
Ejemplo n.º 40
0
 def test_do_not_remove_last_admin(self):
     assert len(list(self.preprint.get_admin_contributors(self.preprint.contributors))) == 1
     view = setup_log_view(self.view(), self.request, guid=self.preprint._id,
                           user_id=self.user._id)
     count = AdminLogEntry.objects.count()
     view.delete(self.request)
     self.preprint.reload()  # Reloads instance to show that nothing was removed
     assert len(list(self.preprint.contributors)) == 2
     assert len(list(self.preprint.get_admin_contributors(self.preprint.contributors))) == 1
     assert AdminLogEntry.objects.count() == count
Ejemplo n.º 41
0
    def setUp(self):
        super(TestPreprintDeleteView, self).setUp()
        self.user = AuthUserFactory()
        self.preprint = PreprintFactory(creator=self.user)
        self.request = RequestFactory().post('/fake_path')
        self.plain_view = views.PreprintDeleteView
        self.view = setup_log_view(self.plain_view(), self.request,
                                   guid=self.preprint._id)

        self.url = reverse('preprints:remove', kwargs={'guid': self.preprint._id})
Ejemplo n.º 42
0
 def test_do_not_remove_last_admin(self):
     assert len(list(self.preprint.get_admin_contributors(self.preprint.contributors))) == 1
     view = setup_log_view(self.view(), self.request, guid=self.preprint._id,
                           user_id=self.user._id)
     count = AdminLogEntry.objects.count()
     view.delete(self.request)
     self.preprint.reload()  # Reloads instance to show that nothing was removed
     assert len(list(self.preprint.contributors)) == 2
     assert len(list(self.preprint.get_admin_contributors(self.preprint.contributors))) == 1
     assert AdminLogEntry.objects.count() == count
Ejemplo n.º 43
0
 def test_integration_remove_contributor(self):
     patch_messages(self.request)
     nt.assert_in(self.user_2, self.node.contributors)
     view = setup_log_view(self.view(),
                           self.request,
                           guid=self.node._id,
                           user_id=self.user_2.id)
     count = AdminLogEntry.objects.count()
     view.post(self.request)
     nt.assert_not_in(self.user_2, self.node.contributors)
     nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 44
0
    def test_reindex_preprint_share(self, mock_reindex_preprint, preprint, req):
        preprint.provider.access_token = 'totally real access token I bought from a guy wearing a trenchcoat in the summer'
        preprint.provider.save()

        count = AdminLogEntry.objects.count()
        view = views.PreprintReindexShare()
        view = setup_log_view(view, req, guid=preprint._id)
        view.delete(req)

        assert mock_reindex_preprint.called
        assert AdminLogEntry.objects.count() == count + 1
Ejemplo n.º 45
0
    def test_reindex_preprint_share(self, mock_reindex_preprint):
        self.preprint.provider.access_token = 'totally real access token I bought from a guy wearing a trenchcoat in the summer'
        self.preprint.provider.save()

        count = AdminLogEntry.objects.count()
        view = views.PreprintReindexShare()
        view = setup_log_view(view, self.request, guid=self.preprint._id)
        view.delete(self.request)

        nt.assert_true(mock_reindex_preprint.called)
        nt.assert_equal(AdminLogEntry.objects.count(), count + 1)
Ejemplo n.º 46
0
 def test_remove_stuck_registration_with_an_addon(self):
     # Prevents circular import that prevents admin app from starting up
     from django.contrib.messages.storage.fallback import FallbackStorage
     self.registration.add_addon('github', auth=Auth(self.user))
     view = RemoveStuckRegistrationsView()
     view = setup_log_view(view, self.request, guid=self.registration._id)
     setattr(self.request, 'session', 'session')
     messages = FallbackStorage(self.request)
     setattr(self.request, '_messages', messages)
     view.post(self.request)
     self.registration.refresh_from_db()
     nt.assert_true(self.registration.is_deleted)
Ejemplo n.º 47
0
    def test_get_queryset(self):

        self.node.set_title('New Title', auth=self.auth, save=True)

        view = AdminNodeLogView()
        view = setup_log_view(view, self.request, guid=self.node._id)

        logs = view.get_queryset()

        log_entry = logs.first()
        nt.assert_true(log_entry.action == 'edit_title')
        nt.assert_true(log_entry.params['title_new'] == u'New Title')
Ejemplo n.º 48
0
    def test_get_context_data(self):

        self.node.set_title('New Title', auth=self.auth, save=True)

        view = AdminNodeLogView()
        view = setup_log_view(view, self.request, guid=self.node._id)

        logs = view.get_context_data()['logs']
        log_entry = logs[0][0]
        log_params = logs[0][1]
        nt.assert_true(log_entry.action == NodeLog.EDITED_TITLE)
        nt.assert_true((u'title_new', u'New Title') in log_params)
        nt.assert_true((u'node', self.node._id) in log_params)
Ejemplo n.º 49
0
    def test_restart_stuck_registration(self):
        view = RestartStuckRegistrationsView()
        view = setup_log_view(view, self.request, guid=self.registration._id)
        nt.assert_equal(self.registration.archive_job.status, u'INITIATED')
        from django.contrib.messages.storage.fallback import FallbackStorage

        # django.contrib.messages has a bug which effects unittests
        # more info here -> https://code.djangoproject.com/ticket/17971
        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

        view.post(self.request)

        nt.assert_equal(self.registration.archive_job.status, u'SUCCESS')
Ejemplo n.º 50
0
    def test_merge_user(self, mock_merge_user):
        user = UserFactory()
        user_merged = UserFactory()

        view = views.UserMergeAccounts()
        view = setup_log_view(view, self.request, guid=user._id)

        invalid_form = MergeUserForm(data={'user_guid_to_be_merged': 'Not a valid Guid'})
        valid_form = MergeUserForm(data={'user_guid_to_be_merged': user_merged._id})

        nt.assert_false(invalid_form.is_valid())
        nt.assert_true(valid_form.is_valid())

        view.form_valid(valid_form)
        nt.assert_true(mock_merge_user.called_with())
Ejemplo n.º 51
0
    def test_remove_stuck_registration(self):
        # Prevents circular import that prevents admin app from starting up
        from django.contrib.messages.storage.fallback import FallbackStorage
        view = RemoveStuckRegistrationsView()
        view = setup_log_view(view, self.request, guid=self.registration._id)

        # django.contrib.messages has a bug which effects unittests
        # more info here -> https://code.djangoproject.com/ticket/17971
        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)

        view.post(self.request)

        self.registration.refresh_from_db()
        nt.assert_true(self.registration.is_deleted)
Ejemplo n.º 52
0
 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, guid=self.node._id,
                           user_id=self.user._id)
     count = AdminLogEntry.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(AdminLogEntry.objects.count(), count)
Ejemplo n.º 53
0
    def test_get_logs_for_children(self):
        """ The "create component" action is actually logged as a create_project action
        for its child with a log parameter 'node' having its guid as a value. We have to ensure
        that all the components a parent has created appear in its admin app logs, so we can't just
         do node.logs.all(), that will leave out component creation.
        """

        component = ProjectFactory(creator=self.user, parent=self.node)
        component.save()

        view = AdminNodeLogView()
        view = setup_log_view(view, self.request, guid=self.node._id)

        logs = view.get_context_data()['logs']
        log_entry = logs[0][0]
        log_params = logs[0][1]

        nt.assert_true(log_entry.action == NodeLog.PROJECT_CREATED)
        nt.assert_true(log_entry.node._id == component._id)
        nt.assert_true(('node', component._id) in log_params)
Ejemplo n.º 54
0
    def test_get_object(self):
        view = RemoveStuckRegistrationsView()
        view = setup_log_view(view, self.request, guid=self.registration._id)

        nt.assert_true(self.registration, view.get_object())
Ejemplo n.º 55
0
    def test_get_object(self):

        view = AdminNodeLogView()
        view = setup_log_view(view, self.request, guid=self.node._id)

        nt.assert_true(self.node, view.get_object())
Ejemplo n.º 56
0
 def test_no_log(self):
     view = setup_log_view(self.view(), self.request, guid=self.node._id,
                           user_id=self.user_2._id)
     view.delete(self.request)
     nt.assert_not_equal(self.node.logs.latest().action, NodeLog.CONTRIB_REMOVED)