コード例 #1
0
ファイル: test_views.py プロジェクト: DanielSBrown/osf.io
 def test_get_spam(self):
     guid = self.user_1._id
     request = RequestFactory().get('/fake_path')
     view = UserSpamList()
     view = setup_view(view, request, user_id=guid)
     res = list(view.get_queryset())
     nt.assert_equal(len(res), 4)
コード例 #2
0
 def setUp(self):
     super(TestSpamListView, self).setUp()
     Comment.remove()
     self.project = ProjectFactory(is_public=True)
     self.user_1 = AuthUserFactory()
     self.user_2 = AuthUserFactory()
     self.project.add_contributor(self.user_1)
     self.project.add_contributor(self.user_2)
     self.project.save()
     self.user_1.save()
     self.user_2.save()
     date = datetime.utcnow()
     self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_1.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=5))
     self.comment_2.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=4))
     self.comment_3.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=3))
     self.comment_4.report_abuse(user=self.user_2, save=True, category="spam", date=date - timedelta(seconds=2))
     self.comment_5.report_abuse(user=self.user_1, save=True, category="spam", date=date - timedelta(seconds=1))
     self.comment_6.report_abuse(user=self.user_1, save=True, category="spam")
     self.request = RequestFactory().get("/fake_path")
     self.view = SpamList()
     self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
コード例 #3
0
ファイル: test_views.py プロジェクト: erinspace/osf.io
    def test_checkout_checkin_files(self):
        self.draft.submit_for_review(self.user, {}, save=True)
        request = RequestFactory().get('/fake_path')
        view = DraftDetailView()
        view = setup_user_view(view, request, self.admin_user,
                               draft_pk=self.draft._id)
        view.checkout_files(self.draft)
        for q, f in self.d_of_qs.iteritems():
            f.refresh_from_db()
            nt.assert_equal(self.admin_user, f.checkout)

        # test user attempt force checkin
        with nt.assert_raises(file_exceptions.FileNodeCheckedOutError):
            self.d_of_qs['q7'].check_in_or_out(self.user, self.admin_user)

        # test delete draft returns files
        utils.checkin_files(self.draft)

        view2 = DraftFormView()
        view2 = setup_view(view2, request, draft_pk=self.draft._id)
        view2.checkin_files(self.draft)

        for q, f in self.d_of_qs.iteritems():
            f.refresh_from_db()
            nt.assert_equal(None, f.checkout)
コード例 #4
0
ファイル: test_views.py プロジェクト: erinspace/osf.io
    def setUp(self, mock_archive):
        super(TestDraftListView, self).setUp()
        self.user = AuthUserFactory()
        self.schema = utils.draft_reg_util()
        self.dr1 = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.dr1.submit_for_review(self.user, {}, save=True)
        self.dr2 = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.dr2.submit_for_review(self.user, {}, save=True)
        # Simply here to NOT be returned when get_queryset is called
        self.unsubmitted_prereg = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=self.schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.unsubmitted_prereg.register(Auth(self.user), save=True)
        self.request = RequestFactory().get('/fake_path')
        self.plain_view = DraftListView
        self.view = setup_view(self.plain_view(), self.request)

        self.url = reverse('pre_reg:prereg')
コード例 #5
0
 def setUp(self):
     super(TestUserSpamListView, self).setUp()
     self.project = ProjectFactory(is_public=True)
     self.user_1 = AuthUserFactory()
     self.user_2 = AuthUserFactory()
     self.project.add_contributor(self.user_1)
     self.project.add_contributor(self.user_2)
     self.project.save()
     self.user_1.save()
     self.user_2.save()
     self.comment_1 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_2 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_3 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_4 = CommentFactory(node=self.project, user=self.user_1)
     self.comment_5 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_6 = CommentFactory(node=self.project, user=self.user_2)
     self.comment_1.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_2.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_3.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_4.report_abuse(user=self.user_2, save=True, category="spam")
     self.comment_5.report_abuse(user=self.user_1, save=True, category="spam")
     self.comment_6.report_abuse(user=self.user_1, save=True, category="spam")
     self.request = RequestFactory().get("/fake_path")
     self.view = UserSpamList()
     self.view = setup_view(self.view, self.request, user_id=self.user_1._id)
コード例 #6
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
 def setUp(self):
     super(TestResetPasswordView, self).setUp()
     self.user = UserFactory()
     self.request = RequestFactory().get('/fake_path')
     self.request.user = self.user
     self.plain_view = views.ResetPasswordView
     self.view = setup_view(self.plain_view(), self.request, guid=self.user._id)
