[backend][s]: Webstore and DataProxy now passing tests again.
This commit is contained in:
@@ -144,8 +144,7 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
sync: function(method, model, options) {
|
sync: function(method, model, options) {
|
||||||
if (method === "read") {
|
if (method === "read") {
|
||||||
if (model.__type__ == 'Dataset') {
|
if (model.__type__ == 'Dataset') {
|
||||||
var dataset = model;
|
var base = model.get('webstore_url');
|
||||||
var base = dataset.backendConfig.url;
|
|
||||||
var schemaUrl = base + '/schema.json';
|
var schemaUrl = base + '/schema.json';
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: schemaUrl,
|
url: schemaUrl,
|
||||||
@@ -157,11 +156,11 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
headers = _.map(schema.data, function(item) {
|
headers = _.map(schema.data, function(item) {
|
||||||
return item.name;
|
return item.name;
|
||||||
});
|
});
|
||||||
dataset.set({
|
model.set({
|
||||||
headers: headers
|
headers: headers
|
||||||
});
|
});
|
||||||
dataset.docCount = schema.count;
|
model.docCount = schema.count;
|
||||||
dfd.resolve(dataset, jqxhr);
|
dfd.resolve(model, jqxhr);
|
||||||
})
|
})
|
||||||
.fail(function(arguments) {
|
.fail(function(arguments) {
|
||||||
dfd.reject(arguments);
|
dfd.reject(arguments);
|
||||||
@@ -171,7 +170,7 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
query: function(model, queryObj) {
|
query: function(model, queryObj) {
|
||||||
var base = model.backendConfig.url;
|
var base = model.get('webstore_url');
|
||||||
var data = {
|
var data = {
|
||||||
_limit: queryObj.size
|
_limit: queryObj.size
|
||||||
, _offset: queryObj.offset
|
, _offset: queryObj.offset
|
||||||
@@ -196,33 +195,30 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
//
|
//
|
||||||
// For connecting to [DataProxy-s](http://github.com/okfn/dataproxy).
|
// For connecting to [DataProxy-s](http://github.com/okfn/dataproxy).
|
||||||
//
|
//
|
||||||
// Set a Dataset to use this backend:
|
|
||||||
//
|
|
||||||
// dataset.backendConfig = {
|
|
||||||
// // required
|
|
||||||
// url: {url-of-data-to-proxy},
|
|
||||||
// format: csv | xls,
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// When initializing the DataProxy backend you can set the following attributes:
|
// When initializing the DataProxy backend you can set the following attributes:
|
||||||
//
|
//
|
||||||
// * dataproxy: {url-to-proxy} (optional). Defaults to http://jsonpdataproxy.appspot.com
|
// * dataproxy: {url-to-proxy} (optional). Defaults to http://jsonpdataproxy.appspot.com
|
||||||
//
|
//
|
||||||
|
// Datasets using using this backend should set the following attributes:
|
||||||
|
//
|
||||||
|
// * url: (required) url-of-data-to-proxy
|
||||||
|
// * format: (optional) csv | xls (defaults to csv if not specified)
|
||||||
|
//
|
||||||
// Note that this is a **read-only** backend.
|
// Note that this is a **read-only** backend.
|
||||||
my.BackendDataProxy = Backbone.Model.extend({
|
my.BackendDataProxy = Backbone.Model.extend({
|
||||||
defaults: {
|
defaults: {
|
||||||
dataproxy: 'http://jsonpdataproxy.appspot.com'
|
dataproxy_url: 'http://jsonpdataproxy.appspot.com'
|
||||||
},
|
},
|
||||||
sync: function(method, model, options) {
|
sync: function(method, model, options) {
|
||||||
|
var self = this;
|
||||||
if (method === "read") {
|
if (method === "read") {
|
||||||
if (model.__type__ == 'Dataset') {
|
if (model.__type__ == 'Dataset') {
|
||||||
var dataset = model;
|
var base = self.get('dataproxy_url');
|
||||||
var base = my.backends['dataproxy'].get('dataproxy');
|
|
||||||
// TODO: should we cache for extra efficiency
|
// TODO: should we cache for extra efficiency
|
||||||
var data = {
|
var data = {
|
||||||
url: dataset.backendConfig.url
|
url: model.get('url')
|
||||||
, 'max-results': 1
|
, 'max-results': 1
|
||||||
, type: dataset.backendConfig.format
|
, type: model.get('format') || 'csv'
|
||||||
};
|
};
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: base
|
url: base
|
||||||
@@ -231,10 +227,10 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
});
|
});
|
||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
wrapInTimeout(jqxhr).done(function(results) {
|
wrapInTimeout(jqxhr).done(function(results) {
|
||||||
dataset.set({
|
model.set({
|
||||||
headers: results.fields
|
headers: results.fields
|
||||||
});
|
});
|
||||||
dfd.resolve(dataset, jqxhr);
|
dfd.resolve(model, jqxhr);
|
||||||
})
|
})
|
||||||
.fail(function(arguments) {
|
.fail(function(arguments) {
|
||||||
dfd.reject(arguments);
|
dfd.reject(arguments);
|
||||||
@@ -246,11 +242,11 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
query: function(dataset, queryObj) {
|
query: function(dataset, queryObj) {
|
||||||
var base = my.backends['dataproxy'].get('dataproxy');
|
var base = this.get('dataproxy_url');
|
||||||
var data = {
|
var data = {
|
||||||
url: dataset.backendConfig.url
|
url: dataset.get('url')
|
||||||
, 'max-results': queryObj.size
|
, 'max-results': queryObj.size
|
||||||
, type: dataset.backendConfig.format
|
, type: dataset.get('format')
|
||||||
};
|
};
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: base
|
url: base
|
||||||
|
|||||||
@@ -144,12 +144,12 @@ webstoreData = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test('Webstore Backend', function() {
|
test('Webstore Backend', function() {
|
||||||
var dataset = new recline.Model.Dataset();
|
var dataset = new recline.Model.Dataset({
|
||||||
dataset.backendConfig = {
|
id: 'my-id',
|
||||||
type: 'webstore',
|
webstore_url: 'http://webstore.test.ckan.org/rufuspollock/demo/data'
|
||||||
url: 'http://webstore.test.ckan.org/rufuspollock/demo/data'
|
},
|
||||||
};
|
'webstore'
|
||||||
|
);
|
||||||
var stub = sinon.stub($, 'ajax', function(options) {
|
var stub = sinon.stub($, 'ajax', function(options) {
|
||||||
if (options.url.indexOf('schema.json') != -1) {
|
if (options.url.indexOf('schema.json') != -1) {
|
||||||
return {
|
return {
|
||||||
@@ -175,10 +175,10 @@ test('Webstore Backend', function() {
|
|||||||
dataset.fetch().done(function(dataset) {
|
dataset.fetch().done(function(dataset) {
|
||||||
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('headers'));
|
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('headers'));
|
||||||
equal(3, dataset.docCount)
|
equal(3, dataset.docCount)
|
||||||
// dataset.query().done(function(docList) {
|
dataset.query().done(function(docList) {
|
||||||
// equal(3, docList.length)
|
equal(3, docList.length)
|
||||||
// equal("2009-01-01", docList.models[0].get('date'));
|
equal("2009-01-01", docList.models[0].get('date'));
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
$.ajax.restore();
|
$.ajax.restore();
|
||||||
});
|
});
|
||||||
@@ -250,11 +250,11 @@ var dataProxyData = {
|
|||||||
test('DataProxy Backend', function() {
|
test('DataProxy Backend', function() {
|
||||||
// needed only if not stubbing
|
// needed only if not stubbing
|
||||||
// stop();
|
// stop();
|
||||||
var dataset = new recline.Model.Dataset();
|
var dataset = new recline.Model.Dataset({
|
||||||
dataset.backendConfig = {
|
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
|
||||||
type: 'dataproxy',
|
},
|
||||||
url: 'http://webstore.thedatahub.org/rufuspollock/gold_prices/data.csv'
|
'dataproxy'
|
||||||
};
|
);
|
||||||
|
|
||||||
var stub = sinon.stub($, 'ajax', function(options) {
|
var stub = sinon.stub($, 'ajax', function(options) {
|
||||||
var partialUrl = 'jsonpdataproxy.appspot.com';
|
var partialUrl = 'jsonpdataproxy.appspot.com';
|
||||||
|
|||||||
Reference in New Issue
Block a user