2014-09-05 02:37:29 +00:00
|
|
|
import requests
|
2014-08-27 15:40:52 +00:00
|
|
|
|
2023-06-19 05:06:15 +00:00
|
|
|
from tests.common.utils import randstring
|
2014-09-06 03:38:20 +00:00
|
|
|
from tests.api.apitestbase import ApiTestBase
|
2023-06-19 05:06:15 +00:00
|
|
|
from tests.api.urls import PING_URL, AUTH_PING_URL
|
2014-08-27 15:40:52 +00:00
|
|
|
|
2014-09-05 02:37:29 +00:00
|
|
|
test_account_username = 'test_%s@test.com' % randstring(10)
|
|
|
|
test_account_password = randstring(20)
|
|
|
|
test_account_password2 = randstring(20)
|
2014-08-27 15:40:52 +00:00
|
|
|
|
2014-09-05 02:07:33 +00:00
|
|
|
class AccountsApiTest(ApiTestBase):
|
2014-08-27 15:40:52 +00:00
|
|
|
|
2015-04-14 08:01:32 +00:00
|
|
|
def test_update_account_passwd(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
data = {'password': 'new_password'}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
|
|
|
|
def test_set_account_to_staff(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
self.assertEqual(self.admin_get(user.user_url).json()['is_staff'],
|
|
|
|
False)
|
|
|
|
data = {'is_staff': 'true'}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
self.assertEqual(self.admin_get(user.user_url).json()['is_staff'],
|
|
|
|
True)
|
|
|
|
|
|
|
|
def test_set_account_inactive(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
self.assertEqual(self.admin_get(user.user_url).json()['is_active'],
|
|
|
|
True)
|
|
|
|
data = {'is_active': 'false'}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
self.assertEqual(self.admin_get(user.user_url).json()['is_active'],
|
|
|
|
False)
|
|
|
|
|
|
|
|
def test_set_account_inactive_with_wrong_arg(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
self.assertEqual(self.admin_get(user.user_url).json()['is_active'],
|
|
|
|
True)
|
|
|
|
data = {'is_active': 'fals'}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=400)
|
|
|
|
|
|
|
|
def test_set_account_inactive_with_empty_arg(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
self.assertEqual(self.admin_get(user.user_url).json()['is_active'],
|
|
|
|
True)
|
|
|
|
data = {'is_active': ''}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=400)
|
|
|
|
|
|
|
|
def test_update_account_nickname(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
data = {'name': 'new nick name'}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
|
|
|
|
# def test_update_account_nickname_with_slash(self):
|
|
|
|
# with self.get_tmp_user() as user:
|
|
|
|
# data = {'name': 'new /nick name'}
|
|
|
|
# self.admin_put(user.user_url, data=data, expected=400)
|
|
|
|
|
|
|
|
def test_update_account_intro(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
data = {'note': 'hello, my name is foo'}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
|
|
|
|
def test_update_account_storage_quota(self):
|
|
|
|
with self.get_tmp_user() as user:
|
2017-01-05 05:33:12 +00:00
|
|
|
data = {'storage': 1024} # 1 Mb
|
2015-04-14 08:01:32 +00:00
|
|
|
self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
self.assertEqual(self.admin_get(user.user_url).json()['total'],
|
2017-01-05 05:33:12 +00:00
|
|
|
1024000000)
|
2015-04-14 08:01:32 +00:00
|
|
|
|
|
|
|
# def test_update_account_sharing_quota(self):
|
|
|
|
# with self.get_tmp_user() as user:
|
|
|
|
# data = {'sharing': 1024} # 1KB
|
|
|
|
# self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
# self.assertEqual(self.admin_get(user.user_url).json()['sharing'],
|
|
|
|
# 1024)
|
|
|
|
|
|
|
|
def test_unset_trial_account(self):
|
|
|
|
with self.get_tmp_user() as user:
|
|
|
|
data = {'is_trial': 'false'}
|
|
|
|
self.admin_put(user.user_url, data=data, expected=200)
|
|
|
|
|
2014-09-05 02:07:33 +00:00
|
|
|
def test_auth_ping(self):
|
|
|
|
res = self.get(AUTH_PING_URL)
|
2019-09-11 03:46:43 +00:00
|
|
|
self.assertRegex(res.text, '"pong"')
|
2014-09-05 02:37:29 +00:00
|
|
|
res = requests.get(AUTH_PING_URL)
|
|
|
|
self.assertEqual(res.status_code, 403)
|
2014-09-05 02:07:33 +00:00
|
|
|
|
|
|
|
def test_ping(self):
|
2014-09-05 02:37:29 +00:00
|
|
|
res = requests.get(PING_URL)
|
2019-09-11 03:46:43 +00:00
|
|
|
self.assertRegex(res.text, '"pong"')
|
2014-09-05 02:37:29 +00:00
|
|
|
self.assertEqual(res.status_code, 200)
|