1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-05 11:17:36 +00:00
seahub/tests/api/endpoints/admin/test_favicon.py

65 lines
2.2 KiB
Python
Raw Normal View History

2017-05-17 08:59:38 +00:00
import os
2018-01-03 03:07:16 +00:00
import json
2017-05-17 08:59:38 +00:00
from tests.common.utils import urljoin
from tests.common.common import BASE_URL
from django.core.urlresolvers import reverse
2018-01-03 03:07:16 +00:00
from seahub.test_utils import BaseTestCase
from seahub.utils import PREVIEW_FILEEXT
from seahub.utils.file_types import IMAGE
from seahub.utils.error_msg import file_type_error_msg
2017-08-31 06:43:25 +00:00
from seahub.settings import MEDIA_ROOT, CUSTOM_FAVICON_PATH
2017-05-17 08:59:38 +00:00
2018-01-03 03:07:16 +00:00
class AdminFaviconTest(BaseTestCase):
def setUp(self):
self.login_as(self.admin)
2017-05-17 08:59:38 +00:00
def test_update_favicon(self):
custom_symlink = os.path.join(MEDIA_ROOT, os.path.dirname(CUSTOM_FAVICON_PATH))
if os.path.exists(custom_symlink):
os.remove(custom_symlink)
assert not os.path.exists(custom_symlink)
# update user avatar
2018-01-03 03:07:16 +00:00
logo_url = reverse('api-v2.1-admin-favicon')
2017-05-17 08:59:38 +00:00
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png')
with open(logo_file) as f:
2018-01-03 03:07:16 +00:00
resp = self.client.post(logo_url, {'favicon': f})
2017-05-17 08:59:38 +00:00
2018-01-03 03:07:16 +00:00
assert resp.status_code == 200
json_resp = json.loads(resp.content)
2017-05-17 08:59:38 +00:00
assert json_resp['success'] == True
assert os.path.exists(custom_symlink)
assert os.path.islink(custom_symlink)
def test_update_favicon_with_invalid_user_permission(self):
2018-01-03 03:07:16 +00:00
self.logout()
self.login_as(self.user)
2017-05-17 08:59:38 +00:00
# update user avatar
logo_url = reverse('api-v2.1-admin-favicon')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png')
with open(logo_file) as f:
2018-01-03 03:07:16 +00:00
resp = self.client.post(logo_url, {'favicon': f})
assert resp.status_code == 403
def test_update_favicon_with_invalid_filetype(self):
with open('test.noico', 'w') as f:
f.write('hello')
logo_url = reverse('api-v2.1-admin-favicon')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'test.noico')
with open(logo_file) as f:
resp = self.client.post(logo_url, {'favicon': f})
json_resp = json.loads(resp.content)
assert resp.status_code == 400
assert json_resp['error_msg'] == file_type_error_msg('noico', PREVIEW_FILEEXT.get(IMAGE))