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");
8 dojox.data.tests.stores.FlickrRestStore.error = function(t, d, errData){
10 // The error callback function to be used for all of the tests.
14 doh.register("dojox.data.tests.stores.FlickrRestStore",
17 name: "ReadAPI: Fetch_One",
18 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
19 runTest: function(t) {
21 // Simple test of a basic fetch on FlickrRestStore of a single item.
23 // Simple test of a basic fetch on FlickrRestStore of a single item.
25 var flickrStore = new dojox.data.FlickrRestStore();
27 var d = new doh.Deferred();
28 function onComplete(items, request){
29 t.is(1, items.length);
34 userid: "44153025@N00",
35 apikey: "8c6803164dbc395fb7131c9d54843627"
38 onComplete: onComplete,
39 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, doh, d)
45 name: "ReadAPI: Fetch_20_Streaming",
46 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
47 runTest: function(t) {
49 // Simple test of a basic fetch on FlickrRestStore.
51 // Simple test of a basic fetch on FlickrRestStore.
52 var flickrStore = new dojox.data.FlickrRestStore();
54 var d = new doh.Deferred();
57 function onItem(item, requestObj){
58 t.assertTrue(flickrStore.isItem(item));
61 function onComplete(items, request){
70 userid: "44153025@N00",
71 apikey: "8c6803164dbc395fb7131c9d54843627"
76 onComplete: onComplete,
77 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
83 name: "ReadAPI: Fetch_Paging",
84 timeout: 30000, //30 seconds. Flickr can sometimes be slow.
85 runTest: function(t) {
87 // Test of multiple fetches on a single result. Paging, if you will.
89 // Test of multiple fetches on a single result. Paging, if you will.
91 var flickrStore = new dojox.data.FlickrRestStore();
93 var d = new doh.Deferred();
94 function dumpFirstFetch(items, request){
95 t.is(5, items.length);
98 request.onComplete = dumpSecondFetch;
99 flickrStore.fetch(request);
102 function dumpSecondFetch(items, request){
103 t.is(1, items.length);
106 request.onComplete = dumpThirdFetch;
107 flickrStore.fetch(request);
110 function dumpThirdFetch(items, request){
111 t.is(5, items.length);
114 request.onComplete = dumpFourthFetch;
115 flickrStore.fetch(request);
118 function dumpFourthFetch(items, request){
119 t.is(18, items.length);
122 request.onComplete = dumpFifthFetch;
123 flickrStore.fetch(request);
126 function dumpFifthFetch(items, request){
127 t.is(11, items.length);
130 request.onComplete = dumpSixthFetch;
131 flickrStore.fetch(request);
134 function dumpSixthFetch(items, request){
135 t.is(16, items.length);
139 function completed(items, request){
140 t.is(7, items.length);
143 request.onComplete = dumpFirstFetch;
144 flickrStore.fetch(request);
148 userid: "44153025@N00",
149 apikey: "8c6803164dbc395fb7131c9d54843627"
152 onComplete: completed,
153 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
159 name: "ReadAPI: getLabel",
160 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
161 runTest: function(t) {
163 // Simple test of the getLabel function against a store set that has a label defined.
165 // Simple test of the getLabel function against a store set that has a label defined.
167 var flickrStore = new dojox.data.FlickrRestStore();
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);
178 userid: "44153025@N00",
179 apikey: "8c6803164dbc395fb7131c9d54843627"
182 onComplete: onComplete,
183 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
189 name: "ReadAPI: getLabelAttributes",
190 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
191 runTest: function(t) {
193 // Simple test of the getLabelAttributes function against a store set that has a label defined.
195 // Simple test of the getLabelAttributes function against a store set that has a label defined.
197 var flickrStore = new dojox.data.FlickrRestStore();
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]);
209 userid: "44153025@N00",
210 apikey: "8c6803164dbc395fb7131c9d54843627"
213 onComplete: onComplete,
214 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
220 name: "ReadAPI: getValue",
221 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
222 runTest: function(t) {
224 // Simple test of the getValue function of the store.
226 // Simple test of the getValue function of the store.
227 var flickrStore = new dojox.data.FlickrRestStore();
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);
239 //Get one item and look at it.
242 userid: "44153025@N00",
243 apikey: "8c6803164dbc395fb7131c9d54843627"
246 onComplete: completedAll,
247 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)});
252 name: "ReadAPI: getValues",
253 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
254 runTest: function(t) {
256 // Simple test of the getValue function of the store.
258 // Simple test of the getValue function of the store.
259 var flickrStore = new dojox.data.FlickrRestStore();
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);
267 var imgUrl = flickrStore.getValues(items[0], "imageUrl");
268 t.assertTrue(imgUrl instanceof Array);
270 var imgUrlSmall = flickrStore.getValues(items[0], "imageUrlSmall");
271 t.assertTrue(imgUrlSmall instanceof Array);
273 var imgUrlMedium = flickrStore.getValues(items[0], "imageUrlMedium");
274 t.assertTrue(imgUrlMedium instanceof Array);
277 //Get one item and look at it.
280 userid: "44153025@N00",
281 apikey: "8c6803164dbc395fb7131c9d54843627"
284 onComplete: completedAll,
285 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error,
292 name: "ReadAPI: isItem",
293 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
294 runTest: function(t) {
296 // Simple test of the isItem function of the store
298 // Simple test of the isItem function of the store
299 var flickrStore = new dojox.data.FlickrRestStore();
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]));
313 userid: "44153025@N00",
314 apikey: "8c6803164dbc395fb7131c9d54843627"
317 onComplete: completedAll,
318 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
324 name: "ReadAPI: hasAttribute",
325 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
326 runTest: function(t) {
328 // Simple test of the hasAttribute function of the store
330 // Simple test of the hasAttribute function of the store
332 var flickrStore = new dojox.data.FlickrRestStore();
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"));
343 //Test that null attributes throw an exception
346 flickrStore.hasAttribute(items[0], null);
350 t.assertTrue(passed);
357 userid: "44153025@N00",
358 apikey: "8c6803164dbc395fb7131c9d54843627"
361 onComplete: onComplete,
362 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
368 name: "ReadAPI: containsValue",
369 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
370 runTest: function(t) {
372 // Simple test of the containsValue function of the store
374 // Simple test of the containsValue function of the store
376 var flickrStore = new dojox.data.FlickrRestStore();
378 var d = new doh.Deferred();
379 function onComplete(items){
380 t.is(1, items.length);
387 userid: "44153025@N00",
388 apikey: "8c6803164dbc395fb7131c9d54843627"
391 onComplete: onComplete,
392 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
398 name: "ReadAPI: getAttributes",
399 timeout: 10000, //10 seconds. Flickr can sometimes be slow.
400 runTest: function(t) {
402 // Simple test of the getAttributes function of the store
404 // Simple test of the getAttributes function of the store
406 var flickrStore = new dojox.data.FlickrRestStore();
408 var d = new doh.Deferred();
409 function onComplete(items){
410 t.is(1, items.length);
411 t.assertTrue(flickrStore.isItem(items[0]));
413 var attributes = flickrStore.getAttributes(items[0]);
414 t.is(9, attributes.length);
421 userid: "44153025@N00",
422 apikey: "8c6803164dbc395fb7131c9d54843627"
425 onComplete: onComplete,
426 onError: dojo.partial(dojox.data.tests.stores.FlickrRestStore.error, t, d)
431 function testReadAPI_getFeatures(t){
433 // Simple test of the getFeatures function of the store
435 // Simple test of the getFeatures function of the store
437 var flickrStore = new dojox.data.FlickrRestStore();
439 var features = flickrStore.getFeatures();
442 t.assertTrue((i === "dojo.data.api.Read"));
445 t.assertTrue(count === 1);
447 function testReadAPI_functionConformance(t){
449 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
451 // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances.
453 var testStore = new dojox.data.FlickrRestStore();
454 var readApi = new dojo.data.api.Read();
458 if(i.toString().charAt(0) !== '_')
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")){