Debian Codegraph @

dojox/data/tests/stores/PicasaStore.js

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