本文整理汇总了Python中tests.common.utils.urljoin函数的典型用法代码示例。如果您正苦于以下问题:Python urljoin函数的具体用法?Python urljoin怎么用?Python urljoin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了urljoin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy_file
def test_copy_file(self):
with self.get_tmp_repo() as repo:
fname, _ = self.create_file(repo)
# TODO: create another repo here, and use it as dst_repo
dpath, _ = self.create_dir(repo)
fopurl = urljoin(repo.repo_url, 'fileops/copy/') + '?p=/'
data = {
'file_names': fname,
'dst_repo': repo.repo_id,
'dst_dir': dpath,
}
res = self.post(fopurl, data=data)
self.assertEqual(res.text, '"success"')
# create tmp file in sub folder(dpath)
tmp_file = 'tmp_file.txt'
furl = repo.get_filepath_url(dpath + '/' + tmp_file)
data = {'operation': 'create'}
res = self.post(furl, data=data, expected=201)
# copy tmp file(in dpath) to dst dir
fopurl = urljoin(repo.repo_url, 'fileops/copy/') + '?p=' + quote(dpath)
data = {
'file_names': tmp_file,
'dst_repo': repo.repo_id,
'dst_dir': dpath,
}
res = self.post(fopurl, data=data)
self.assertEqual(res.text, '"success"')
示例2: _get_repo_info
def _get_repo_info(self, sync_token, repo_id, **kwargs):
headers = {
'Seafile-Repo-Token': sync_token
}
url = urljoin(SEAFILE_BASE_URL,
'repo/%s/permission-check/?op=upload' % repo_id)
self.get(url, use_token=False, headers=headers, **kwargs)
示例3: test_download_dir
def test_download_dir(self):
with self.get_tmp_repo() as repo:
dpath, _ = self.create_dir(repo)
query = '?p=%s' % quote(dpath)
ddurl = urljoin(repo.dir_url, 'download') + query
res = self.get(ddurl)
self.assertRegexpMatches(res.text,
r'"http(.*)/files/[^/]+/%s"' % quote(dpath[1:]))
示例4: test_generate_client_login_token
def test_generate_client_login_token(self):
url = self._get_client_login_url()
r = requests.get(url)
assert r.url == BASE_URL
r = requests.get(url)
assert r.url == urljoin(BASE_URL, 'accounts/login/?next=/'), \
'a client login token can only be used once'
示例5: test_add_remove_group_member
def test_add_remove_group_member(self):
with self.get_tmp_user() as user:
with self.get_tmp_group() as group:
test_group_members_url = urljoin(group.group_url, '/members/')
data = {'user_name': user.user_name}
res = self.put(test_group_members_url, data=data).json()
self.assertTrue(res['success'])
res = self.delete(test_group_members_url, data=data).json()
self.assertTrue(res['success'])
示例6: test_group_avatar
def test_group_avatar(self):
gname = randstring(16)
data = {'group_name': gname}
res = self.put(GROUPS_URL, data=data)
gid = res.json()['group_id']
avatar_url = urljoin(AVATAR_BASE_URL, 'group', str(gid), '/resized/80/')
info = self.get(avatar_url).json()
self.assertIsNotNone(info)
self.assertIsNotNone(info['url'])
self.assertIsNotNone(info['is_default'])
self.assertIsNotNone(info['mtime'])
示例7: test_update_favicon_with_invalid_user_permission
def test_update_favicon_with_invalid_user_permission(self):
self.logout()
self.login_as(self.user)
# update user avatar
logo_url = reverse('api-v2.1-admin-favicon')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png')
with open(logo_file) as f:
resp = self.client.post(logo_url, {'favicon': f})
assert resp.status_code == 403
示例8: test_fetch_repo_download_info
def test_fetch_repo_download_info(self):
with self.get_tmp_repo() as repo:
download_info_repo_url = urljoin(repo.repo_url, '/download-info/')
info = self.get(download_info_repo_url).json()
self.assertIsNotNone(info['relay_addr'])
self.assertIsNotNone(info['token'])
self.assertIsNotNone(info['repo_id'])
self.assertIsNotNone(info['relay_port'])
self.assertIsNotNone(info['encrypted'])
self.assertIsNotNone(info['repo_name'])
self.assertIsNotNone(info['relay_id'])
self.assertIsNotNone(info['email'])
示例9: test_add_remove_group_with_blank_and_hyphen
def test_add_remove_group_with_blank_and_hyphen(self):
data = {'group_name': randstring(4) + '-' + randstring(4) + ' ' + randstring(4)}
info = self.put(GROUPS_URL, data=data).json()
self.assertTrue(info['success'])
group_id = info['group_id']
self.assertGreater(group_id, 0)
url = urljoin(GROUPS_URL, str(group_id))
self.delete(url)
# check group is really removed
groups = self.get(GROUPS_URL).json()['groups']
for group in groups:
self.assertNotEqual(group['id'], group_id)
示例10: test_update_favicon_with_invalid_filetype
def test_update_favicon_with_invalid_filetype(self):
with open('test.noico', 'w') as f:
f.write('hello')
logo_url = reverse('api-v2.1-admin-favicon')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'test.noico')
with open(logo_file) as f:
resp = self.client.post(logo_url, {'favicon': f})
json_resp = json.loads(resp.content)
assert resp.status_code == 400
assert json_resp['error_msg'] == file_type_error_msg('noico', PREVIEW_FILEEXT.get(IMAGE))
示例11: test_copy_file
def test_copy_file(self):
with self.get_tmp_repo() as repo:
fname, _ = self.create_file(repo)
# TODO: create another repo here, and use it as dst_repo
dpath, _ = self.create_dir(repo)
fopurl = urljoin(repo.repo_url, 'fileops/copy/') + '?p=/'
data = {
'file_names': fname,
'dst_repo': repo.repo_id,
'dst_dir': dpath,
}
res = self.post(fopurl, data=data)
self.assertEqual(res.text, '"success"')
示例12: test_share_dir
def test_share_dir(self):
with self.get_tmp_repo() as repo:
dpath, _ = self.create_dir(repo)
query = '?p=%s' % quote(dpath)
share_dir_url = urljoin(repo.dir_url, 'share/') + query
with self.get_tmp_user() as user:
data = {
'emails': user.user_name,
's_type': 'd',
'path': '/',
'perm': 'r'
}
res = self.post(share_dir_url, data=data)
self.assertEqual(res.text, u'{}')
示例13: test_download_file_from_history
def test_download_file_from_history(self):
with self.get_tmp_repo() as repo:
fname, _ = self.create_file(repo)
file_history_url = urljoin(repo.repo_url, 'history/') + \
'?p=/%s' % quote(fname)
res = self.get(file_history_url).json()
commit_id = res['commits'][0]['id']
self.assertEqual(len(commit_id), 40)
data = {
'p': fname,
'commit_id': commit_id,
}
query = '?' + urlencode(data)
res = self.get(repo.file_url + query)
self.assertRegexpMatches(res.text, r'"http(.*)/%s"' % quote(fname))
示例14: test_update_favicon
def test_update_favicon(self):
custom_symlink = os.path.join(MEDIA_ROOT, os.path.dirname(CUSTOM_FAVICON_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-favicon')
logo_url = urljoin(BASE_URL, logo_url)
logo_file = os.path.join(os.getcwd(), 'media/img/seafile-logo.png')
with open(logo_file) as f:
resp = self.client.post(logo_url, {'favicon': f})
assert resp.status_code == 200
json_resp = json.loads(resp.content)
assert json_resp['success'] == True
assert os.path.exists(custom_symlink)
assert os.path.islink(custom_symlink)
示例15: test_create_file_shared_link
def test_create_file_shared_link(self):
with self.get_tmp_repo() as repo:
fname, _ = self.create_file(repo)
fsurl = urljoin(repo.file_url, 'shared-link')
data = {
'type': 'f',
'p': '/' + fname,
}
res = self.put(fsurl, data=data, expected=201)
self.assertRegexpMatches(res.headers['Location'], \
r'http(.*)/f/(\w{10,10})/')
res = self.get(SHARED_LINKS_URL).json()
self.assertNotEmpty(res)
for fileshare in res['fileshares']:
self.assertIsNotNone(fileshare['username'])
self.assertIsNotNone(fileshare['repo_id'])
#self.assertIsNotNone(fileshare['ctime'])
self.assertIsNotNone(fileshare['s_type'])
self.assertIsNotNone(fileshare['token'])
self.assertIsNotNone(fileshare['view_cnt'])
self.assertIsNotNone(fileshare['path'])