Skip to content

Commit

Permalink
Changes in tests for the preview interface
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 5, 2012
1 parent 5aea0d8 commit 6b003a6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
17 changes: 17 additions & 0 deletions ckan/templates/tests/mock_resource_preview_template.html
@@ -0,0 +1,17 @@
{% extends 'dataviewer/base.html' %}

{% block page %}
<div>
<pre data-module="mock-preview">
<div class="loading">
{{ _('Loading...') }}
</div>
</pre>
</div>
{% endblock %}

{% block scripts %}
{{ super() }}

<script src="mock-preview.js" ?>
{% endblock %}
42 changes: 31 additions & 11 deletions ckan/tests/functional/test_preview_interface.py
@@ -1,9 +1,9 @@
from ckan.tests import *
import ckan.lib.helpers as h
import ckan.model as model
from ckan.lib.create_test_data import CreateTestData
from ckan.tests.pylons_controller import PylonsTestCase
from ckan.tests.functional.base import FunctionalTestCase
import ckan.plugins as plugins
import ckan.controllers.package as package
import ckan.tests.mock_plugin as mock


Expand All @@ -22,27 +22,47 @@ def setup_template_variables(self, context, data_dict):
self.calls['setup_template_variables'] += 1

def preview_template(self, context, data_dict):
self.calls['preview_template'] += 1
self.calls['preview_templates'] += 1
return 'tests/mock_resource_preview_template.html'


class TestPluggablePreviews(object):
class TestPluggablePreviews(FunctionalTestCase):
@classmethod
def setup_class(cls):
PylonsTestCase.setup_class()
cls.plugin = MockResourcePreviewExtension()
plugins.load(cls.plugin)
CreateTestData.create()

@classmethod
def teardown_class(cls):
model.repo.rebuild_db()
plugins.unload(cls.plugin)

def test_hook(self):
plugin = MockResourcePreviewExtension()
plugins.load(plugin)
'''
TODO:
* Modify mock plugin to only preview resources of type 'mock'
* Create a dataset with two resources (logic function), one of type mock and one
of another type, and check that the mock stuff is only rendered on
the relevant one and not the other
* (?) create resources of type csv, json and pdf and look if the relevant bits
are rendered (these tests should probably go in their relevant extensions)
'''



testpackage = model.Package.get('annakarenina')

pc = package.PackageController()
pc.resource_datapreview(testpackage.id, testpackage.resources[0])
offset = h.url_for(controller='package',
action='resource_datapreview',
id=testpackage.id,
resource_id=testpackage.resources[0].id)
result = self.app.get(offset, status=200)

assert 'mock-preview' in result.body
assert 'mock-preview.js' in result.body

assert plugin.calls['can_preview'] == 1, plugin.calls
plugins.unload(plugin)
assert self.plugin.calls['can_preview'] == 1, plugin.call
assert self.plugin.calls['setup_template_variables'] == 1, plugin.calls
assert self.plugin.calls['preview_templates'] == 1, plugin.calls

0 comments on commit 6b003a6

Please sign in to comment.