-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_smuglr.py
135 lines (111 loc) · 3.41 KB
/
test_smuglr.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import datetime
import urllib
import httpretty
from smuglr import BASE_URL, Client
NICKNAME = 'test-nickname'
APIKEY = 'test-api-key'
SITE_PASSWORD = 'site-password'
def load_fixture(name):
with open('fixtures/' + name, 'rb') as f:
return f.read()
def fake_image(id, key):
return {
'album': {'title': 'Test'},
'id': id,
'key': key,
}
def register_request(method, response=None, params=None):
params = params or {}
base_params = {
'NickName': NICKNAME,
'APIKey': APIKEY,
'method': method,
'SitePassword': SITE_PASSWORD
}
params.update(base_params)
query_params = urllib.parse.urlencode(params)
url = BASE_URL + '?' + query_params
httpretty.register_uri(httpretty.GET, url, body=response)
@httpretty.activate
def test_fetch_albums():
register_request('smugmug.albums.get',
load_fixture('smugmug.albums.get.json'))
client = Client(APIKEY, NICKNAME, SITE_PASSWORD)
albums = client.fetch_albums()
assert len(albums) == 2, albums
assert {'title': 'Album 1', 'id': 1, 'key': 'album-1'} in albums
assert {'title': 'Album 2', 'id': 2, 'key': 'album-2'} in albums
@httpretty.activate
def test_fetch_album_image_ids():
register_request(
'smugmug.images.get',
params={
'AlbumId': 1,
'AlbumKey': 'album-1'
},
response=load_fixture('smugmug.images.get.json')
)
client = Client(APIKEY, NICKNAME, SITE_PASSWORD)
album = {
'id': 1,
'key': 'album-1',
'title': 'Test',
}
media_items = client.fetch_album_image_ids(album)
assert len(media_items) == 2
assert media_items == [
{
'id': 1,
'key': 'image-1',
'album': {'id': 1, 'key': 'album-1', 'title': 'Test'},
},
{
'id': 2,
'key': 'video-2',
'album': {'id': 1, 'key': 'album-1', 'title': 'Test'},
}
]
@httpretty.activate
def test_fetch_image_photo():
register_request(
'smugmug.images.getInfo',
params={
'ImageId': 1,
'ImageKey': 'image-1'
},
response=load_fixture('smugmug.images.getInfo-image.json')
)
client = Client(APIKEY, NICKNAME, SITE_PASSWORD)
image_info = fake_image(1, 'image-1')
data = client.fetch_image(image_info)
assert data == {
'album': {'title': 'Test'},
'type': 'photo',
'id': 1,
'key': 'image-1',
'url': 'https://test-nickname.smugmug.com/Family/album-1/i-asdfasdf/0/42424242/O/image.jpg',
'filename': 'image.jpeg',
'modified_at': datetime.datetime(2014, 4, 21, 18, 40, 23),
}
@httpretty.activate
def test_fetch_image_video():
register_request(
'smugmug.images.getInfo',
params={
'ImageId': 2,
'ImageKey': 'video-2'
},
response=load_fixture('smugmug.images.getInfo-video.json')
)
client = Client(APIKEY, NICKNAME, SITE_PASSWORD)
image_info = fake_image(2, 'video-2')
data = client.fetch_image(image_info)
assert data == {
'album': {'title': 'Test'},
'type': 'video',
'id': 2,
'key': 'video-2',
'url': 'https://test-nickname.smugmug.com/album-1/i-4418Qs/0/asdfasdf/1280/VIDEO-1280.mp4',
'filename': 'VIDEO.MP4',
'modified_at': datetime.datetime(2016, 2, 10, 7, 21, 45),
}