From 497dfeea02cc836c6f78269730dd978aed8f3a31 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 14 Jan 2016 10:06:25 +0000 Subject: [PATCH 1/5] Add test for missing form --- ckanext/harvest/tests/test_controller.py | 36 ++++++++++++++++++++++++ test-core.ini | 1 + 2 files changed, 37 insertions(+) create mode 100644 ckanext/harvest/tests/test_controller.py diff --git a/ckanext/harvest/tests/test_controller.py b/ckanext/harvest/tests/test_controller.py new file mode 100644 index 0000000..6028ba5 --- /dev/null +++ b/ckanext/harvest/tests/test_controller.py @@ -0,0 +1,36 @@ +from ckan.lib.helpers import url_for + +try: + from ckan.tests import helpers +except ImportError: + from ckan.new_tests import helpers + +from ckanext.harvest.tests import factories + + +assert_in = helpers.assert_in + + +class TestController(helpers.FunctionalTestBase): + + def test_new_form_is_rendered(self): + + url = url_for('harvest_new') + + app = self._get_test_app() + + response = app.get(url) + + assert_in('
Date: Thu, 14 Jan 2016 10:16:45 +0000 Subject: [PATCH 2/5] [#219] Don't use c.form to render the form --- ckanext/harvest/templates_new/source/edit.html | 4 +++- ckanext/harvest/templates_new/source/new.html | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ckanext/harvest/templates_new/source/edit.html b/ckanext/harvest/templates_new/source/edit.html index c5a62bc..d74489b 100644 --- a/ckanext/harvest/templates_new/source/edit.html +++ b/ckanext/harvest/templates_new/source/edit.html @@ -4,6 +4,8 @@ {% block primary_content_inner %}
- {% block form %}{{ c.form | safe }}{% endblock %} + {% block form %} + {{- h.snippet(form_snippet, c=c, **form_vars) -}} + {% endblock %}
{% endblock %} diff --git a/ckanext/harvest/templates_new/source/new.html b/ckanext/harvest/templates_new/source/new.html index f98e69c..eaeb0e1 100644 --- a/ckanext/harvest/templates_new/source/new.html +++ b/ckanext/harvest/templates_new/source/new.html @@ -13,7 +13,9 @@ {% block primary_content %}
- {% block form %}{{ c.form | safe }}{% endblock %} + {% block form %} + {{- h.snippet(form_snippet, c=c, **form_vars) -}} + {% endblock %}
{% endblock %} From 0bae79b526ef805963fa6e328e335983de5dcb6a Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 14 Jan 2016 11:15:48 +0000 Subject: [PATCH 3/5] Run tests with debug=false --- test-core.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-core.ini b/test-core.ini index 976c701..9abedfb 100644 --- a/test-core.ini +++ b/test-core.ini @@ -1,5 +1,5 @@ [DEFAULT] -debug = true +debug = false # Uncomment and replace with the address which should receive any error reports #email_to = you@yourdomain.com smtp_server = localhost From 5bf0ac9b86576d82ee56bd49abfd7b729ee16881 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 14 Jan 2016 11:23:17 +0000 Subject: [PATCH 4/5] [#219] Fix tests auth --- ckanext/harvest/tests/test_controller.py | 36 +++++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/ckanext/harvest/tests/test_controller.py b/ckanext/harvest/tests/test_controller.py index 6028ba5..86fd4b3 100644 --- a/ckanext/harvest/tests/test_controller.py +++ b/ckanext/harvest/tests/test_controller.py @@ -1,36 +1,58 @@ from ckan.lib.helpers import url_for try: - from ckan.tests import helpers + from ckan.tests import helpers, factories except ImportError: - from ckan.new_tests import helpers + from ckan.new_tests import helpers, factories -from ckanext.harvest.tests import factories +from ckanext.harvest.tests import factories as harvest_factories +try: + from ckan.tests.helpers import assert_in +except ImportError: + # for ckan 2.2 + try: + from nose.tools import assert_in + except ImportError: + # Python 2.6 doesn't have it + def assert_in(a, b, msg=None): + assert a in b, msg or '%r was not in %r' % (a, b) -assert_in = helpers.assert_in +import ckanext.harvest.model as harvest_model class TestController(helpers.FunctionalTestBase): + @classmethod + def setup_class(cls): + super(TestController, cls).setup_class() + harvest_model.setup() + sysadmin = factories.Sysadmin() + cls.extra_environ = {'REMOTE_USER': sysadmin['name'].encode('ascii')} + + @classmethod + def teardown_class(cls): + super(TestController, cls).teardown_class() + helpers.reset_db() + def test_new_form_is_rendered(self): url = url_for('harvest_new') app = self._get_test_app() - response = app.get(url) + response = app.get(url, extra_environ=self.extra_environ) assert_in(' Date: Thu, 14 Jan 2016 11:23:41 +0000 Subject: [PATCH 5/5] [#219] Support CKAN < 2.3 --- ckanext/harvest/templates_new/source/edit.html | 7 ++++++- ckanext/harvest/templates_new/source/new.html | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ckanext/harvest/templates_new/source/edit.html b/ckanext/harvest/templates_new/source/edit.html index d74489b..bf34bf4 100644 --- a/ckanext/harvest/templates_new/source/edit.html +++ b/ckanext/harvest/templates_new/source/edit.html @@ -5,7 +5,12 @@ {% block primary_content_inner %}
{% block form %} - {{- h.snippet(form_snippet, c=c, **form_vars) -}} + {% if c.form %} + {# CKAN < 2.3 #} + {{ c.form | safe }} + {% else %} + {{- h.snippet(form_snippet, c=c, **form_vars) -}} + {% endif %} {% endblock %}
{% endblock %} diff --git a/ckanext/harvest/templates_new/source/new.html b/ckanext/harvest/templates_new/source/new.html index eaeb0e1..00b4418 100644 --- a/ckanext/harvest/templates_new/source/new.html +++ b/ckanext/harvest/templates_new/source/new.html @@ -14,7 +14,12 @@
{% block form %} - {{- h.snippet(form_snippet, c=c, **form_vars) -}} + {% if c.form %} + {# CKAN < 2.3 #} + {{ c.form | safe }} + {% else %} + {{- h.snippet(form_snippet, c=c, **form_vars) -}} + {% endif %} {% endblock %}