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
110 lines (81 loc) · 2.39 KB
/
Copy pathtest_file.py
File metadata and controls
110 lines (81 loc) · 2.39 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# coding: utf-8
import os
from StringIO import StringIO
import cStringIO
from nose.tools import with_setup
from nose.tools import assert_raises
from nose.tools import raises
import requests
import leancloud
from leancloud import File
from leancloud import ACL
__author__ = 'asaka'
def setup_func():
leancloud.init(
os.environ['APP_ID'],
master_key=os.environ['MASTER_KEY']
)
def test_basic():
s = StringIO('blah blah blah')
s1 = cStringIO.StringIO()
s1.write('blah blah blah')
f1 = File('Blah', s, 'text/plain')
f2 = File('Blah', s1)
f3 = File('Blah', open('tests/test_file.txt', 'r'))
for f in (f1, f2, f3):
assert f.name == 'Blah'
assert f._metadata['size'] == 14
assert f.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', meta_data={})
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'))
assert_raises(TypeError, f.set_acl, 'a')
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
@raises(ValueError)
def test_thumbnail_url_erorr():
f = File.create_with_url('xx', False)
f.get_thumbnail_url(100, 100)
@raises(ValueError)
def test_thumbnail_size_erorr():
r = requests.get('http://www.lenna.org/full/len_std.jpg')
b = buffer(r.content)
f = File('Lenna2.jpg', b)
f.save()
assert f.id
f.get_thumbnail_url(-1, -1)
f.get_thumbnail_url(1, 1, quality=110)
@with_setup(setup_func)
def test_thumbnail():
r = requests.get('http://www.lenna.org/full/len_std.jpg')
b = buffer(r.content)
f = File('Lenna2.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')
@with_setup(setup_func)
def test_destroy():
r = requests.get('http://www.lenna.org/full/len_std.jpg')
b = buffer(r.content)
f = File('Lenna2.jpg', b)
f.save()
assert f.id
f.destroy()