コード例 #7
0
 def test_load_data(self):
     node = ProjectFactory()
     guid = node._id
     request = RequestFactory().get('/fake_path')
     view = NodeView()
     view = setup_view(view, request, guid=guid)
     res = view.get_object()
     nt.assert_is_instance(res, dict)
コード例 #8
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
 def test_load_data(self):
     user = UserFactory()
     guid = user._id
     request = RequestFactory().get('/fake_path')
     view = views.UserView()
     view = setup_view(view, request, guid=guid)
     res = view.get_object()
     nt.assert_is_instance(res, dict)
コード例 #9
0
ファイル: test_views.py プロジェクト: baylee-d/osf.io
 def test_reset_password_context(self):
     user = UserFactory()
     guid = user._id
     request = RequestFactory().get('/fake_path')
     view = ResetPasswordView()
     view = setup_view(view, request, guid=guid)
     res = view.get_context_data()
     nt.assert_is_instance(res, dict)
     nt.assert_in((user.emails[0], user.emails[0]), view.initial['emails'])
コード例 #10
0
 def test_name_data(self):
     node = ProjectFactory()
     guid = node._id
     request = RequestFactory().get('/fake_path')
     view = NodeView()
     view = setup_view(view, request, guid=guid)
     temp_object = view.get_object()
     view.object = temp_object
     res = view.get_context_data()
     nt.assert_equal(res[NodeView.context_object_name], temp_object)
コード例 #11
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
 def test_name_data(self):
     user = UserFactory()
     guid = user._id
     request = RequestFactory().get('/fake_path')
     view = views.UserView()
     view = setup_view(view, request, guid=guid)
     temp_object = view.get_object()
     view.object = temp_object
     res = view.get_context_data()
     nt.assert_equal(res[views.UserView.context_object_name], temp_object)
コード例 #12
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
    def test_search_user_list_case_insensitive(self):
        view = views.UserSearchList()
        view = setup_view(view, self.request)
        view.kwargs = {'name': 'hardy'}

        results = view.get_queryset()

        nt.assert_equal(len(results), 3)
        for user in results:
            nt.assert_in('Hardy', user.fullname)
コード例 #13
0
 def test_get_context_data(self):
     view = SpamDetail()
     view = setup_view(view, self.request, spam_id=self.comment._id)
     res = view.get_context_data()
     nt.assert_equal(res['status'], '1')
     nt.assert_equal(res['page_number'], '1')
     nt.assert_is_instance(res['comment'], dict)
     nt.assert_equal(res['SPAM_STATUS'].UNKNOWN, SpamStatus.UNKNOWN)
     nt.assert_equal(res['SPAM_STATUS'].SPAM, SpamStatus.SPAM)
     nt.assert_equal(res['SPAM_STATUS'].HAM, SpamStatus.HAM)
     nt.assert_equal(res['SPAM_STATUS'].FLAGGED, SpamStatus.FLAGGED)
コード例 #14
0
ファイル: test_views.py プロジェクト: 545zhou/osf.io
 def test_get_context_data(self):
     view = SpamDetail()
     view = setup_view(view, self.request, spam_id=self.comment._id)
     res = view.get_context_data()
     nt.assert_equal(res['status'], '1')
     nt.assert_equal(res['page_number'], '1')
     nt.assert_is_instance(res['comment'], dict)
     nt.assert_equal(res['UNKNOWN'], Comment.UNKNOWN)
     nt.assert_equal(res['SPAM'], Comment.SPAM)
     nt.assert_equal(res['HAM'], Comment.HAM)
     nt.assert_equal(res['FLAGGED'], Comment.FLAGGED)
コード例 #15
0
 def test_get_context_data(self):
     view = SpamDetail()
     view = setup_view(view, self.request, spam_id=self.comment._id)
     res = view.get_context_data()
     nt.assert_equal(res["status"], "1")
     nt.assert_equal(res["page_number"], "1")
     nt.assert_is_instance(res["comment"], dict)
     nt.assert_equal(res["UNKNOWN"], Comment.UNKNOWN)
     nt.assert_equal(res["SPAM"], Comment.SPAM)
     nt.assert_equal(res["HAM"], Comment.HAM)
     nt.assert_equal(res["FLAGGED"], Comment.FLAGGED)
