This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
media_test.go
299 lines (251 loc) · 9.97 KB
/
media_test.go
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
package gostagram
import (
"testing"
)
var (
media_id = ""
shortcode = ""
)
func LogMedia(media *Media, t *testing.T) {
if (*media).MediaType().IsImage() {
mediaImage := (*media).(MediaImage)
t.Log("------------------ Start Image Media ------------------")
t.Log("Id: ", DefaultStringValueIfEmpty(mediaImage.Id))
t.Log("Type: ", DefaultStringValueIfEmpty(mediaImage.Type))
t.Log("Link: ", DefaultStringValueIfEmpty(mediaImage.Link))
t.Log("Filter: ", DefaultStringValueIfEmpty(mediaImage.Filter))
t.Log("Created Time: ", DefaultStringValueIfEmpty(mediaImage.CreatedTime))
t.Log("------------------ Media Start User ------------------")
LogUser(&mediaImage.User, t)
t.Log("------------------ Media End User ------------------")
t.Log("User Has Liked: ", mediaImage.UserHasLiked)
t.Log("Attribution: ", mediaImage.Attribution)
t.Log("Tags: ", mediaImage.Tags)
t.Log("User in Photo: ")
for _, tmp := range mediaImage.UserInPhoto {
t.Log("User in Photo User: ")
LogUser(&tmp.User, t)
t.Log("User In Photo Position X: ", tmp.Position.X)
t.Log("User In Photo Position Y: ", tmp.Position.Y)
}
t.Log("Comments Count: ", mediaImage.Comments.Count)
t.Log("Caption Id: ", DefaultStringValueIfEmpty(mediaImage.Caption.Id))
t.Log("Caption Created Time: ", DefaultStringValueIfEmpty(mediaImage.Caption.CreatedTime))
t.Log("Caption Created Text: ", DefaultStringValueIfEmpty(mediaImage.Caption.Text))
t.Log("Caption User: ")
LogUser(&mediaImage.Caption.From, t)
t.Log("Likes Count: : ", mediaImage.Likes.Count)
t.Log("------------------ Start Thumbnail Videos ------------------")
LogImage(&mediaImage.Images.Thumbnail, t)
t.Log("------------------ End Thumbnail Videos ------------------")
t.Log("------------------ Start Low Resolution Image ------------------")
LogImage(&mediaImage.Images.LowResolution, t)
t.Log("------------------ End Low Resolution Image ------------------")
t.Log("------------------ Start Standard Resolution Image ------------------")
LogImage(&mediaImage.Images.StandardResolution, t)
t.Log("------------------ End Standard Resolution Image ------------------")
t.Log("Location Id: ", DefaultStringValueIfEmpty(mediaImage.Location.Id))
t.Log("Location Name: ", DefaultStringValueIfEmpty(mediaImage.Location.Name))
t.Log("Location Latitude: ", mediaImage.Location.Latitude)
t.Log("Location Longitude: ", mediaImage.Location.Longitude)
t.Log("Location Street Address: ", DefaultStringValueIfEmpty(mediaImage.Location.StreetAddress))
t.Log("------------------ End Image Media ------------------")
} else if (*media).MediaType().IsVideo() {
mediaVideo := (*media).(MediaVideo)
t.Log("------------------ Start Video Media ------------------")
t.Log("Id: ", DefaultStringValueIfEmpty(mediaVideo.Id))
t.Log("Type: ", DefaultStringValueIfEmpty(mediaVideo.Type))
t.Log("Link: ", DefaultStringValueIfEmpty(mediaVideo.Link))
t.Log("Filter: ", DefaultStringValueIfEmpty(mediaVideo.Filter))
t.Log("Created Time: ", DefaultStringValueIfEmpty(mediaVideo.CreatedTime))
t.Log("------------------ Media Start User ------------------")
LogUser(&mediaVideo.User, t)
t.Log("------------------ Media End User ------------------")
t.Log("User Has Liked: ", mediaVideo.UserHasLiked)
t.Log("Attribution: ", mediaVideo.Attribution)
t.Log("Tags: ", mediaVideo.Tags)
t.Log("User in Photo: ")
for _, tmp := range mediaVideo.UserInPhoto {
t.Log("User in Photo User:")
LogUser(&tmp.User, t)
t.Log("User In Photo Position X: ", tmp.Position.X)
t.Log("User In Photo Position Y: ", tmp.Position.Y)
}
t.Log("Comments Count: ", mediaVideo.Comments.Count)
t.Log("Caption Id: ", DefaultStringValueIfEmpty(mediaVideo.Caption.Id))
t.Log("Caption Created Time: ", DefaultStringValueIfEmpty(mediaVideo.Caption.CreatedTime))
t.Log("Caption Created Text: ", DefaultStringValueIfEmpty(mediaVideo.Caption.Text))
t.Log("Caption User: ")
LogUser(&mediaVideo.Caption.From, t)
t.Log("Likes Count: : ", mediaVideo.Likes.Count)
t.Log("------------------ Start Thumbnail Videos ------------------")
LogImage(&mediaVideo.Images.Thumbnail, t)
t.Log("------------------ End Thumbnail Videos ------------------")
t.Log("------------------ Start Low Resolution Image ------------------")
LogImage(&mediaVideo.Images.LowResolution, t)
t.Log("------------------ End Low Resolution Image ------------------")
t.Log("------------------ Start Standard Resolution Image ------------------")
LogImage(&mediaVideo.Images.StandardResolution, t)
t.Log("------------------ End Standard Resolution Image ------------------")
t.Log("Location Id: ", DefaultStringValueIfEmpty(mediaVideo.Location.Id))
t.Log("Location Name: ", DefaultStringValueIfEmpty(mediaVideo.Location.Name))
t.Log("Location Latitude: ", mediaVideo.Location.Latitude)
t.Log("Location Longitude: ", mediaVideo.Location.Longitude)
t.Log("Location Street Address: ", DefaultStringValueIfEmpty(mediaVideo.Location.StreetAddress))
t.Log("------------------ Start Standard Resolution Videos ------------------")
LogVideo(&mediaVideo.Videos.StandardResolution, t)
t.Log("------------------ End Standard Resolution Videos ------------------")
t.Log("------------------ End Start Resolution Videos ------------------")
LogVideo(&mediaVideo.Videos.LowResolution, t)
t.Log("------------------ End Low Resolution Videos ------------------")
t.Log("------------------ End Video Media ------------------")
}
}
func LogImage(image *Image, t *testing.T) {
t.Log("Image Url: ", DefaultStringValueIfEmpty(image.Url))
t.Log("Image Height: ", image.Height)
t.Log("Image Width: ", image.Width)
}
func LogVideo(video *VideoResolution, t *testing.T) {
t.Log("Video Url: ", DefaultStringValueIfEmpty(video.Url))
t.Log("Video Width: ", video.Width)
t.Log("Video Height: ", video.Height)
}
func IterateMedia(media_arr []*Media, t *testing.T) {
if len(media_arr) > 0 {
for _, media := range media_arr {
LogMedia(media, t)
}
} else {
t.Log("No content.")
}
}
func TestClient_GetCurrentUserRecentMedia(t *testing.T) {
client := CreateClient(t)
media_arr, err := client.GetCurrentUserRecentMedia(nil)
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetCurrentUserRecentMedia2(t *testing.T) {
client := CreateClient(t)
media_arr, err := client.GetCurrentUserRecentMedia(Parameters{
"count": "1",
})
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetCurrentUserRecentMedia3(t *testing.T) {
client := CreateClient(t)
media_arr, err := client.GetCurrentUserRecentMedia(Parameters{
"max_id": "1",
"min_id": "1",
"count": "1",
})
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetUserMedia(t *testing.T) {
FatalIfEmptyString(other_user_id, "user id cannot be empty.", t)
client := CreateClient(t)
media_arr, err := client.GetUserMedia(other_user_id, nil)
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetUserMedia2(t *testing.T) {
FatalIfEmptyString(other_user_id, "user id cannot be empty.", t)
client := CreateClient(t)
media_arr, err := client.GetUserMedia(other_user_id, Parameters{
"count": "1",
})
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetCurrentUserMediaLiked(t *testing.T) {
FatalIfEmptyString(media_id, "media id cannot be empty.", t)
client := CreateClient(t)
media_arr, err := client.GetCurrentUserMediaLiked(media_id, Parameters{})
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetCurrentUserMediaLiked2(t *testing.T) {
FatalIfEmptyString(media_id, "media id cannot be empty.", t)
client := CreateClient(t)
media_arr, err := client.GetCurrentUserMediaLiked(media_id, Parameters{
"count": "1",
})
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetMediaById(t *testing.T) {
FatalIfEmptyString(media_id, "media id cannot be empty.", t)
client := CreateClient(t)
media, err := client.GetMediaById(media_id)
PanicIfError(err, t)
LogMedia(media, t)
}
func TestClient_GetMediaByShortcode(t *testing.T) {
FatalIfEmptyString(shortcode, "shortcode cannot be empty.", t)
client := CreateClient(t)
media, err := client.GetMediaByShortcode(shortcode)
PanicIfError(err, t)
LogMedia(media, t)
}
func TestClient_SearchMedia(t *testing.T) {
client := CreateClient(t)
media_arr, err := client.SearchMedia("0", "0", nil)
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_SearchMedia2(t *testing.T) {
client := CreateClient(t)
media_arr, err := client.SearchMedia("0", "0", Parameters{
"distance": "2000",
})
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_SearchMedia_DistanceError(t *testing.T) {
client := CreateClient(t)
_, err := client.SearchMedia("0", "0", Parameters{
"distance": "asdasd",
})
if err != nil {
t.Log("Distance most be a digit")
} else {
t.Fatal("Error, distance parameter it is not a digit and request was sended anyway.")
}
}
func TestClient_SearchMedia_DistanceError2(t *testing.T) {
client := CreateClient(t)
_, err := client.SearchMedia("0", "0", Parameters{
"distance": "5001",
})
if err != nil {
t.Log("Success distance cannot be higher 5000")
} else {
t.Fatal("Error, distance parameter it is higher 5000 and request was sended anyway.")
}
}
func TestClient_GetRecentMediaTaggedByTagName(t *testing.T) {
FatalIfEmptyString(tagname, "tagname cannot be empty.", t)
client := CreateClient(t)
media_arr, err := client.GetRecentMediaTaggedByTagName(tagname, nil)
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetRecentMediaTaggedByTagName2(t *testing.T) {
FatalIfEmptyString(tagname, "tagname cannot be empty.", t)
client := CreateClient(t)
media_arr, err := client.GetRecentMediaTaggedByTagName(tagname, Parameters{
"count": "1",
})
PanicIfError(err, t)
IterateMedia(media_arr, t)
}
func TestClient_GetRecentMediaLocation(t *testing.T) {
FatalIfEmptyString(location_id, "Location id cannot be empty.", t)
client := CreateClient(t)
media_arr, err := client.GetRecentMediaLocation(location_id, nil)
PanicIfError(err, t)
IterateMedia(media_arr, t)
}