Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2180-idataset-form-functional-te…
Browse files Browse the repository at this point in the history
…sts'
  • Loading branch information
wardi committed Jan 14, 2015
2 parents e9e56dd + cc79960 commit 7dac7f5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ckan/templates/package/snippets/resources_list.html
Expand Up @@ -21,7 +21,7 @@ <h3>{{ _('Data and Resources') }}</h3>
{% endblock %}
</ul>
{% else %}
{% if h.check_access('resource_create', pkg) %}
{% if h.check_access('resource_create', {'package_id': pkg['id']}) %}
{% trans url=h.url_for(controller='package', action='new_resource', id=pkg.name) %}
<p class="empty">This dataset has no data, <a href="{{ url }}">why not add some?</a></p>
{% endtrans %}
Expand Down
@@ -1,9 +1,9 @@
{% ckan_extends %}

{# Remove 'free extras' from the package form, as we don't want to support
them on our example. #}
{% block custom_fields %}
{% endblock %}
{# You could remove 'free extras' from the package form like this, but we keep them for this example's tests.
{% block custom_fields %}
{% endblock %}
#}

{% block package_metadata_fields %}

Expand Down
64 changes: 64 additions & 0 deletions ckanext/example_idatasetform/tests/test_controllers.py
@@ -0,0 +1,64 @@
from nose.tools import assert_equal
from routes import url_for

import ckan.plugins as plugins
import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.model as model

submit_and_follow = helpers.submit_and_follow


def _get_package_edit_page(app, package_name):
user = factories.User()
env = {'REMOTE_USER': user['name'].encode('ascii')}
response = app.get(
url=url_for(controller='package', action='edit', id=package_name),
extra_environ=env,
)
return env, response


class TestPackageController(helpers.FunctionalTestBase):
@classmethod
def setup_class(cls):
super(TestPackageController, cls).setup_class()
plugins.load('example_idatasetform')

@classmethod
def teardown_class(cls):
plugins.unload('example_idatasetform')
super(TestPackageController, cls).teardown_class()

def test_edit_converted_extra_field(self):
dataset = factories.Dataset(custom_text='foo')
app = self._get_test_app()
env, response = _get_package_edit_page(app, dataset['name'])
form = response.forms['dataset-edit']
form['custom_text'] = u'bar'

response = submit_and_follow(app, form, env, 'save')
# just check it has finished the edit, rather than being sent on to the
# resource create/edit form.
assert_equal(response.req.path, '/dataset/%s' % dataset['name'])

pkg = model.Package.by_name(dataset['name'])
assert_equal(pkg.extras['custom_text'], u'bar')

def test_edit_custom_extra_field(self):
# i.e. an extra field that is not mentioned in the schema, filled in on
# the form in the 'custom-fields' section
dataset = factories.Dataset(extras=[{'key': 'testkey',
'value': 'foo'}])
app = self._get_test_app()
env, response = _get_package_edit_page(app, dataset['name'])
form = response.forms['dataset-edit']
form['extras__0__value'] = u'bar'

response = submit_and_follow(app, form, env, 'save')
# just check it has finished the edit, rather than being sent on to the
# resource create/edit form.
assert_equal(response.req.path, '/dataset/%s' % dataset['name'])

pkg = model.Package.by_name(dataset['name'])
assert_equal(pkg.extras['testkey'], u'bar')

0 comments on commit 7dac7f5

Please sign in to comment.