Skip to content

Commit

Permalink
Merge branch '2322-recline-views-datastore-only'
Browse files Browse the repository at this point in the history
  • Loading branch information
joetsoi committed Mar 2, 2015
2 parents 13d7fee + 71fbb94 commit a96938e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ckanext/reclineview/plugin.py
Expand Up @@ -58,7 +58,9 @@ def update_config(self, config):
toolkit.add_resource('theme/public', 'ckanext-reclineview')

def can_view(self, data_dict):
return data_dict['resource'].get('datastore_active')
resource = data_dict['resource']
return (resource.get('datastore_active') or
resource.get('url') == '_datastore_only_resource')

def setup_template_variables(self, context, data_dict):
return {'resource_json': json.dumps(data_dict['resource']),
Expand All @@ -83,9 +85,12 @@ def info(self):
}

def can_view(self, data_dict):
if data_dict['resource'].get('datastore_active'):
resource = data_dict['resource']

if (resource.get('datastore_active') or
resource.get('url') == '_datastore_only_resource'):
return True
resource_format = data_dict['resource'].get('format', None)
resource_format = resource.get('format', None)
if resource_format:
return resource_format.lower() in ['csv', 'xls', 'xlsx', 'tsv']
else:
Expand Down
43 changes: 43 additions & 0 deletions ckanext/reclineview/tests/test_view.py
Expand Up @@ -9,6 +9,8 @@
import ckan.lib.create_test_data as create_test_data
import ckan.config.middleware as middleware

from ckan.new_tests import helpers, factories


class BaseTestReclineViewBase(tests.WsgiAppCase):
@classmethod
Expand Down Expand Up @@ -78,6 +80,47 @@ def test_can_view_bad_format_no_datastore(self):
assert not self.p.can_view(data_dict)


class TestReclineViewDatastoreOnly(helpers.FunctionalTestBase):

@classmethod
def setup_class(cls):
if not p.plugin_loaded('recline_view'):
p.load('recline_view')
if not p.plugin_loaded('datastore'):
p.load('datastore')
app_config = config.copy()
app_config['ckan.legacy_templates'] = 'false'
app_config['ckan.plugins'] = 'recline_view datastore'
app_config['ckan.views.default_views'] = 'recline_view'
wsgiapp = middleware.make_app(config['global_conf'], **app_config)
cls.app = paste.fixture.TestApp(wsgiapp)

@classmethod
def teardown_class(cls):
if p.plugin_loaded('recline_view'):
p.unload('recline_view')
if p.plugin_loaded('datastore'):
p.unload('datastore')

def test_create_datastore_only_view(self):
dataset = factories.Dataset()
data = {
'resource': {'package_id': dataset['id']},
'fields': [{'id': 'a'}, {'id': 'b'}],
'records': [{'a': 1, 'b': 'xyz'}, {'a': 2, 'b': 'zzz'}]
}
result = helpers.call_action('datastore_create', **data)

resource_id = result['resource_id']

url = h.url_for(controller='package', action='resource_read',
id=dataset['id'], resource_id=resource_id)

result = self.app.get(url)

assert 'data-module="data-viewer"' in result.body


class TestReclineGridView(BaseTestReclineViewBase):
view_type = 'recline_grid_view'
view_class = plugin.ReclineGridView
Expand Down

0 comments on commit a96938e

Please sign in to comment.