1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-18 11:28:54 +00:00
seahub/tests/api/apitestbase.py

58 lines
1.9 KiB
Python
Raw Normal View History

2014-08-28 02:21:28 +00:00
from common.common import BASE_URL, USERNAME, PASSWORD, IS_PRO
2014-08-27 03:08:39 +00:00
import requests, re
2014-08-27 15:40:52 +00:00
BASE_URL = BASE_URL
2014-08-27 09:13:05 +00:00
PING_URL = BASE_URL + u'/api2/ping/'
TOKEN_URL = BASE_URL + u'/api2/auth-token/'
AUTH_PING_URL = BASE_URL + u'/api2/auth/ping/'
2014-08-27 03:08:39 +00:00
2014-08-27 15:40:52 +00:00
ACCOUNTS_URL = BASE_URL + u'/api2/accounts/'
ACCOUNT_INFO_URL = BASE_URL + u'/api2/account/info/'
USERMSGS_URL = BASE_URL + u'/api2/user/msgs/' + USERNAME + u'/'
USERMSGS_COUNT_URL = BASE_URL + u'/api2/unseen_messages/'
GROUP_URL = BASE_URL + u'/api2/group/'
GROUPS_URL = BASE_URL + u'/api2/groups/'
GROUPMSGS_URL = BASE_URL + u'/api2/group/msgs/'
GROUPMSGS_NREPLY_URL = BASE_URL + u'/api2/new_replies/'
AVATAR_BASE_URL = BASE_URL + u'/api2/avatars/'
2014-08-28 03:35:19 +00:00
DEFAULT_LIBRARY_URL = BASE_URL + u'/api2/default-repo/'
LIBRARIES_URL = BASE_URL + u'/api2/repos/'
VIRTUAL_LIBRARIES_URL = BASE_URL + u'/api2/virtual-repos/'
STARREDFILES_URL = BASE_URL + u'/api2/starredfiles/'
2014-08-28 08:19:42 +00:00
SHARED_LINKS_URL = BASE_URL + u'/api2/shared-links/'
SHARED_LIBRARIES_URL = BASE_URL + u'/api2/shared-repos/'
BESHARED_LIBRARIES_URL = BASE_URL + u'/api2/beshared-repos/'
SHARED_FILES_URL = BASE_URL + u'/api2/shared-files/'
F_URL = BASE_URL + u'/api2/f/'
S_F_URL = BASE_URL + u'/api2/s/f/'
2014-08-27 15:40:52 +00:00
2014-08-28 03:35:19 +00:00
MISC_SEARCH_URL = BASE_URL + u'/api2/search/'
2014-08-28 02:21:28 +00:00
MISC_LIST_GROUP_AND_CONTACTS_URL = BASE_URL + u'/api2/groupandcontacts/'
MISC_LIST_EVENTS_URL = BASE_URL + u'/api2/events/'
2014-08-27 03:08:39 +00:00
META_AUTH = {'username': USERNAME, 'password': PASSWORD}
2014-08-27 09:13:05 +00:00
def get_auth_token():
2014-08-27 03:08:39 +00:00
res = requests.post(TOKEN_URL, data=META_AUTH)
if (res.status_code != 200):
return None
token = res.json()['token']
if (re.match(r'(\w){40,40}', token) == None):
return None
return token
2014-08-27 15:40:52 +00:00
_token = get_auth_token()
if (_token != None):
_instance = requests.Session()
_instance.headers.update({'Authorization': 'Token ' + _token})
else:
_instance = None
2014-08-28 08:19:42 +00:00
_nuked_instance = requests.Session()
2014-08-27 09:13:05 +00:00
def get_authed_instance():
2014-08-27 15:40:52 +00:00
return _instance
2014-08-28 08:19:42 +00:00
def get_anonymous_instance():
2014-08-30 15:17:08 +00:00
return _nuked_instance