2014-09-03 12:20:26 +08:00
|
|
|
import string
|
|
|
|
import random
|
2017-07-03 14:42:12 +08:00
|
|
|
import requests
|
2014-09-03 12:20:26 +08:00
|
|
|
|
|
|
|
from .common import BASE_URL
|
2014-08-28 02:45:58 +08:00
|
|
|
|
2014-09-05 10:07:33 +08:00
|
|
|
def randstring(length=0):
|
|
|
|
if length == 0:
|
|
|
|
length = random.randint(1, 30)
|
2019-09-11 11:46:43 +08:00
|
|
|
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))
|
2014-09-03 12:20:26 +08:00
|
|
|
|
|
|
|
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 11:38:20 +08:00
|
|
|
return urljoin(BASE_URL, *parts)
|
2017-07-03 14:42:12 +08:00
|
|
|
|
2019-12-10 14:07:55 +08:00
|
|
|
def upload_file_test(upload_link, parent_dir='/'):
|
2017-07-03 14:42:12 +08:00
|
|
|
file_name = randstring(6)
|
|
|
|
files = {
|
|
|
|
'file': (file_name, 'Some lines in this file'),
|
2019-12-10 14:07:55 +08:00
|
|
|
'parent_dir': parent_dir,
|
2017-07-03 14:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resp = requests.post(upload_link, files=files)
|
|
|
|
assert 200 == resp.status_code
|