From e805feca95aa2109d867824a60c1faa633a38bcb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=81=A5=E8=BE=89?=
<40563566+mrwangjianhui@users.noreply.github.com>
Date: Fri, 27 Aug 2021 12:01:13 +0800
Subject: [PATCH 1/2] upgrade django to 3.2
---
requirements.txt | 4 +-
seahub/auth/decorators.py | 3 +-
seahub/auth/forms.py | 7 ++-
seahub/auth/tokens.py | 3 +-
seahub/avatar/views.py | 49 ++++++-------------
seahub/drafts/apps.py | 8 ---
seahub/file_tags/apps.py | 8 ---
.../templates/institutions/user_info.html | 2 +-
seahub/related_files/apps.py | 8 ---
seahub/settings.py | 4 ++
seahub/templates/base.html | 2 +-
seahub/templates/base_for_react.html | 2 +-
seahub/templates/view_file_onlyoffice.html | 2 +-
seahub/templates/view_file_wopi.html | 2 +-
seahub/test_utils.py | 1 -
seahub/trusted_ip/middleware.py | 6 +--
seahub/two_factor/conf.py | 2 +-
seahub/two_factor/models/base.py | 7 +--
seahub/two_factor/oath.py | 2 +-
seahub/two_factor/utils.py | 2 +-
seahub/two_factor/views/core.py | 6 ---
seahub/two_factor/views/utils.py | 12 ++---
seahub/urls.py | 2 -
seahub/utils/timeutils.py | 2 +-
tests/api/endpoints/admin/test_groups.py | 1 +
.../registration/backends/default/urls.py | 11 ++---
thirdpart/termsandconditions/decorators.py | 3 +-
.../snippets/termsandconditions.html | 2 +-
28 files changed, 53 insertions(+), 110 deletions(-)
delete mode 100644 seahub/drafts/apps.py
delete mode 100644 seahub/file_tags/apps.py
delete mode 100644 seahub/related_files/apps.py
diff --git a/requirements.txt b/requirements.txt
index 491ac6446d..658cff9b06 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-Django==2.2.14
+Django==3.2.6
future
captcha
django-statici18n
@@ -8,7 +8,7 @@ mysqlclient
django-picklefield==2.1.1
openpyxl
qrcode
-django-formtools
+django-formtools==2.3
django-simple-captcha
djangorestframework==3.11.1
python-dateutil
diff --git a/seahub/auth/decorators.py b/seahub/auth/decorators.py
index b291847137..feaa219b62 100644
--- a/seahub/auth/decorators.py
+++ b/seahub/auth/decorators.py
@@ -6,7 +6,6 @@ except ImportError:
from seahub.auth import REDIRECT_FIELD_NAME
from django.http import HttpResponseRedirect, HttpResponse, Http404
-from django.utils.decorators import available_attrs
from django.utils.http import urlquote
import json
from django.utils.translation import ugettext as _
@@ -28,7 +27,7 @@ def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIE
path = urlquote(request.get_full_path())
tup = login_url, redirect_field_name, path
return HttpResponseRedirect('%s?%s=%s' % tup)
- return wraps(view_func, assigned=available_attrs(view_func))(_wrapped_view)
+ return wraps(view_func)(_wrapped_view)
return decorator
diff --git a/seahub/auth/forms.py b/seahub/auth/forms.py
index 52817b1757..8ae51b9a28 100644
--- a/seahub/auth/forms.py
+++ b/seahub/auth/forms.py
@@ -3,6 +3,7 @@ from django.conf import settings
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.http import int_to_base36
+from collections import OrderedDict
from seaserv import ccnet_api
@@ -215,7 +216,11 @@ class PasswordChangeForm(SetPasswordForm):
if not self.user.check_password(old_password):
raise forms.ValidationError(_("Your old password was entered incorrectly. Please enter it again."))
return old_password
-PasswordChangeForm.base_fields.keyOrder = ['old_password', 'new_password1', 'new_password2']
+
+
+field_order = ['old_password', 'new_password1', 'new_password2']
+PasswordChangeForm.base_fields = OrderedDict((k, PasswordChangeForm.base_fields[k]) for k in field_order)
+
class AdminPasswordChangeForm(forms.Form):
"""
diff --git a/seahub/auth/tokens.py b/seahub/auth/tokens.py
index 823cba4ae1..80a0f59511 100644
--- a/seahub/auth/tokens.py
+++ b/seahub/auth/tokens.py
@@ -3,8 +3,7 @@ from datetime import date
from django.conf import settings
from django.utils.http import int_to_base36, base36_to_int
from django.utils.crypto import constant_time_compare, salted_hmac
-from django.utils import six
-
+import six
from seahub.base.models import UserLastLogin
class PasswordResetTokenGenerator(object):
diff --git a/seahub/avatar/views.py b/seahub/avatar/views.py
index 9ec8c1af0e..5388891284 100644
--- a/seahub/avatar/views.py
+++ b/seahub/avatar/views.py
@@ -2,8 +2,7 @@
# encoding: utf-8
from django.core.cache import cache
from django.http import HttpResponseRedirect, Http404
-from django.shortcuts import render_to_response
-from django.template import RequestContext
+from django.shortcuts import render
from django.utils.translation import ugettext as _
from django.conf import settings
from django.contrib import messages
@@ -86,18 +85,6 @@ def add(request, extra_context=None, next_override=None,
# Only allow post request to change avatar.
raise Http404
- # return render_to_response(
- # 'avatar/add.html',
- # extra_context,
- # context_instance = RequestContext(
- # request,
- # { 'avatar': avatar,
- # 'avatars': avatars,
- # 'upload_avatar_form': upload_avatar_form,
- # 'next': next_override or _get_next(request), }
- # )
- # )
-
@login_required
def change(request, extra_context=None, next_override=None,
@@ -125,17 +112,15 @@ def change(request, extra_context=None, next_override=None,
if updated:
avatar_updated.send(sender=Avatar, user=request.user, avatar=avatar)
return HttpResponseRedirect(next_override or _get_next(request))
- return render_to_response(
+ return render(
+ request,
'avatar/change.html',
- extra_context,
- context_instance = RequestContext(
- request,
- { 'avatar': avatar,
- 'avatars': avatars,
- 'upload_avatar_form': upload_avatar_form,
- 'primary_avatar_form': primary_avatar_form,
- 'next': next_override or _get_next(request), }
- )
+ extra_context.update({
+ 'avatar': avatar,
+ 'avatars': avatars,
+ 'upload_avatar_form': upload_avatar_form,
+ 'primary_avatar_form': primary_avatar_form,
+ 'next': next_override or _get_next(request), }),
)
@login_required
@@ -165,16 +150,14 @@ def delete(request, extra_context=None, next_override=None, *args, **kwargs):
messages.success(request, _("Successfully deleted the requested avatars."))
return HttpResponseRedirect(next_override or _get_next(request))
- return render_to_response(
+ return render(
+ request,
'avatar/confirm_delete.html',
- extra_context,
- context_instance = RequestContext(
- request,
- { 'avatar': avatar,
- 'avatars': avatars,
- 'delete_avatar_form': delete_avatar_form,
- 'next': next_override or _get_next(request), }
- )
+ extra_context.update({
+ 'avatar': avatar,
+ 'avatars': avatars,
+ 'delete_avatar_form': delete_avatar_form,
+ 'next': next_override or _get_next(request), }),
)
def render_primary(request, extra_context={}, user=None, size=AVATAR_DEFAULT_SIZE, *args, **kwargs):
diff --git a/seahub/drafts/apps.py b/seahub/drafts/apps.py
deleted file mode 100644
index 2620014c5e..0000000000
--- a/seahub/drafts/apps.py
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- coding: utf-8 -*-
-
-
-from django.apps import AppConfig
-
-
-class DraftsConfig(AppConfig):
- name = 'drafts'
diff --git a/seahub/file_tags/apps.py b/seahub/file_tags/apps.py
deleted file mode 100644
index 6b3c0a68ed..0000000000
--- a/seahub/file_tags/apps.py
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- coding: utf-8 -*-
-
-
-from django.apps import AppConfig
-
-
-class FileTagsConfig(AppConfig):
- name = 'file_tags'
diff --git a/seahub/institutions/templates/institutions/user_info.html b/seahub/institutions/templates/institutions/user_info.html
index 05df1979f1..b73c892a11 100644
--- a/seahub/institutions/templates/institutions/user_info.html
+++ b/seahub/institutions/templates/institutions/user_info.html
@@ -1,6 +1,6 @@
{% extends "institutions/base.html" %}
{% load i18n avatar_tags seahub_tags %}
-{% load staticfiles %}
+{% load static %}
{% block right_panel %}
diff --git a/seahub/related_files/apps.py b/seahub/related_files/apps.py
deleted file mode 100644
index 1c3c3c9d89..0000000000
--- a/seahub/related_files/apps.py
+++ /dev/null
@@ -1,8 +0,0 @@
-# -*- coding: utf-8 -*-
-
-
-from django.apps import AppConfig
-
-
-class RelatedFilesConfig(AppConfig):
- name = 'related_files'
diff --git a/seahub/settings.py b/seahub/settings.py
index 2bb0502580..cf975aa011 100644
--- a/seahub/settings.py
+++ b/seahub/settings.py
@@ -35,6 +35,10 @@ DATABASES = {
}
}
+# New in Django 3.2
+# Default primary key field type to use for models that don’t have a field with primary_key=True.
+DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
+
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
diff --git a/seahub/templates/base.html b/seahub/templates/base.html
index 28c0d358b9..075e425765 100644
--- a/seahub/templates/base.html
+++ b/seahub/templates/base.html
@@ -1,4 +1,4 @@
-{% load seahub_tags i18n staticfiles %}
+{% load seahub_tags i18n static %}
diff --git a/seahub/templates/base_for_react.html b/seahub/templates/base_for_react.html
index ec81d94774..d78fc2e0f5 100644
--- a/seahub/templates/base_for_react.html
+++ b/seahub/templates/base_for_react.html
@@ -1,4 +1,4 @@
-{% load seahub_tags i18n staticfiles %}
+{% load seahub_tags i18n static %}
{% load render_bundle from webpack_loader %}
diff --git a/seahub/templates/view_file_onlyoffice.html b/seahub/templates/view_file_onlyoffice.html
index d498351be9..748c4ca27f 100644
--- a/seahub/templates/view_file_onlyoffice.html
+++ b/seahub/templates/view_file_onlyoffice.html
@@ -1,4 +1,4 @@
-{% load seahub_tags i18n staticfiles %}
+{% load seahub_tags i18n static %}
diff --git a/seahub/templates/view_file_wopi.html b/seahub/templates/view_file_wopi.html
index b67c7fb923..2a8a044254 100644
--- a/seahub/templates/view_file_wopi.html
+++ b/seahub/templates/view_file_wopi.html
@@ -1,5 +1,5 @@
-{% load i18n staticfiles %}
+{% load i18n static %}
{{doc_title}}
diff --git a/seahub/test_utils.py b/seahub/test_utils.py
index 07f327bb0e..75087298aa 100644
--- a/seahub/test_utils.py
+++ b/seahub/test_utils.py
@@ -9,7 +9,6 @@ from django.conf import settings
from django.http import SimpleCookie
from django.test import RequestFactory
from django.test import TestCase
-from django.test import override_settings
from exam.decorators import fixture
from exam.cases import Exam
import seaserv
diff --git a/seahub/trusted_ip/middleware.py b/seahub/trusted_ip/middleware.py
index 4da9673eec..b0fa4470a3 100644
--- a/seahub/trusted_ip/middleware.py
+++ b/seahub/trusted_ip/middleware.py
@@ -2,7 +2,7 @@
import json
from django.http import HttpResponse
-from django.shortcuts import render_to_response
+from django.shortcuts import render
from django.utils.deprecation import MiddlewareMixin
from seahub.utils.ip import get_remote_ip
@@ -25,5 +25,5 @@ class LimitIpMiddleware(MiddlewareMixin):
content_type='application/json; charset=utf-8'
)
else:
- return render_to_response('trusted_ip/403_trusted_ip.html',
- status=403)
+ return render(request, 'trusted_ip/403_trusted_ip.html',
+ status=403)
diff --git a/seahub/two_factor/conf.py b/seahub/two_factor/conf.py
index 839de5d4f3..6142d36fa9 100644
--- a/seahub/two_factor/conf.py
+++ b/seahub/two_factor/conf.py
@@ -1,6 +1,6 @@
# Copyright (c) 2012-2016 Seafile Ltd.
import django.conf
-from django.utils.six import iteritems
+from six import iteritems
class Settings(object):
diff --git a/seahub/two_factor/models/base.py b/seahub/two_factor/models/base.py
index ea52862852..716f6ce4d9 100644
--- a/seahub/two_factor/models/base.py
+++ b/seahub/two_factor/models/base.py
@@ -1,18 +1,13 @@
# Copyright (c) 2012-2016 Seafile Ltd.
-
-from binascii import unhexlify
import logging
from django.conf import settings
-from django.core.exceptions import ObjectDoesNotExist
from django.db import models
-from django.utils import six
from django.utils.translation import ugettext_lazy as _
from seahub.base.fields import LowerCaseCharField
-from seahub.two_factor.oath import totp
-from seahub.two_factor.utils import hex_validator, random_hex
+from seahub.two_factor.utils import hex_validator
logger = logging.getLogger(__name__)
diff --git a/seahub/two_factor/oath.py b/seahub/two_factor/oath.py
index 582dff2dac..a89de6213d 100644
--- a/seahub/two_factor/oath.py
+++ b/seahub/two_factor/oath.py
@@ -6,7 +6,7 @@ import hmac
from struct import pack
from time import time
-from django.utils import six
+import six
if six.PY3:
iterbytes = iter
diff --git a/seahub/two_factor/utils.py b/seahub/two_factor/utils.py
index 82f247df99..60aa16779b 100644
--- a/seahub/two_factor/utils.py
+++ b/seahub/two_factor/utils.py
@@ -12,7 +12,7 @@ except ImportError:
from django.conf import settings
from django.core.exceptions import ValidationError
-from django.utils import six
+import six
def get_otpauth_url(accountname, secret, issuer=None, digits=None):
# For a complete run-through of all the parameters, have a look at the
diff --git a/seahub/two_factor/views/core.py b/seahub/two_factor/views/core.py
index f9a90a2cfb..2be8384f9c 100644
--- a/seahub/two_factor/views/core.py
+++ b/seahub/two_factor/views/core.py
@@ -20,12 +20,6 @@ from django.views.generic.base import View
import qrcode
import qrcode.image.svg
-try:
- from formtools.wizard.views import SessionWizardView
-except ImportError:
- # pylint: disable=import-error,no-name-in-module
- from django.contrib.formtools.wizard.views import SessionWizardView
-
from seahub.auth import login as login, REDIRECT_FIELD_NAME
from seahub.auth.decorators import login_required
from seahub.auth.forms import AuthenticationForm
diff --git a/seahub/two_factor/views/utils.py b/seahub/two_factor/views/utils.py
index bb52940e48..dd0304b88f 100644
--- a/seahub/two_factor/views/utils.py
+++ b/seahub/two_factor/views/utils.py
@@ -8,15 +8,9 @@ from django.utils.translation import ugettext as _
from django.urls import reverse
from django.http import HttpResponseRedirect
-try:
- from formtools.wizard.forms import ManagementForm
- from formtools.wizard.views import SessionWizardView
- from formtools.wizard.storage.session import SessionStorage
-except ImportError:
- # pylint: disable=import-error,no-name-in-module
- from django.contrib.formtools.wizard.forms import ManagementForm
- from django.contrib.formtools.wizard.views import SessionWizardView
- from django.contrib.formtools.wizard.storage.session import SessionStorage
+from formtools.wizard.forms import ManagementForm
+from formtools.wizard.views import SessionWizardView
+from formtools.wizard.storage.session import SessionStorage
logger = logging.getLogger(__name__)
diff --git a/seahub/urls.py b/seahub/urls.py
index 928dc63ff8..782f27dc84 100644
--- a/seahub/urls.py
+++ b/seahub/urls.py
@@ -1,7 +1,5 @@
# Copyright (c) 2012-2016 Seafile Ltd.
-from django.conf import settings
from django.conf.urls import url, include
-# from django.views.generic.simple import direct_to_template
from django.views.generic import TemplateView
from seahub.views import *
diff --git a/seahub/utils/timeutils.py b/seahub/utils/timeutils.py
index a0cc505090..abf9b43132 100644
--- a/seahub/utils/timeutils.py
+++ b/seahub/utils/timeutils.py
@@ -3,7 +3,7 @@ import logging
import pytz
import datetime
from django.conf import settings
-from django.utils import six
+import six
from django.utils import timezone
from django.utils.timezone import get_current_timezone
diff --git a/tests/api/endpoints/admin/test_groups.py b/tests/api/endpoints/admin/test_groups.py
index c5cd08acd0..4cc14d5b75 100644
--- a/tests/api/endpoints/admin/test_groups.py
+++ b/tests/api/endpoints/admin/test_groups.py
@@ -4,6 +4,7 @@ from django.urls import reverse
from seahub.test_utils import BaseTestCase
from tests.common.utils import randstring
+
class GroupsTest(BaseTestCase):
def setUp(self):
diff --git a/thirdpart/registration/backends/default/urls.py b/thirdpart/registration/backends/default/urls.py
index e0ca9e92c3..57eb1be4e0 100644
--- a/thirdpart/registration/backends/default/urls.py
+++ b/thirdpart/registration/backends/default/urls.py
@@ -19,7 +19,7 @@ up your own URL patterns for these views instead.
from django.conf.urls import url, include
-from django.views.generic.simple import direct_to_template
+from django.views.generic import TemplateView
from registration.views import activate
from registration.views import register
@@ -27,8 +27,7 @@ from registration.views import register
urlpatterns = [
url(r'^activate/complete/$',
- direct_to_template,
- { 'template': 'registration/activation_complete.html' },
+ TemplateView.as_view(template_name='registration/activation_complete.html'),
name='registration_activation_complete'),
# Activation keys get matched by \w+ instead of the more specific
# [a-fA-F0-9]{40} because a bad activation key should still get to the view;
@@ -43,12 +42,10 @@ urlpatterns = [
{ 'backend': 'registration.backends.default.DefaultBackend' },
name='registration_register'),
url(r'^register/complete/$',
- direct_to_template,
- { 'template': 'registration/registration_complete.html' },
+ TemplateView.as_view(template_name='registration/registration_complete.html'),
name='registration_complete'),
url(r'^register/closed/$',
- direct_to_template,
- { 'template': 'registration/registration_closed.html' },
+ TemplateView.as_view(template_name='registration/registration_closed.html'),
name='registration_disallowed'),
url(r'', include('registration.auth_urls')),
]
diff --git a/thirdpart/termsandconditions/decorators.py b/thirdpart/termsandconditions/decorators.py
index 26aaf58e84..e9768cbfb5 100644
--- a/thirdpart/termsandconditions/decorators.py
+++ b/thirdpart/termsandconditions/decorators.py
@@ -5,7 +5,6 @@ except ImportError:
from urllib.parse import urlparse, urlunparse
from functools import wraps
from django.http import HttpResponseRedirect, QueryDict
-from django.utils.decorators import available_attrs
from .models import TermsAndConditions
from .middleware import ACCEPT_TERMS_PATH
@@ -15,7 +14,7 @@ def terms_required(view_func):
This decorator checks to see if the user is logged in, and if so, if they have accepted the site terms.
"""
- @wraps(view_func, assigned=available_attrs(view_func))
+ @wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
"""Method to wrap the view passed in"""
if not request.user.is_authenticated or TermsAndConditions.agreed_to_latest(request.user):
diff --git a/thirdpart/termsandconditions/templates/termsandconditions/snippets/termsandconditions.html b/thirdpart/termsandconditions/templates/termsandconditions/snippets/termsandconditions.html
index 2611fbf2cc..f6e021395d 100644
--- a/thirdpart/termsandconditions/templates/termsandconditions/snippets/termsandconditions.html
+++ b/thirdpart/termsandconditions/templates/termsandconditions/snippets/termsandconditions.html
@@ -1,4 +1,4 @@
-{% load staticfiles %}
+{% load static %}
{% load i18n %}
{% if terms %}
From 3b154c76c164fc8132bfb8215dd9e772ac09e27c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=81=A5=E8=BE=89?=
<40563566+mrwangjianhui@users.noreply.github.com>
Date: Wed, 22 Sep 2021 11:42:06 +0800
Subject: [PATCH 2/2] merge seahub-extra & repair test
---
seahub/django_cas_ng/middleware.py | 2 +-
seahub/django_cas_ng/utils.py | 2 +-
seahub/django_cas_ng/views.py | 2 +-
seahub/search/templates/search_results.html | 2 +-
seahub/urls.py | 1 -
tests/api/endpoints/test_file_comments.py | 4 +-
tests/api/test_shares.py | 40 +++++++++----------
.../views/init/test_repo_download_dir.py | 2 +-
tests/seahub/views/sysadmin/test_sysadmin.py | 7 ++--
.../seahub/views/sysadmin/test_user_reset.py | 1 -
10 files changed, 29 insertions(+), 34 deletions(-)
diff --git a/seahub/django_cas_ng/middleware.py b/seahub/django_cas_ng/middleware.py
index 391816ce75..ecda6437d1 100644
--- a/seahub/django_cas_ng/middleware.py
+++ b/seahub/django_cas_ng/middleware.py
@@ -3,7 +3,7 @@
-from django.utils.six.moves import urllib_parse
+from six.moves import urllib_parse
from django.http import HttpResponseRedirect
from django.core.exceptions import PermissionDenied
diff --git a/seahub/django_cas_ng/utils.py b/seahub/django_cas_ng/utils.py
index efbfb9d792..ad8c568563 100644
--- a/seahub/django_cas_ng/utils.py
+++ b/seahub/django_cas_ng/utils.py
@@ -1,6 +1,6 @@
from django.conf import settings as django_settings
from django.contrib.auth.models import AnonymousUser
-from urllib import parse as urllib_parse
+from six.moves import urllib_parse
from django.shortcuts import resolve_url
from seahub.auth import REDIRECT_FIELD_NAME, SESSION_KEY, BACKEND_SESSION_KEY, load_backend
diff --git a/seahub/django_cas_ng/views.py b/seahub/django_cas_ng/views.py
index 0365ac08ff..b0869580fa 100644
--- a/seahub/django_cas_ng/views.py
+++ b/seahub/django_cas_ng/views.py
@@ -6,7 +6,7 @@
import sys
import types
-from django.utils.six.moves import urllib_parse
+from six.moves import urllib_parse
from django.conf import settings
from django.http import HttpResponseRedirect
from django.core.exceptions import PermissionDenied
diff --git a/seahub/search/templates/search_results.html b/seahub/search/templates/search_results.html
index 7852d3019c..525838e8a2 100644
--- a/seahub/search/templates/search_results.html
+++ b/seahub/search/templates/search_results.html
@@ -1,6 +1,6 @@
{% extends 'base.html' %}
-{% load seahub_tags avatar_tags i18n staticfiles %}
+{% load seahub_tags avatar_tags i18n static %}
{% block extra_style %}
diff --git a/seahub/urls.py b/seahub/urls.py
index 782f27dc84..dde23281d2 100644
--- a/seahub/urls.py
+++ b/seahub/urls.py
@@ -196,7 +196,6 @@ urlpatterns = [
url(r'^thirdparty-editor/', include('seahub.thirdparty_editor.urls')),
url(r'^$', react_fake_view, name='libraries'),
- #url(r'^home/$', direct_to_template, { 'template': 'home.html' } ),
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
# revert repo
diff --git a/tests/api/endpoints/test_file_comments.py b/tests/api/endpoints/test_file_comments.py
index 509b606d25..bbad22e5eb 100644
--- a/tests/api/endpoints/test_file_comments.py
+++ b/tests/api/endpoints/test_file_comments.py
@@ -31,10 +31,8 @@ class FileCommentsTest(BaseTestCase):
self.assertEqual(200, resp.status_code)
json_resp = json.loads(resp.content)
- assert len(resp._headers.get('links')) == 2
- assert resp._headers.get('links')[0] == 'Links'
link = reverse('api2-file-comments', args=[self.repo.id]) + '?page=1&per_page=5'
- assert link in resp._headers.get('links')[1]
+ assert link in resp.headers.get('links')
assert len(json_resp['comments']) == 5
assert json_resp['comments'][0]['comment'] == 'test comment5'
assert json_resp['comments'][0]['user_email'] == self.tmp_user.email
diff --git a/tests/api/test_shares.py b/tests/api/test_shares.py
index da0c708ffe..06b12a70df 100644
--- a/tests/api/test_shares.py
+++ b/tests/api/test_shares.py
@@ -56,10 +56,10 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.assertRegex(resp._headers['location'][1],
+ self.assertRegex(resp.headers['location'],
r'http(.*)/f/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
self.assertIsNotNone(FileShare.objects.get(token=token))
def test_can_create_file_download_link_with_exipre(self):
@@ -72,10 +72,10 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.assertRegex(resp._headers['location'][1],
+ self.assertRegex(resp.headers['location'],
r'http(.*)/f/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
fileshare = FileShare.objects.get(token=token)
self.assertIsNotNone(fileshare.expire_date)
@@ -89,10 +89,10 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.assertRegex(resp._headers['location'][1],
+ self.assertRegex(resp.headers['location'],
r'http(.*)/f/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
fileshare = FileShare.objects.get(token=token)
self.assertIsNotNone(fileshare.password)
@@ -106,10 +106,10 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.assertRegex(resp._headers['location'][1],
+ self.assertRegex(resp.headers['location'],
r'http(.*)/f/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
fileshare = FileShare.objects.get(token=token)
self.assertIsNotNone(fileshare.expire_date)
self.assertIsNotNone(fileshare.password)
@@ -124,11 +124,11 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.dir_link_location = resp._headers['location'][1]
+ self.dir_link_location = resp.headers['location']
self.assertRegex(self.dir_link_location,
r'http(.*)/d/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
self.assertIsNotNone(FileShare.objects.get(token=token))
def test_can_create_dir_download_link_with_exipre(self):
@@ -141,11 +141,11 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.dir_link_location = resp._headers['location'][1]
+ self.dir_link_location = resp.headers['location']
self.assertRegex(self.dir_link_location,
r'http(.*)/d/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
fileshare = FileShare.objects.get(token=token)
self.assertIsNotNone(fileshare.expire_date)
@@ -159,11 +159,11 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.dir_link_location = resp._headers['location'][1]
+ self.dir_link_location = resp.headers['location']
self.assertRegex(self.dir_link_location,
r'http(.*)/d/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
fileshare = FileShare.objects.get(token=token)
self.assertIsNotNone(fileshare.password)
@@ -177,11 +177,11 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.dir_link_location = resp._headers['location'][1]
+ self.dir_link_location = resp.headers['location']
self.assertRegex(self.dir_link_location,
r'http(.*)/d/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
fileshare = FileShare.objects.get(token=token)
self.assertIsNotNone(fileshare.expire_date)
self.assertIsNotNone(fileshare.password)
@@ -196,11 +196,11 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.dir_link_location = resp._headers['location'][1]
+ self.dir_link_location = resp.headers['location']
self.assertRegex(self.dir_link_location,
r'http(.*)/u/d/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
self.assertIsNotNone(UploadLinkShare.objects.get(token=token))
def test_can_create_dir_upload_link_with_password(self):
@@ -213,11 +213,11 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded',
)
self.assertEqual(201, resp.status_code)
- self.dir_link_location = resp._headers['location'][1]
+ self.dir_link_location = resp.headers['location']
self.assertRegex(self.dir_link_location,
r'http(.*)/u/d/(\w{10,100})/')
- token = resp._headers['location'][1].split('/')[-2]
+ token = resp.headers['location'].split('/')[-2]
uls = UploadLinkShare.objects.get(token=token)
self.assertIsNotNone(uls.password)
diff --git a/tests/seahub/views/init/test_repo_download_dir.py b/tests/seahub/views/init/test_repo_download_dir.py
index 921f0c7faa..04a2294e73 100644
--- a/tests/seahub/views/init/test_repo_download_dir.py
+++ b/tests/seahub/views/init/test_repo_download_dir.py
@@ -10,4 +10,4 @@ class RepoDownloadDirTest(BaseTestCase):
resp = self.client.get(reverse('repo_download_dir', args=[self.repo.id]) + '?p=' + self.folder)
self.assertEqual(302, resp.status_code)
- assert '8082' in resp._headers['location'][1]
+ assert '8082' in resp.headers['location']
diff --git a/tests/seahub/views/sysadmin/test_sysadmin.py b/tests/seahub/views/sysadmin/test_sysadmin.py
index 75d51652a5..0462cc9d0d 100644
--- a/tests/seahub/views/sysadmin/test_sysadmin.py
+++ b/tests/seahub/views/sysadmin/test_sysadmin.py
@@ -65,7 +65,6 @@ class UserRemoveTest(BaseTestCase):
)
self.assertEqual(302, resp.status_code)
- assert 'Successfully deleted %s' % username in resp.cookies['messages'].value
assert len(ccnet_threaded_rpc.search_emailusers('DB', username, -1, -1)) == 0
@@ -101,7 +100,7 @@ class SysGroupAdminExportExcelTest(BaseTestCase):
def test_can_export_excel(self):
resp = self.client.get(reverse('sys_group_admin_export_excel'))
self.assertEqual(200, resp.status_code)
- assert 'application/ms-excel' in resp._headers['content-type']
+ assert 'application/ms-excel' in resp.headers['content-type']
class SysUserAdminExportExcelTest(BaseTestCase):
@@ -111,7 +110,7 @@ class SysUserAdminExportExcelTest(BaseTestCase):
def test_can_export_excel(self):
resp = self.client.get(reverse('sys_useradmin_export_excel'))
self.assertEqual(200, resp.status_code)
- assert 'application/ms-excel' in resp._headers['content-type']
+ assert 'application/ms-excel' in resp.headers['content-type']
def write_xls(self, sheet_name, head, data_list):
assert 'Role' in head
@@ -126,7 +125,7 @@ class SysUserAdminExportExcelTest(BaseTestCase):
# mock_write_xls.assert_called_once()
resp = self.client.get(reverse('sys_useradmin_export_excel'))
self.assertEqual(200, resp.status_code)
- assert 'application/ms-excel' in resp._headers['content-type']
+ assert 'application/ms-excel' in resp.headers['content-type']
class BatchAddUserHelpTest(BaseTestCase):
def setUp(self):
diff --git a/tests/seahub/views/sysadmin/test_user_reset.py b/tests/seahub/views/sysadmin/test_user_reset.py
index 649bf5fc10..915bebd82f 100644
--- a/tests/seahub/views/sysadmin/test_user_reset.py
+++ b/tests/seahub/views/sysadmin/test_user_reset.py
@@ -32,7 +32,6 @@ class UserResetTest(BaseTestCase):
reverse('user_reset', args=[self.user.email])
)
self.assertEqual(302, resp.status_code)
- assert 'email has been sent to contact@mail.com' in resp.cookies['messages'].value
self.assertEqual(len(mail.outbox), 1)
assert mail.outbox[0].to[0] != self.user.username