1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-31 02:57:06 +00:00
seahub/tests/common/utils.py

33 lines
723 B
Python
Raw Normal View History

2014-09-03 04:20:26 +00:00
import string
import random
2017-07-03 06:42:12 +00:00
import requests
2014-09-03 04:20:26 +00:00
from .common import BASE_URL
2014-09-05 02:07:33 +00:00
def randstring(length=0):
if length == 0:
length = random.randint(1, 30)
2014-09-03 04:20:26 +00:00
return ''.join(random.choice(string.lowercase) for i in range(length))
def urljoin(base, *args):
url = base
if url[-1] != '/':
url += '/'
for arg in args:
arg = arg.strip('/')
url += arg + '/'
return url
def apiurl(*parts):
2014-09-06 03:38:20 +00:00
return urljoin(BASE_URL, *parts)
2017-07-03 06:42:12 +00:00
def upload_file_test(upload_link):
file_name = randstring(6)
files = {
'file': (file_name, 'Some lines in this file'),
'parent_dir': '/',
}
resp = requests.post(upload_link, files=files)
assert 200 == resp.status_code