Remove mock API interfaces from storyboard.
This patch will remove the existing mock abstraction from storyboard, so that we can finally pair it with a real api. Change-Id: Ica72e8b71236033e1a7d34ed0e3c8177aad42917
This commit is contained in:
parent
32283d03cc
commit
3d304bf7fe
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the 'License'); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mock resource responses for the AuthProvider resource.
|
||||
*/
|
||||
|
||||
angular.module('sb.services')
|
||||
.run(function (mock) {
|
||||
'use strict';
|
||||
|
||||
var authProviders = [
|
||||
{
|
||||
'id': 0,
|
||||
'type': 'openid',
|
||||
'title': 'OpenID',
|
||||
'url': 'https://login.launchpad.net/+openid',
|
||||
'params': {
|
||||
'openid.ns': 'http://specs.openid.net/auth/2.0',
|
||||
'openid.claimed_id': 'http://specs.openid.net/auth' +
|
||||
'/2.0/identifier_select',
|
||||
'openid.identity': 'http://specs.openid.net/auth' +
|
||||
'/2.0/identifier_select',
|
||||
// 'openid.return_to': 'https://review.openstack.org/
|
||||
// openid?gerrit.mode=SIGN_IN&gerrit.token=%2Fq%2Fstatus%3Aopen%2Cn%2Cz',
|
||||
// 'openid.realm': 'https://review.openstack.org/',
|
||||
'openid.assoc_handle': '{HMAC-SHA256}{52c79079}{z+v4vA==}',
|
||||
'openid.mode': 'checkid_setup',
|
||||
'openid.ns.sreg': 'http://openid.net/sreg/1.0',
|
||||
'openid.sreg.required': 'fullname,email',
|
||||
'openid.ns.ext2': 'http://openid.net/srv/ax/1.0',
|
||||
'openid.ext2.mode': 'fetch_request',
|
||||
'openid.ext2.type.FirstName': 'http://schema.openid.net/' +
|
||||
'namePerson/first',
|
||||
'openid.ext2.type.LastName': 'http://schema.openid.net/' +
|
||||
'namePerson/last',
|
||||
'openid.ext2.type.Email': 'http://schema.openid.net/' +
|
||||
'contact/email',
|
||||
'openid.ext2.required': 'FirstName,LastName,Email'
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': 1,
|
||||
'type': 'openid_connect',
|
||||
'title': 'OpenID Connect',
|
||||
'url': 'https://www.google.com/prediscovered' +
|
||||
'/redirection/url',
|
||||
'params': {
|
||||
'list': 'of',
|
||||
'additional': 'parameters',
|
||||
'required': 'for.this.provider'
|
||||
}
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'type': 'ldap',
|
||||
'title': 'LDAP',
|
||||
'url': 'https://www.google.com/prediscovered' +
|
||||
'/redirection/url',
|
||||
'params': {
|
||||
'list': 'of',
|
||||
'additional': 'parameters',
|
||||
'required': 'for.this.provider'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
mock.api('/api/v1/auth/provider',
|
||||
'/api/v1/auth/provider/:id',
|
||||
'id',
|
||||
authProviders);
|
||||
|
||||
});
|
@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This service creates an automatic CRUD mock based on provided
|
||||
* urls and data sets.
|
||||
*
|
||||
* TODO(krotscheck): Once we have a real API, we can remove this.
|
||||
*/
|
||||
|
||||
angular.module('sb.services')
|
||||
.factory('mock', function ($log, $urlMatcherFactory, $httpBackend) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* URL matcher factory generator, used for testing API urls for
|
||||
* mocking.
|
||||
*
|
||||
* @param testUrl
|
||||
*/
|
||||
function matchUrl(testUrl) {
|
||||
var urlMatcher = $urlMatcherFactory.compile(testUrl);
|
||||
|
||||
return {
|
||||
test: function (url) {
|
||||
return urlMatcher.exec(url);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that extracts the array index from the default data
|
||||
* passed. Necessary because to simulate our mock list, we're splicing
|
||||
* all the time, so the actual indexes of the array may not match the
|
||||
* ID's of the items therein.
|
||||
*/
|
||||
function getIndexById(defaultData, idParamName, id) {
|
||||
for (var i = 0; i < defaultData.length; i++) {
|
||||
var item = defaultData[i];
|
||||
if (item[idParamName] === id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* This method mocks an entire RESTful api endpoint.
|
||||
*/
|
||||
api: function (searchUrl, crudUrl, crudIdParamName, defaultData) {
|
||||
this.search(searchUrl, defaultData);
|
||||
this.crud(searchUrl, crudUrl, crudIdParamName, defaultData);
|
||||
},
|
||||
|
||||
/**
|
||||
* This method creates a mock search service for the passed URL and
|
||||
* the provided data hash.
|
||||
*/
|
||||
search: function (searchUrl, defaultData) {
|
||||
$httpBackend.when('GET', matchUrl(searchUrl))
|
||||
.respond(function (method, url) {
|
||||
$log.info('[mock] ' + method + ' ' + url);
|
||||
return [200, {
|
||||
total: defaultData.length,
|
||||
offset: 0,
|
||||
limit: defaultData.length,
|
||||
results: defaultData
|
||||
}];
|
||||
}
|
||||
);
|
||||
},
|
||||
/**
|
||||
* This method creates a mock CRUD service for the passed URL,
|
||||
* ID parameter name, and data hash
|
||||
*/
|
||||
crud: function (createUrl, crudUrl, idParamName, defaultData) {
|
||||
var crudMatcher = matchUrl(crudUrl);
|
||||
var createMatcher = matchUrl(createUrl);
|
||||
|
||||
/**
|
||||
* Mock responder for a POST action. Extracts the ID from the
|
||||
* last item in our default data array and increments it, then
|
||||
* adds another item with that same ID.
|
||||
*/
|
||||
var createResolver = function (method, url, body) {
|
||||
$log.info('[mock] ' + method + ' ' + url);
|
||||
|
||||
body = JSON.parse(body);
|
||||
var now = Math.round(new Date().getTime() / 1000);
|
||||
body.id = defaultData[defaultData.length - 1].id + 1;
|
||||
// jshint -W106
|
||||
body.created_at = now;
|
||||
body.updated_at = now;
|
||||
// jshint +W106
|
||||
defaultData[body.id] = body;
|
||||
console.warn(defaultData);
|
||||
return [201, body];
|
||||
};
|
||||
|
||||
/**
|
||||
* Mock responder for Get/Update/Delete. Given an existing ID,
|
||||
* extracts the data from that location and either just sends
|
||||
* it back, or manipulates it as requested.
|
||||
*/
|
||||
var rudResolver = function (method, url, body) {
|
||||
$log.info('[mock] ' + method + ' ' + url);
|
||||
|
||||
if (!!body) {
|
||||
body = JSON.parse(body);
|
||||
}
|
||||
|
||||
var id = parseInt(crudMatcher.test(url).id);
|
||||
var idx = getIndexById(defaultData, idParamName, id);
|
||||
var now = Math.round(new Date().getTime() / 1000);
|
||||
|
||||
if (idx === false) {
|
||||
return [404];
|
||||
}
|
||||
|
||||
// Temporarily disable the camelcase JSHint rule.
|
||||
// jshint -W106
|
||||
switch (method) {
|
||||
case 'GET':
|
||||
return [200, defaultData[idx]];
|
||||
case 'PUT':
|
||||
body.id = id;
|
||||
body.updated_at = now;
|
||||
defaultData[idx] = body;
|
||||
return [200, defaultData[idx]];
|
||||
case 'DELETE':
|
||||
defaultData.splice(idx, 1);
|
||||
return [200];
|
||||
}
|
||||
// Re-enable camelcase check.
|
||||
// jshint +W106
|
||||
};
|
||||
|
||||
$httpBackend.when('POST', createMatcher)
|
||||
.respond(createResolver);
|
||||
$httpBackend.when('GET', crudMatcher)
|
||||
.respond(rudResolver);
|
||||
$httpBackend.when('PUT', crudMatcher)
|
||||
.respond(rudResolver);
|
||||
$httpBackend.when('DELETE', crudMatcher)
|
||||
.respond(rudResolver);
|
||||
}
|
||||
};
|
||||
});
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mock resource responses for the Project resource.
|
||||
*/
|
||||
|
||||
angular.module('sb.services')
|
||||
.run(function (mock) {
|
||||
'use strict';
|
||||
|
||||
var projects = [
|
||||
{
|
||||
'id': 0,
|
||||
'created_at': 12000000,
|
||||
'updated_at': 12000000,
|
||||
'name': 'Test Project 1',
|
||||
'description': 'Let\'s make orange juice',
|
||||
'team_id': null
|
||||
},
|
||||
{
|
||||
'id': 1,
|
||||
'created_at': 12000000,
|
||||
'updated_at': 12000000,
|
||||
'name': 'Test Project 2',
|
||||
'description': 'Let\'s make apple juice',
|
||||
'team_id': null
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'created_at': 12000000,
|
||||
'updated_at': 12000000,
|
||||
'name': 'Test Project 3',
|
||||
'description': 'Let\'s make lemonade',
|
||||
'team_id': null
|
||||
}
|
||||
];
|
||||
|
||||
mock.api('/api/v1/projects',
|
||||
'/api/v1/projects/:id',
|
||||
'id',
|
||||
projects);
|
||||
}
|
||||
)
|
||||
;
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mock resource responses for the Task resource.
|
||||
*/
|
||||
|
||||
angular.module('sb.services')
|
||||
.run(function (mock) {
|
||||
'use strict';
|
||||
|
||||
var tasks = [
|
||||
];
|
||||
|
||||
mock.api('/api/v1/tasks',
|
||||
'/api/v1/tasks/:id',
|
||||
'id',
|
||||
tasks);
|
||||
}
|
||||
)
|
||||
;
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mock resource responses for the Team resource.
|
||||
*/
|
||||
|
||||
angular.module('sb.services')
|
||||
.run(function (mock) {
|
||||
'use strict';
|
||||
|
||||
var team = [
|
||||
];
|
||||
|
||||
mock.api('/api/v1/teams',
|
||||
'/api/v1/teams/:id',
|
||||
'id',
|
||||
team);
|
||||
}
|
||||
)
|
||||
;
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mock resource responses for the User resource.
|
||||
*/
|
||||
|
||||
angular.module('sb.services')
|
||||
.run(function (mock) {
|
||||
'use strict';
|
||||
|
||||
var users = [
|
||||
];
|
||||
|
||||
mock.api('/api/v1/users',
|
||||
'/api/v1/users/:id',
|
||||
'id',
|
||||
users);
|
||||
}
|
||||
)
|
||||
;
|
@ -21,5 +21,4 @@
|
||||
*
|
||||
* @author Michael Krotscheck
|
||||
*/
|
||||
angular.module('sb.services', ['ngResource', 'ngCookies', 'ngMock',
|
||||
'ui.router']);
|
||||
angular.module('sb.services', ['ngResource', 'ngCookies']);
|
@ -28,23 +28,3 @@ angular.module('sb.services').factory('ProjectGroup',
|
||||
{id: '@id'},
|
||||
storyboardApiSignature);
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
This is initial commit adding pecan/wsme framework.
|
||||
Example operations are:
|
||||
* GET /v1/project_groups
|
||||
* GET /v1/project_groups/<group_name>
|
||||
|
||||
* GET /v1/projects
|
||||
* GET /v1/projects/<project_name>
|
||||
|
||||
* GET /v1/teams
|
||||
* GET /v1/teams/<team_name>
|
||||
* POST /v1/teams
|
||||
|
||||
* GET /v1/users
|
||||
* GET /v1/users/<username>
|
||||
* POST /v1/users
|
||||
* PUT /v1/users/<username>
|
||||
*/
|
Loading…
Reference in New Issue
Block a user