def test_new_form_is_rendered(self): app = self._get_test_app() url = url_for('harvest_new') response = app.get(url, extra_environ=self.extra_environ) assert_in('<form id="source-new"', response.unicode_body)
def test_organization_read(self): response = self.app.get(url=url_for(controller='organization', action='read', id=self.organization['id']), status=200, extra_environ=self.user_env) assert_in(self.organization['title'], response) assert_in(self.organization['description'], response)
def test_date_invalid(self): app = self._get_test_app() response = app.get( '/api/search/revision' '?since_time=2010-02-31T00:00:00', status=400) assert_in('Bad request - ValueError: day is out of range for month', response.body)
def test_organization_read(self): response = self.app.get( url=url_for(controller="organization", action="read", id=self.organization["id"]), status=200, extra_environ=self.user_env, ) assert_in(self.organization["title"], response) assert_in(self.organization["description"], response)
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_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_show_issue(self): app = self._get_test_app() env = {"REMOTE_USER": self.user["name"].encode("ascii")} response = app.get( url=toolkit.url_for("issues_show", dataset_id=self.dataset["id"], issue_number=self.issue["number"]), extra_environ=env, ) assert_in(self.issue["title"], response) assert_in(self.issue["description"], response)
def test_edit_form_is_rendered(self): source = harvest_factories.HarvestSource() app = self._get_test_app() 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_index_page_is_rendered(self): source1 = harvest_factories.HarvestSource() source2 = harvest_factories.HarvestSource() app = self._get_test_app() response = app.get(u'/harvest') assert_in(source1['title'], response.unicode_body) assert_in(source2['title'], response.unicode_body)
def test_show_issue(self): app = self._get_test_app() env = {'REMOTE_USER': self.user['name'].encode('ascii')} response = app.get( url=toolkit.url_for('issues_show', dataset_id=self.dataset['id'], issue_number=self.issue['number']), extra_environ=env, ) assert_in(self.issue['title'], response) assert_in(self.issue['description'], response)
def test_new_form_is_rendered(self): app = self._get_test_app() if hasattr(app, 'flask_app'): with app.flask_app.test_request_context(): url = url_for('harvest_new') else: url = url_for('harvest_new') response = app.get(url, extra_environ=self.extra_environ) assert_in('<form id="source-new"', response.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_edit_form_is_rendered(self): source = harvest_factories.HarvestSource() app = self._get_test_app() if hasattr(app, 'flask_app'): with app.flask_app.test_request_context(): url = url_for('harvest_edit', id=source['id']) else: url = url_for('harvest_edit', id=source['id']) response = app.get(url, extra_environ=self.extra_environ) assert_in('<form id="source-new"', response.body)
def test_harvest_job_create_as_sysadmin(self): source = factories.HarvestSource(**SOURCE_DICT.copy()) site_user = toolkit.get_action('get_site_user')( {'model': model, 'ignore_auth': True}, {})['name'] data_dict = { 'source_id': source['id'], 'run': True } job = toolkit.get_action('harvest_job_create')( {'user': site_user}, data_dict) assert_equal(job['source_id'], source['id']) assert_equal(job['status'], 'Running') assert_equal(job['gather_started'], None) assert_in('stats', job.keys())
def test_harvest_job_create_as_admin(self): # as if an admin user presses 'refresh' user = ckan_factories.User() user['capacity'] = 'admin' org = ckan_factories.Organization(users=[user]) source_dict = dict(SOURCE_DICT.items() + [('publisher_id', org['id'])]) source = factories.HarvestSource(**source_dict) data_dict = {'source_id': source['id'], 'run': True} job = toolkit.get_action('harvest_job_create')({ 'user': user['name'] }, data_dict) assert_equal(job['source_id'], source['id']) assert_equal(job['status'], 'Running') assert_equal(job['gather_started'], None) assert_in('stats', job.keys())
def test_harvest_job_create_as_admin(self): # as if an admin user presses 'refresh' user = ckan_factories.User() user['capacity'] = 'admin' org = ckan_factories.Organization(users=[user]) source_dict = dict(SOURCE_DICT.items() + [('publisher_id', org['id'])]) source = factories.HarvestSource(**source_dict) data_dict = { 'source_id': source['id'], 'run': True } job = toolkit.get_action('harvest_job_create')( {'user': user['name']}, data_dict) assert_equal(job['source_id'], source['id']) assert_equal(job['status'], 'Running') assert_equal(job['gather_started'], None) assert_in('stats', job.keys())
def test_no_value(self): app = self._get_test_app() response = app.get('/api/search/revision?since_id=', status=400) assert_in('Bad request - No revision specified', response.body)
def test_revision_doesnt_exist_api_v2(self): app = self._get_test_app() response = app.get('/api/2/search/revision?since_id=1234', status=404) assert_in('Not found - There is no revision', response.body)
def test_date_instead_of_revision(self): app = self._get_test_app() response = app.get( '/api/search/revision' '?since_id=2010-01-01T00:00:00', status=404) assert_in('Not found - There is no revision', response.body)
def test_no_search_term_api_v2(self): app = self._get_test_app() response = app.get('/api/2/search/revision', status=400) assert_in('Bad request - Missing search term', response.body)
def test_file_url(self): url = u'file:///home/root/test.txt' result = self.check_link(url) assert_in(u'Invalid url scheme. Please use one of: ftp http https', result['url_errors'])
def test_url_with_503(self, url): result = self.check_link(url) assert_in('Server returned HTTP error status: 503 Service Unavailable', result['url_errors'])
def test_url_with_404(self, url): result = self.check_link(url) assert_in('Server returned HTTP error status: 404 Not Found', result['url_errors'])
def test_date_invalid(self): app = self._get_test_app() response = app.get('/api/search/revision' '?since_time=2010-02-31T00:00:00', status=400) assert_in('Bad request - ValueError: day is out of range for month', response.body)
def test_date_instead_of_revision(self): app = self._get_test_app() response = app.get('/api/search/revision' '?since_id=2010-01-01T00:00:00', status=404) assert_in('Not found - There is no revision', response.body)
def test_empty_url(self): url = u'' result = self.check_link(url) assert_in("URL parsing failure - did not find a host name", result['url_errors'])