2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.data.tests.stores.FlickrRestStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.data.tests.stores.FlickrRestStore"] = true;
|
|
|
3 |
dojo.provide("dojox.data.tests.stores.FlickrRestStore");
|
|
|
4 |
dojo.require("dojox.data.FlickrRestStore");
|
|
|
5 |
dojo.require("dojo.data.api.Read");
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
dojox.data.tests.stores.FlickrRestStore.error = function(t, d, errData){
|
|
|
9 |
// summary:
|
|
|
10 |
// The error callback function to be used for all of the tests.
|
|
|
11 |
d.errback(errData);
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
doh.register("dojox.data.tests.stores.FlickrRestStore",
|
|
|
15 |
[
|
|
|
16 |
{
|
|
|
17 |
name: "ReadAPI: Fetch_One",
|
|
|
18 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
19 |
runTest: function(t) {
|
|
|
20 |
// summary:
|
|
|
21 |
// Simple test of a basic fetch on FlickrRestStore of a single item.
|
|
|
22 |
// description:
|
|
|
23 |
// Simple test of a basic fetch on FlickrRestStore of a single item.
|
|
|
24 |
|
|
|
25 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
26 |
|
|
|
27 |
var d = new doh.Deferred();
|
|
|
28 |
function onComplete(items, request){
|
|
|
29 |
t.is(1, items.length);
|
|
|
30 |
d.callback(true);
|
|
|
31 |
}
|
|
|
32 |
flickrStore.fetch({
|
|
|
33 |
query: {
|
|
|
34 |
userid: "44153025@N00",
|
|
|
35 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
36 |
},
|
|
|
37 |
count: 1,
|
|
|
38 |
onComplete: onComplete,
|
|
|
39 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, doh, d)
|
|
|
40 |
});
|
|
|
41 |
return d; //Object
|
|
|
42 |
}
|
|
|
43 |
},
|
|
|
44 |
{
|
|
|
45 |
name: "ReadAPI: Fetch_20_Streaming",
|
|
|
46 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
47 |
runTest: function(t) {
|
|
|
48 |
// summary:
|
|
|
49 |
// Simple test of a basic fetch on FlickrRestStore.
|
|
|
50 |
// description:
|
|
|
51 |
// Simple test of a basic fetch on FlickrRestStore.
|
|
|
52 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
53 |
|
|
|
54 |
var d = new doh.Deferred();
|
|
|
55 |
var count = 0;
|
|
|
56 |
|
|
|
57 |
function onItem(item, requestObj){
|
|
|
58 |
t.assertTrue(flickrStore.isItem(item));
|
|
|
59 |
count++;
|
|
|
60 |
}
|
|
|
61 |
function onComplete(items, request){
|
|
|
62 |
t.is(5, count);
|
|
|
63 |
|
|
|
64 |
t.is(null, items);
|
|
|
65 |
d.callback(true);
|
|
|
66 |
}
|
|
|
67 |
//Get everything...
|
|
|
68 |
flickrStore.fetch({
|
|
|
69 |
query: {
|
|
|
70 |
userid: "44153025@N00",
|
|
|
71 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
72 |
},
|
|
|
73 |
onBegin: null,
|
|
|
74 |
count: 5,
|
|
|
75 |
onItem: onItem,
|
|
|
76 |
onComplete: onComplete,
|
|
|
77 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
78 |
});
|
|
|
79 |
return d; //Object
|
|
|
80 |
}
|
|
|
81 |
},
|
|
|
82 |
{
|
|
|
83 |
name: "ReadAPI: Fetch_Paging",
|
|
|
84 |
timeout: 30000, //30 seconds. Flickr can sometimes be slow.
|
|
|
85 |
runTest: function(t) {
|
|
|
86 |
// summary:
|
|
|
87 |
// Test of multiple fetches on a single result. Paging, if you will.
|
|
|
88 |
// description:
|
|
|
89 |
// Test of multiple fetches on a single result. Paging, if you will.
|
|
|
90 |
|
|
|
91 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
92 |
|
|
|
93 |
var d = new doh.Deferred();
|
|
|
94 |
function dumpFirstFetch(items, request){
|
|
|
95 |
t.is(5, items.length);
|
|
|
96 |
request.start = 3;
|
|
|
97 |
request.count = 1;
|
|
|
98 |
request.onComplete = dumpSecondFetch;
|
|
|
99 |
flickrStore.fetch(request);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
function dumpSecondFetch(items, request){
|
|
|
103 |
t.is(1, items.length);
|
|
|
104 |
request.start = 0;
|
|
|
105 |
request.count = 5;
|
|
|
106 |
request.onComplete = dumpThirdFetch;
|
|
|
107 |
flickrStore.fetch(request);
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
function dumpThirdFetch(items, request){
|
|
|
111 |
t.is(5, items.length);
|
|
|
112 |
request.start = 2;
|
|
|
113 |
request.count = 18;
|
|
|
114 |
request.onComplete = dumpFourthFetch;
|
|
|
115 |
flickrStore.fetch(request);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
function dumpFourthFetch(items, request){
|
|
|
119 |
t.is(18, items.length);
|
|
|
120 |
request.start = 9;
|
|
|
121 |
request.count = 11;
|
|
|
122 |
request.onComplete = dumpFifthFetch;
|
|
|
123 |
flickrStore.fetch(request);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
function dumpFifthFetch(items, request){
|
|
|
127 |
t.is(11, items.length);
|
|
|
128 |
request.start = 4;
|
|
|
129 |
request.count = 16;
|
|
|
130 |
request.onComplete = dumpSixthFetch;
|
|
|
131 |
flickrStore.fetch(request);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
function dumpSixthFetch(items, request){
|
|
|
135 |
t.is(16, items.length);
|
|
|
136 |
d.callback(true);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
function completed(items, request){
|
|
|
140 |
t.is(7, items.length);
|
|
|
141 |
request.start = 1;
|
|
|
142 |
request.count = 5;
|
|
|
143 |
request.onComplete = dumpFirstFetch;
|
|
|
144 |
flickrStore.fetch(request);
|
|
|
145 |
}
|
|
|
146 |
flickrStore.fetch({
|
|
|
147 |
query: {
|
|
|
148 |
userid: "44153025@N00",
|
|
|
149 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
150 |
},
|
|
|
151 |
count: 7,
|
|
|
152 |
onComplete: completed,
|
|
|
153 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
154 |
});
|
|
|
155 |
return d; //Object
|
|
|
156 |
}
|
|
|
157 |
},
|
|
|
158 |
{
|
|
|
159 |
name: "ReadAPI: getLabel",
|
|
|
160 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
161 |
runTest: function(t) {
|
|
|
162 |
// summary:
|
|
|
163 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
164 |
// description:
|
|
|
165 |
// Simple test of the getLabel function against a store set that has a label defined.
|
|
|
166 |
|
|
|
167 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
168 |
|
|
|
169 |
var d = new doh.Deferred();
|
|
|
170 |
function onComplete(items, request){
|
|
|
171 |
t.assertEqual(items.length, 1);
|
|
|
172 |
var label = flickrStore.getLabel(items[0]);
|
|
|
173 |
t.assertTrue(label !== null);
|
|
|
174 |
d.callback(true);
|
|
|
175 |
}
|
|
|
176 |
flickrStore.fetch({
|
|
|
177 |
query: {
|
|
|
178 |
userid: "44153025@N00",
|
|
|
179 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
180 |
},
|
|
|
181 |
count: 1,
|
|
|
182 |
onComplete: onComplete,
|
|
|
183 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
184 |
});
|
|
|
185 |
return d;
|
|
|
186 |
}
|
|
|
187 |
},
|
|
|
188 |
{
|
|
|
189 |
name: "ReadAPI: getLabelAttributes",
|
|
|
190 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
191 |
runTest: function(t) {
|
|
|
192 |
// summary:
|
|
|
193 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
194 |
// description:
|
|
|
195 |
// Simple test of the getLabelAttributes function against a store set that has a label defined.
|
|
|
196 |
|
|
|
197 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
198 |
|
|
|
199 |
var d = new doh.Deferred();
|
|
|
200 |
function onComplete(items, request){
|
|
|
201 |
t.assertEqual(items.length, 1);
|
|
|
202 |
var labelList = flickrStore.getLabelAttributes(items[0]);
|
|
|
203 |
t.assertTrue(dojo.isArray(labelList));
|
|
|
204 |
t.assertEqual("title", labelList[0]);
|
|
|
205 |
d.callback(true);
|
|
|
206 |
}
|
|
|
207 |
flickrStore.fetch({
|
|
|
208 |
query: {
|
|
|
209 |
userid: "44153025@N00",
|
|
|
210 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
211 |
},
|
|
|
212 |
count: 1,
|
|
|
213 |
onComplete: onComplete,
|
|
|
214 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
215 |
});
|
|
|
216 |
return d;
|
|
|
217 |
}
|
|
|
218 |
},
|
|
|
219 |
{
|
|
|
220 |
name: "ReadAPI: getValue",
|
|
|
221 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
222 |
runTest: function(t) {
|
|
|
223 |
// summary:
|
|
|
224 |
// Simple test of the getValue function of the store.
|
|
|
225 |
// description:
|
|
|
226 |
// Simple test of the getValue function of the store.
|
|
|
227 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
228 |
|
|
|
229 |
var d = new doh.Deferred();
|
|
|
230 |
function completedAll(items){
|
|
|
231 |
t.is(1, items.length);
|
|
|
232 |
t.assertTrue(flickrStore.getValue(items[0], "title") !== null);
|
|
|
233 |
t.assertTrue(flickrStore.getValue(items[0], "imageUrl") !== null);
|
|
|
234 |
t.assertTrue(flickrStore.getValue(items[0], "imageUrlSmall") !== null);
|
|
|
235 |
t.assertTrue(flickrStore.getValue(items[0], "imageUrlMedium") !== null);
|
|
|
236 |
d.callback(true);
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
//Get one item and look at it.
|
|
|
240 |
flickrStore.fetch({
|
|
|
241 |
query: {
|
|
|
242 |
userid: "44153025@N00",
|
|
|
243 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
244 |
},
|
|
|
245 |
count: 1,
|
|
|
246 |
onComplete: completedAll,
|
|
|
247 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)});
|
|
|
248 |
return d; //Object
|
|
|
249 |
}
|
|
|
250 |
},
|
|
|
251 |
{
|
|
|
252 |
name: "ReadAPI: getValues",
|
|
|
253 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
254 |
runTest: function(t) {
|
|
|
255 |
// summary:
|
|
|
256 |
// Simple test of the getValue function of the store.
|
|
|
257 |
// description:
|
|
|
258 |
// Simple test of the getValue function of the store.
|
|
|
259 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
260 |
|
|
|
261 |
var d = new doh.Deferred();
|
|
|
262 |
function completedAll(items){
|
|
|
263 |
t.is(1, items.length);
|
|
|
264 |
var title = flickrStore.getValues(items[0], "title");
|
|
|
265 |
t.assertTrue(title instanceof Array);
|
|
|
266 |
|
|
|
267 |
var imgUrl = flickrStore.getValues(items[0], "imageUrl");
|
|
|
268 |
t.assertTrue(imgUrl instanceof Array);
|
|
|
269 |
|
|
|
270 |
var imgUrlSmall = flickrStore.getValues(items[0], "imageUrlSmall");
|
|
|
271 |
t.assertTrue(imgUrlSmall instanceof Array);
|
|
|
272 |
|
|
|
273 |
var imgUrlMedium = flickrStore.getValues(items[0], "imageUrlMedium");
|
|
|
274 |
t.assertTrue(imgUrlMedium instanceof Array);
|
|
|
275 |
d.callback(true);
|
|
|
276 |
}
|
|
|
277 |
//Get one item and look at it.
|
|
|
278 |
flickrStore.fetch({
|
|
|
279 |
query: {
|
|
|
280 |
userid: "44153025@N00",
|
|
|
281 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
282 |
},
|
|
|
283 |
count: 1,
|
|
|
284 |
onComplete: completedAll,
|
|
|
285 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error,
|
|
|
286 |
t,
|
|
|
287 |
d)});
|
|
|
288 |
return d; //Object
|
|
|
289 |
}
|
|
|
290 |
},
|
|
|
291 |
{
|
|
|
292 |
name: "ReadAPI: isItem",
|
|
|
293 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
294 |
runTest: function(t) {
|
|
|
295 |
// summary:
|
|
|
296 |
// Simple test of the isItem function of the store
|
|
|
297 |
// description:
|
|
|
298 |
// Simple test of the isItem function of the store
|
|
|
299 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
300 |
|
|
|
301 |
var d = new doh.Deferred();
|
|
|
302 |
function completedAll(items){
|
|
|
303 |
t.is(5, items.length);
|
|
|
304 |
for(var i=0; i < items.length; i++){
|
|
|
305 |
t.assertTrue(flickrStore.isItem(items[i]));
|
|
|
306 |
}
|
|
|
307 |
d.callback(true);
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
//Get everything...
|
|
|
311 |
flickrStore.fetch({
|
|
|
312 |
query: {
|
|
|
313 |
userid: "44153025@N00",
|
|
|
314 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
315 |
},
|
|
|
316 |
count: 5,
|
|
|
317 |
onComplete: completedAll,
|
|
|
318 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
319 |
});
|
|
|
320 |
return d; //Object
|
|
|
321 |
}
|
|
|
322 |
},
|
|
|
323 |
{
|
|
|
324 |
name: "ReadAPI: hasAttribute",
|
|
|
325 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
326 |
runTest: function(t) {
|
|
|
327 |
// summary:
|
|
|
328 |
// Simple test of the hasAttribute function of the store
|
|
|
329 |
// description:
|
|
|
330 |
// Simple test of the hasAttribute function of the store
|
|
|
331 |
|
|
|
332 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
333 |
|
|
|
334 |
var d = new doh.Deferred();
|
|
|
335 |
function onComplete(items){
|
|
|
336 |
t.is(1, items.length);
|
|
|
337 |
t.assertTrue(items[0] !== null);
|
|
|
338 |
t.assertTrue(flickrStore.hasAttribute(items[0], "title"));
|
|
|
339 |
t.assertTrue(flickrStore.hasAttribute(items[0], "author"));
|
|
|
340 |
t.assertTrue(!flickrStore.hasAttribute(items[0], "Nothing"));
|
|
|
341 |
t.assertTrue(!flickrStore.hasAttribute(items[0], "Text"));
|
|
|
342 |
|
|
|
343 |
//Test that null attributes throw an exception
|
|
|
344 |
var passed = false;
|
|
|
345 |
try{
|
|
|
346 |
flickrStore.hasAttribute(items[0], null);
|
|
|
347 |
}catch (e){
|
|
|
348 |
passed = true;
|
|
|
349 |
}
|
|
|
350 |
t.assertTrue(passed);
|
|
|
351 |
d.callback(true);
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
//Get one item...
|
|
|
355 |
flickrStore.fetch({
|
|
|
356 |
query: {
|
|
|
357 |
userid: "44153025@N00",
|
|
|
358 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
359 |
},
|
|
|
360 |
count: 1,
|
|
|
361 |
onComplete: onComplete,
|
|
|
362 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
363 |
});
|
|
|
364 |
return d; //Object
|
|
|
365 |
}
|
|
|
366 |
},
|
|
|
367 |
{
|
|
|
368 |
name: "ReadAPI: containsValue",
|
|
|
369 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
370 |
runTest: function(t) {
|
|
|
371 |
// summary:
|
|
|
372 |
// Simple test of the containsValue function of the store
|
|
|
373 |
// description:
|
|
|
374 |
// Simple test of the containsValue function of the store
|
|
|
375 |
|
|
|
376 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
377 |
|
|
|
378 |
var d = new doh.Deferred();
|
|
|
379 |
function onComplete(items){
|
|
|
380 |
t.is(1, items.length);
|
|
|
381 |
d.callback(true);
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
//Get one item...
|
|
|
385 |
flickrStore.fetch({
|
|
|
386 |
query: {
|
|
|
387 |
userid: "44153025@N00",
|
|
|
388 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
389 |
},
|
|
|
390 |
count: 1,
|
|
|
391 |
onComplete: onComplete,
|
|
|
392 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
393 |
});
|
|
|
394 |
return d; //Object
|
|
|
395 |
}
|
|
|
396 |
},
|
|
|
397 |
{
|
|
|
398 |
name: "ReadAPI: getAttributes",
|
|
|
399 |
timeout: 10000, //10 seconds. Flickr can sometimes be slow.
|
|
|
400 |
runTest: function(t) {
|
|
|
401 |
// summary:
|
|
|
402 |
// Simple test of the getAttributes function of the store
|
|
|
403 |
// description:
|
|
|
404 |
// Simple test of the getAttributes function of the store
|
|
|
405 |
|
|
|
406 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
407 |
|
|
|
408 |
var d = new doh.Deferred();
|
|
|
409 |
function onComplete(items){
|
|
|
410 |
t.is(1, items.length);
|
|
|
411 |
t.assertTrue(flickrStore.isItem(items[0]));
|
|
|
412 |
|
|
|
413 |
var attributes = flickrStore.getAttributes(items[0]);
|
|
|
414 |
t.is(9, attributes.length);
|
|
|
415 |
d.callback(true);
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
//Get everything...
|
|
|
419 |
flickrStore.fetch({
|
|
|
420 |
query: {
|
|
|
421 |
userid: "44153025@N00",
|
|
|
422 |
apikey: "8c6803164dbc395fb7131c9d54843627"
|
|
|
423 |
},
|
|
|
424 |
count: 1,
|
|
|
425 |
onComplete: onComplete,
|
|
|
426 |
onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
|
|
|
427 |
});
|
|
|
428 |
return d; //Object
|
|
|
429 |
}
|
|
|
430 |
},
|
|
|
431 |
function testReadAPI_getFeatures(t){
|
|
|
432 |
// summary:
|
|
|
433 |
// Simple test of the getFeatures function of the store
|
|
|
434 |
// description:
|
|
|
435 |
// Simple test of the getFeatures function of the store
|
|
|
436 |
|
|
|
437 |
var flickrStore = new dojox.data.FlickrRestStore();
|
|
|
438 |
|
|
|
439 |
var features = flickrStore.getFeatures();
|
|
|
440 |
var count = 0;
|
|
|
441 |
for(i in features){
|
|
|
442 |
t.assertTrue((i === "dojo.data.api.Read"));
|
|
|
443 |
count++;
|
|
|
444 |
}
|
|
|
445 |
t.assertTrue(count === 1);
|
|
|
446 |
},
|
|
|
447 |
function testReadAPI_functionConformance(t){
|
|
|
448 |
// summary:
|
|
|
449 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
450 |
// description:
|
|
|
451 |
// Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
|
|
|
452 |
|
|
|
453 |
var testStore = new dojox.data.FlickrRestStore();
|
|
|
454 |
var readApi = new dojo.data.api.Read();
|
|
|
455 |
var passed = true;
|
|
|
456 |
|
|
|
457 |
for(i in readApi){
|
|
|
458 |
if(i.toString().charAt(0) !== '_')
|
|
|
459 |
{
|
|
|
460 |
var member = readApi[i];
|
|
|
461 |
//Check that all the 'Read' defined functions exist on the test store.
|
|
|
462 |
if(typeof member === "function"){
|
|
|
463 |
var testStoreMember = testStore[i];
|
|
|
464 |
if(!(typeof testStoreMember === "function")){
|
|
|
465 |
passed = false;
|
|
|
466 |
break;
|
|
|
467 |
}
|
|
|
468 |
}
|
|
|
469 |
}
|
|
|
470 |
}
|
|
|
471 |
}
|
|
|
472 |
]
|
|
|
473 |
);
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
}
|