/
tests.py
78 lines (68 loc) · 2.32 KB
/
tests.py
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
import unittest
from unistorage.models import (FileFactory, TemporaryFile, PendingFile,
ImageFile, VideoFile, DocFile)
class TestFileFactory(unittest.TestCase):
def get_ok_image_response(self):
return {
'status': 'ok',
'data': {
'extra': {
'width': 100,
'height': 100,
'orientation': 1,
},
'mimetype': 'image/jpeg',
'name': 'some.jpeg',
'size': 211258,
'unistorage_type': 'image',
'url': 'http:///127.0.0.2/525cde8bf7c07954bec2552f',
},
'ttl': 604800,
}
def get_ok_video_response(self):
return {
'status': 'ok',
'data': {
'extra': {
'video': {
'width': 100,
'height': 100,
'codec': 'codec',
},
},
'mimetype': 'video/ogg',
'name': 'some.jpeg',
'size': 211258,
'unistorage_type': 'video',
'url': 'http:///127.0.0.2/525cde8bf7c07954bec2552f',
},
'ttl': 604800,
}
def get_just_uri_response(self):
return {
'status': 'just_uri',
'data': {
'url': 'http://127.0.0.1/503dd7c48149954c99f41a29',
},
'ttl': 15,
}
def get_wait_response(self):
return {
'status': 'wait',
'ttl': 5,
}
def test_just_uri(self):
response = self.get_just_uri_response()
result = FileFactory.build_from_dict(None, response)
self.assertIs(type(result), TemporaryFile)
def test_wait(self):
response = self.get_wait_response()
result = FileFactory.build_from_dict(None, response)
self.assertIs(type(result), PendingFile)
def test_ok(self):
response = self.get_ok_image_response()
result = FileFactory.build_from_dict(None, response)
self.assertIs(type(result), ImageFile)
response = self.get_ok_video_response()
result = FileFactory.build_from_dict(None, response)
self.assertIs(type(result), VideoFile)