Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new datastore action to return info on tables.
When called with a resource id, provides the names and types of the fields stored in the datastore, and a count of the total number of rows. This might be useful in providing info to people who want to call the search apis.
- Loading branch information
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import json | ||
import nose | ||
import pprint | ||
|
||
import pylons | ||
import sqlalchemy.orm as orm | ||
|
||
import ckan.plugins as p | ||
import ckan.lib.create_test_data as ctd | ||
import ckan.model as model | ||
import ckan.tests as tests | ||
|
||
import ckanext.datastore.db as db | ||
from ckanext.datastore.tests.helpers import extract, rebuild_all_dbs | ||
|
||
import ckan.new_tests.helpers as helpers | ||
import ckan.new_tests.factories as factories | ||
|
||
assert_equals = nose.tools.assert_equals | ||
assert_raises = nose.tools.assert_raises | ||
|
||
|
||
class TestDatastoreInfo(object): | ||
@classmethod | ||
def setup_class(cls): | ||
if not tests.is_datastore_supported(): | ||
raise nose.SkipTest("Datastore not supported") | ||
plugin = p.load('datastore') | ||
if plugin.legacy_mode: | ||
# make sure we undo adding the plugin | ||
p.unload('datastore') | ||
raise nose.SkipTest("Info is not supported in legacy mode") | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
p.unload('datastore') | ||
helpers.reset_db() | ||
|
||
def test_info_success(self): | ||
resource = factories.Resource() | ||
data = { | ||
'resource_id': resource['id'], | ||
'force': True, | ||
'records': [ | ||
{'from': 'Brazil', 'to': 'Brazil', 'num': 2}, | ||
{'from': 'Brazil', 'to': 'Italy', 'num': 22} | ||
], | ||
} | ||
result = helpers.call_action('datastore_create', **data) | ||
|
||
info = helpers.call_action('datastore_info', id=resource['id']) | ||
|
||
assert info['meta']['count'] == 2, info['meta'] | ||
assert len(info['schema']) == 3 | ||
assert info['schema']['to'] == 'text' | ||
assert info['schema']['from'] == 'text' | ||
assert info['schema']['num'] == 'number', info['schema'] |