コード例 #16
0
ファイル: test_views.py プロジェクト: alexschiller/osf.io
 def test_checkin_files(self):
     self.draft.submit_for_review(self.user, {}, save=True)
     request = RequestFactory().get('/fake_path')
     view = DraftDetailView()
     view = setup_user_view(view, request, self.admin_user,
                            draft_pk=self.draft._id)
     view.checkout_files(self.draft)
     view2 = DraftFormView()
     view2 = setup_view(view2, request, draft_pk=self.draft._id)
     view2.checkin_files(self.draft)
     for q, f in self.d_of_qs.iteritems():
         nt.assert_equal(None, f.checkout)
コード例 #17
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
    def test_get_user_confirmation_link(self):
        user = UnconfirmedUserFactory()
        request = RequestFactory().get('/fake_path')
        view = views.GetUserConfirmationLink()
        view = setup_view(view, request, guid=user._id)

        user_token = user.email_verifications.keys()[0]
        ideal_link_path = '/confirm/{}/{}/'.format(user._id, user_token)
        link = view.get_link(user)
        link_path = str(furl.furl(link).path)

        nt.assert_equal(link_path, ideal_link_path)
コード例 #18
0
ファイル: test_views.py プロジェクト: 545zhou/osf.io
 def setUp(self):
     super(TestCommentUpdateView, self).setUp()
     self.user = AuthUserFactory()
     self.dr1 = DraftRegistrationFactory(
         initiator=self.user,
         registration_schema=utils.draft_reg_util(),
         registration_metadata=utils.SCHEMA_DATA
     )
     self.dr1.submit_for_review(self.user, {}, save=True)
     self.request = RequestFactory().post('/fake_path', data={'blah': 'arg'})
     self.request.user = UserFactory()
     self.view = CommentUpdateView()
     self.view = setup_view(self.view, self.request, draft_pk=self.dr1._id)
コード例 #19
0
ファイル: test_views.py プロジェクト: 545zhou/osf.io
 def setUp(self):
     super(TestDraftDetailView, self).setUp()
     self.user = AuthUserFactory()
     schema = utils.draft_reg_util()
     self.dr1 = DraftRegistrationFactory(
         initiator=self.user,
         registration_schema=schema,
         registration_metadata=utils.SCHEMA_DATA
     )
     self.dr1.submit_for_review(self.user, {}, save=True)
     self.request = RequestFactory().get('/fake_path')
     self.view = DraftDetailView()
     self.view = setup_view(self.view, self.request, draft_pk=self.dr1._id)
コード例 #20
0
ファイル: test_views.py プロジェクト: icereval/osf.io
    def test_confirm_ham(self, preprint, superuser):
        request = RequestFactory().post('/fake_path')
        request.user = superuser

        view = views.PreprintConfirmHamView()
        view = setup_view(view, request, guid=preprint._id)
        view.delete(request)

        preprint.refresh_from_db()
        preprint.node.refresh_from_db()

        assert preprint.spam_status == SpamStatus.HAM
        assert preprint.node.spam_status == SpamStatus.HAM
        assert preprint.node.is_public
コード例 #21
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
    def test_get_password_reset_link(self):
        user = UnconfirmedUserFactory()
        request = RequestFactory().get('/fake_path')
        view = views.GetPasswordResetLink()
        view = setup_view(view, request, guid=user._id)

        link = view.get_link(user)

        user_token = user.verification_key_v2.get('token')
        nt.assert_is_not_none(user_token)

        ideal_link_path = '/resetpassword/{}/{}'.format(user._id, user_token)
        link_path = str(furl.furl(link).path)

        nt.assert_equal(link_path, ideal_link_path)
コード例 #22
0
ファイル: test_views.py プロジェクト: icereval/osf.io
    def test_confirm_spam(self, flagged_preprint, superuser):
        request = RequestFactory().post('/fake_path')
        request.user = superuser

        view = views.PreprintConfirmSpamView()
        view = setup_view(view, request, guid=flagged_preprint._id)
        view.delete(request)

        assert flagged_preprint.node.is_public

        flagged_preprint.refresh_from_db()
        flagged_preprint.node.refresh_from_db()

        assert flagged_preprint.is_spam
        assert flagged_preprint.node.is_spam
        assert not flagged_preprint.node.is_public
コード例 #23
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
    def test_get_user_confirmation_link_with_expired_token(self):
        user = UnconfirmedUserFactory()
        request = RequestFactory().get('/fake_path')
        view = views.GetUserConfirmationLink()
        view = setup_view(view, request, guid=user._id)

        old_user_token = user.email_verifications.keys()[0]
        user.email_verifications[old_user_token]['expiration'] = datetime.utcnow().replace(tzinfo=pytz.utc) - timedelta(hours=24)
        user.save()

        link = view.get_link(user)
        new_user_token = user.email_verifications.keys()[0]

        link_path = str(furl.furl(link).path)
        ideal_link_path = '/confirm/{}/{}/'.format(user._id, new_user_token)

        nt.assert_equal(link_path, ideal_link_path)
