Debian Codegraph @

dojox/data/tests/stores/FlickrRestStore.js

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