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

142 lines
4.0 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):
2018-10-26 13:38:09 +02:00
helpers.reset_db()
2016-01-14 12:23:17 +01:00
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()
2018-10-26 13:38:09 +02:00
def setup(self):
super(TestController, self).setup()
sysadmin = factories.Sysadmin()
self.extra_environ = {'REMOTE_USER': sysadmin['name'].encode('ascii')}
def test_index_page_is_rendered(self):
source1 = harvest_factories.HarvestSource()
source2 = harvest_factories.HarvestSource()
2016-01-14 11:06:25 +01:00
app = self._get_test_app()
2018-10-26 13:38:09 +02:00
response = app.get(u'/harvest')
assert_in(source1['title'], response.unicode_body)
assert_in(source2['title'], response.unicode_body)
def test_new_form_is_rendered(self):
app = self._get_test_app()
url = url_for('harvest_new')
2017-07-27 17:09:00 +02:00
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
2018-10-26 13:38:09 +02:00
assert_in('<form id="source-new"', response.unicode_body)
2016-01-14 11:06:25 +01:00
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
app = self._get_test_app()
2018-10-26 13:38:09 +02:00
url = url_for('harvest_edit', id=source['id'])
response = app.get(url, extra_environ=self.extra_environ)
assert_in('<form id="source-new"', response.unicode_body)
def test_source_page_rendered(self):
source = harvest_factories.HarvestSource()
app = self._get_test_app()
url = url_for('harvest_read', id=source['name'])
response = app.get(url, extra_environ=self.extra_environ)
assert_in(source['name'], response.unicode_body)
def test_admin_page_rendered(self):
source_obj = harvest_factories.HarvestSourceObj()
job = harvest_factories.HarvestJob(source=source_obj)
app = self._get_test_app()
url = url_for('harvest_admin', id=source_obj.id)
response = app.get(url, extra_environ=self.extra_environ)
assert_in(source_obj.title, response.unicode_body)
assert_in(job['id'], response.unicode_body)
def test_about_page_rendered(self):
source = harvest_factories.HarvestSource()
app = self._get_test_app()
url = url_for('harvest_about', id=source['name'])
response = app.get(url, extra_environ=self.extra_environ)
assert_in(source['name'], response.unicode_body)
def test_job_page_rendered(self):
job = harvest_factories.HarvestJob()
app = self._get_test_app()
url = url_for('harvest_job_list', source=job['source_id'])
2017-07-27 17:09:00 +02:00
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
2018-10-26 13:38:09 +02:00
assert_in(job['id'], response.unicode_body)
2018-10-26 14:11:20 +02:00
def test_job_show_last_page_rendered(self):
job = harvest_factories.HarvestJob()
app = self._get_test_app()
url = url_for('harvest_job_show_last', source=job['source_id'])
response = app.get(url, extra_environ=self.extra_environ)
assert_in(job['id'], response.unicode_body)
def test_job_show_page_rendered(self):
job = harvest_factories.HarvestJob()
app = self._get_test_app()
url = url_for(
'harvest_job_show', source=job['source_id'], id=job['id'])
response = app.get(url, extra_environ=self.extra_environ)
assert_in(job['id'], response.unicode_body)