コード例 #24
0
ファイル: test_views.py プロジェクト: mrphishxxx/osf.io
 def test_get_spam(self):
     guid = self.user_1._id
     request = RequestFactory().get('/fake_path')
     view = SpamList()
     view = setup_view(view, request, user_id=guid)
     res = list(view.get_queryset())
     nt.assert_equal(len(res), 6)
     response_list = [r._id for r in res]
     should_be = [
         self.comment_6._id,
         self.comment_5._id,
         self.comment_4._id,
         self.comment_3._id,
         self.comment_2._id,
         self.comment_1._id
     ]
     nt.assert_list_equal(should_be, response_list)
コード例 #25
0
ファイル: test_views.py プロジェクト: geeksnglitter/osf.io
    def test_get_unclaimed_node_links(self):
        project = ProjectFactory()
        unregistered_contributor = project.add_unregistered_contributor(fullname='Brother Nero', email='*****@*****.**', auth=Auth(project.creator))
        project.save()

        request = RequestFactory().get('/fake_path')
        view = views.GetUserClaimLinks()
        view = setup_view(view, request, guid=unregistered_contributor._id)

        links = view.get_claim_links(unregistered_contributor)
        unclaimed_records = unregistered_contributor.unclaimed_records

        nt.assert_equal(len(links), 1)
        nt.assert_equal(len(links), len(unclaimed_records.keys()))
        link = links[0]

        nt.assert_in(project._id, link)
        nt.assert_in(unregistered_contributor.unclaimed_records[project._id]['token'], link)
コード例 #26
0
ファイル: test_views.py プロジェクト: 545zhou/osf.io
    def setUp(self):
        super(TestDraftFormView, self).setUp()
        self.user = AuthUserFactory()
        self.dr1 = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=utils.draft_reg_util(),
            registration_metadata=utils.SCHEMA_DATA
        )
        self.dr1.submit_for_review(self.user, {}, save=True)
        self.dr1.flags  # sets flags if there aren't any yet.
        self.request = RequestFactory().get('/fake_path')
        self.view = DraftFormView()
        self.view = setup_view(self.view, self.request, draft_pk=self.dr1._id)

        self.post = RequestFactory().post('/fake_path')
        self.post.user = UserFactory()
        self.post_view = DraftFormView()
        self.form_data = {
            'notes': 'Far between',
            'proof_of_publication': 'approved',
        }
コード例 #27
0
ファイル: test_views.py プロジェクト: adlius/osf.io
    def setUp(self):
        super(TestDraftListView, self).setUp()
        self.user = AuthUserFactory()
        schema = utils.draft_reg_util()
        self.dr1 = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.dr1.submit_for_review(self.user, {}, save=True)
        self.dr2 = DraftRegistrationFactory(
            initiator=self.user,
            registration_schema=schema,
            registration_metadata=utils.SCHEMA_DATA
        )
        self.dr2.submit_for_review(self.user, {}, save=True)
        self.request = RequestFactory().get('/fake_path')
        self.plain_view = DraftListView
        self.view = setup_view(self.plain_view(), self.request)

        self.url = reverse('pre_reg:prereg')
コード例 #28
0
 def view(self, req, provider):
     plain_view = views.RegistrationProviderDisplay()
     view = setup_view(plain_view, req)
     view.kwargs = {'registration_provider_id': provider.id}
     return view
コード例 #29
0
 def view(self, req):
     plain_view = views.ProcessCustomTaxonomy()
     return setup_view(plain_view, req)
コード例 #30
0
 def view(self, req):
     plain_view = views.RegistrationProviderList()
     return setup_view(plain_view, req)
コード例 #31
0
 def test_no_guid(self):
     request = RequestFactory().get('/fake_path')
     view = NodeView()
     view = setup_view(view, request)
     with nt.assert_raises(AttributeError):
         view.get_object()
コード例 #32
0
 def test_no_user(self):
     view = setup_view(views.UserDeleteView(), self.request, guid='meh')
     with nt.assert_raises(Http404):
         view.delete(self.request)
コード例 #33
0
 def test_dispatch_raise_404(self):
     view = setup_view(DraftFormView(), self.request, draft_pk='wrong')
     with nt.assert_raises(Http404):
         view.dispatch(self.request)