harvester-d4science/ckanext/harvest/tests/test_controller.py

59 lines
1.5 KiB
Python
Raw Normal View History

2016-01-14 11:06:25 +01:00
from ckan.lib.helpers import url_for
try:
2016-01-14 12:23:17 +01:00
from ckan.tests import helpers, factories
2016-01-14 11:06:25 +01:00
except ImportError:
2016-01-14 12:23:17 +01:00
from ckan.new_tests import helpers, factories
2016-01-14 11:06:25 +01:00
2016-01-14 12:23:17 +01:00
from ckanext.harvest.tests import factories as harvest_factories
2016-01-14 11:06:25 +01:00
2016-01-14 12:23:17 +01:00
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)
2016-01-14 11:06:25 +01:00
2016-01-14 12:23:17 +01:00
import ckanext.harvest.model as harvest_model
2016-01-14 11:06:25 +01:00
class TestController(helpers.FunctionalTestBase):
2016-01-14 12:23:17 +01:00
@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()
2016-01-14 11:06:25 +01:00
def test_new_form_is_rendered(self):
url = url_for('harvest_new')
app = self._get_test_app()
2016-01-14 12:23:17 +01:00
response = app.get(url, extra_environ=self.extra_environ)
2016-01-14 11:06:25 +01:00
assert_in('<form id="source-new"', response.body)
def test_edit_form_is_rendered(self):
2016-01-14 12:23:17 +01:00
source = harvest_factories.HarvestSource()
2016-01-14 11:06:25 +01:00
url = url_for('harvest_edit', id=source['id'])
app = self._get_test_app()
2016-01-14 12:23:17 +01:00
response = app.get(url, extra_environ=self.extra_environ)
2016-01-14 11:06:25 +01:00
assert_in('<form id="source-new"', response.body)