1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-13 06:55:59 +00:00
seahub/tests/api/endpoints/admin/test_logo.py

75 lines
2.5 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
2020-07-27 06:59:18 +00:00
from django.urls import reverse
2017-05-17 08:59:38 +00:00
2018-01-03 03:07:16 +00:00
from seahub.test_utils import BaseTestCase
from seahub.settings import MEDIA_ROOT, CUSTOM_LOGO_PATH, MEDIA_URL
from seahub.utils import PREVIEW_FILEEXT, get_service_url
from seahub.utils.file_types import IMAGE
from seahub.utils.error_msg import file_type_error_msg
2017-05-17 08:59:38 +00:00
2018-01-03 03:07:16 +00:00
class AdminLogoTest(BaseTestCase):
def setUp(self):
self.login_as(self.admin)
2017-05-17 08:59:38 +00:00
def test_post_admin_permission_denied(self):
self.logout()
self.login_as(self.admin_cannot_config_system)
resp = self.client.post(reverse('api-v2.1-admin-logo'))
self.assertEqual(403, resp.status_code)
2017-05-17 08:59:38 +00:00
def test_update_logo(self):
custom_symlink = os.path.join(MEDIA_ROOT, os.path.dirname(CUSTOM_LOGO_PATH))
if os.path.exists(custom_symlink):
os.remove(custom_symlink)
assert not os.path.exists(custom_symlink)
# update user avatar
logo_url = reverse('api-v2.1-admin-logo')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png')
2018-01-03 03:07:16 +00:00
with open(logo_file, 'rb') as f:
resp = self.client.post(logo_url, {'logo': f})
json_resp = json.loads(resp.content)
2017-05-17 08:59:38 +00:00
2018-01-03 03:07:16 +00:00
assert 200 == resp.status_code
assert json_resp['logo_path'] == get_service_url() + MEDIA_URL + CUSTOM_LOGO_PATH
2017-05-17 08:59:38 +00:00
assert os.path.exists(custom_symlink)
assert os.path.islink(custom_symlink)
def test_update_logo_with_invalid_user_permission(self):
2018-01-03 03:07:16 +00:00
self.logout()
2017-05-17 08:59:38 +00:00
# update user avatar
logo_url = reverse('api-v2.1-admin-logo')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png')
2018-01-03 03:07:16 +00:00
with open(logo_file, 'rb') as f:
resp = self.client.post(logo_url, {'logo': f})
assert 403 == resp.status_code
def test_update_logo_with_invalid_file_type(self):
with open('test.noimage', 'w') as f:
f.write('1')
logo_url = reverse('api-v2.1-admin-logo')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'test.noimage')
with open(logo_file, 'rb') as f:
resp = self.client.post(logo_url, {'logo': f})
json_resp = json.loads(resp.content)
os.remove(logo_file)
assert 400 == resp.status_code
assert json_resp['error_msg'] == file_type_error_msg('noimage', PREVIEW_FILEEXT.get(IMAGE))