PageRenderTime 40ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/public/javascripts/dojo/release/dojo/dojox/data/tests/stores/FlickrRestStore.js

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