forked from leancloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_file.py
More file actions
70 lines (49 loc) · 1.47 KB
/
Copy pathtest_file.py
File metadata and controls
70 lines (49 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# coding: utf-8
from StringIO import StringIO
from nose.tools import with_setup
import requests
import leancloud
from leancloud import File
from leancloud import ACL
__author__ = 'asaka'
def setup_func():
leancloud.init(
'pgk9e8orv8l9coak1rjht1avt2f4o9kptb0au0by5vbk9upb',
'hi4jsm62kok2qz2w2qphzryo564rzsrucl2czb0hn6ogwwnd',
)
def test_basic():
s = StringIO('blah blah blah')
f = File('blah', s)
assert f.name == 'blah'
assert f._metadata['size'] == 14
assert f._type == 'text/plain'
def test_create_with_url():
f = File.create_with_url('xxx', 'http://www.lenna.org/full/len_std.jpg')
assert f.url == 'http://www.lenna.org/full/len_std.jpg'
def test_create_without_data():
f = File.create_without_data(123)
assert f.id == 123
def test_acl():
acl = ACL()
f = File('blah', buffer('xxx'))
f.set_acl(acl)
assert f.get_acl() == acl
@with_setup(setup_func)
def test_save():
f = File('blah', buffer('xxx'))
f.save()
assert f.id
# @with_setup(setup_func)
# def test_save_external():
# f = File.create_with_url('lenna.jpg', 'http://www.lenna.org/full/len_std.jpg')
# f.save()
# assert f.id
@with_setup(setup_func)
def test_thumbnail():
r = requests.get('http://www.lenna.org/full/len_std.jpg')
b = buffer(r.content)
f = File('lenna.jpg', b)
f.save()
assert f.id
url = f.get_thumbnail_url(100, 100)
assert url.endswith('?imageView/2/w/100/h/100/q/100/format/png')