Skip to content
Snippets Groups Projects
Commit c9c839e6 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Open origin api

Close T201
parent 8baa12e9
No related branches found
No related tags found
No related merge requests found
......@@ -357,6 +357,13 @@ def api_search(q):
return jsonify({'found': service.lookup_hash(q)})
@app.route('/api/1/origin/<string:origin_id>')
@jsonp
def api_origin(origin_id):
"""Return information about origin"""
return jsonify({'origin': service.lookup_origin(origin_id)})
@app.route('/api/1/browse/<string:q>/')
@jsonp
def api_browse(q):
......
......@@ -69,6 +69,19 @@ def lookup_hash_origin(q):
return converters.from_origin(origin)
def lookup_origin(origin_id):
"""Return information about the origin with id origin_id.
Args:
origin_id as string
Returns:
origin information as dict.
"""
return main.storage().origin_get({'id': origin_id})
def stat_counters():
"""Return the stat counters for Software Heritage
......
......@@ -163,3 +163,32 @@ class ApiTestCase(unittest.TestCase):
mock_service.upload_and_search.assert_called_once_with(
'simple-filename')
@patch('swh.web.ui.controller.service')
@istest
def api_origin(self, mock_service):
# given
mock_service.lookup_origin.return_value = {
'id': 'origin-0',
'lister': 'uuid-lister-0',
'project': 'uuid-project-0',
'url': 'ftp://some/url/to/origin/0',
'type': 'ftp'}
# when
rv = self.app.get('/api/1/origin/origin-0')
# then
self.assertEquals(rv.status_code, 200)
self.assertEquals(rv.mimetype, 'application/json')
response_data = json.loads(rv.data.decode('utf-8'))
self.assertEquals(response_data, {
'origin': {
'id': 'origin-0',
'lister': 'uuid-lister-0',
'project': 'uuid-project-0',
'url': 'ftp://some/url/to/origin/0',
'type': 'ftp'
}
})
......@@ -153,3 +153,25 @@ class ServiceTestCase(unittest.TestCase):
mock_upload.save_in_upload_folder.assert_called_with(file)
mock_upload.cleanup.assert_called_with('/tmp/blah')
@istest
def lookup_origin(self):
# given
self.storage.origin_get = MagicMock(return_value={
'id': 'origin-id',
'lister': 'uuid-lister',
'project': 'uuid-project',
'url': 'ftp://some/url/to/origin',
'type': 'ftp'})
# when
actual_origin = service.lookup_origin('origin-id')
# then
self.assertEqual(actual_origin, {'id': 'origin-id',
'lister': 'uuid-lister',
'project': 'uuid-project',
'url': 'ftp://some/url/to/origin',
'type': 'ftp'})
self.storage.origin_get.assert_called_with({'id': 'origin-id'})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment