def test_packages(self): response = self.app.get(url(controller='load', action='packages')) # Show title for packages assert '<a href="http://ckan.net/package/baz">The Baz dataset</a>' in response # Show 'import' link for importable packages import_url = url(controller='load', action='start', package='bar') assert '<a href="%s">' % import_url in response # Show 'diagnose' link for non-importable packages diagnose_url = url(controller='load', action='diagnose', package='baz') assert '<a href="%s">' % diagnose_url in response
def test_start(self, have_role_mock): have_role_mock.return_value = True # Pretend to be admin user. response = self.app.get(url(controller='load', action='start', package='bar')) # Redirects to status page status_path = url(controller='job', action='status', job_id='import_bar') assert response.headers['Location'].endswith(status_path), \ "LoadController start action didn't redirect to status page." assert daemon.job_running('import_bar'), \ "LoadController start action didn't start the import_bar job!"
def test_remove_dataset_select(self, have_role_mock): have_role_mock.return_value = True datasets = ['one', 'two', 'three'] for name in datasets: ds = model.Dataset(name=name) ds.save() response = self.app.get(url(controller='task', action='remove_dataset')) for name in datasets: remove_url = url(controller='task', action='remove_dataset', dataset=name) assert remove_url in response, \ "No link to remove dataset '%s' in response!" % name
def test_diagnose_broken_package_ambiguous_hints(self): response = self.app.get(url(controller='load', action='diagnose', package='baz')) assert "multiple resources with hint 'model'" in response, \ "No warning about ambiguous resources in response!"
def test_diagnose_valid_package(self): response = self.app.get(url(controller='load', action='diagnose', package='bar')) assert 'http://example.com/barmodel.js' in response, \ "No link to package model in response!" assert 'http://example.com/bardata.csv' in response, \ "No link to package data in response!" assert 'error-message' not in response, \ "There was an error-message in response"
def test_404(self): response = self.app.get( url(controller='error_test', action='not_found'), status=404 ) assert "404 Not Found" in response, \ "'404 Not Found' not in response to request that should give a 404!" assert "OpenSpending ETL" in response, \ "'OpenSpending ETL' not in 404 page! Is this not a custom 404?" assert "Custom 404 error message" in response, \ "Custom error message was not passed through to 404 error page."
def test_403(self): response = self.app.get( url(controller='error_test', action='not_authorised'), status=403 ) assert "403 Forbidden" in response, \ "'403 Not Found' not in response to request that should give a 403!" assert "OpenSpending ETL" in response, \ "'OpenSpending ETL' not in 403 page! Is this not a custom 403?" assert "Custom 403 error message" in response, \ "Custom error message was not passed through to 403 error page."
def test_drop_database(self, have_role_mock): have_role_mock.return_value = True db = model.mongo.db() db.test_collection.insert({"name": "test thingy"}) response = self.app.get(url(controller='task', action='drop_database')) assert daemon.job_running('drop_database'), \ "drop_database action didn't start the drop_database job!" while daemon.job_running('drop_database'): time.sleep(0.1) h.assert_equal(db.collection_names(), ['system.js', 'system.indexes'])
def test_remove_dataset(self, have_role_mock): have_role_mock.return_value = True ds = model.Dataset(name='mydataset') ds.save() response = self.app.get(url(controller='task', action='remove_dataset', dataset='mydataset')) assert daemon.job_running('remove_mydataset'), \ "remove_dataset action didn't start the remove_mydataset job!" while daemon.job_running('remove_mydataset'): time.sleep(0.1) res = model.Dataset.find_one({'name': 'mydataset'}) h.assert_equal(res, None)
def test_500(self): # NB: This test will fail if the tests are run in debug mode. Add the # following line to your test.ini under [app:main]: # # set debug = False response = self.app.get( url(controller='error_test', action='server_error'), status=500 ) assert "Server Error" in response, \ "'Server Error' not in response to request that should give a 500!" assert "OpenSpending ETL" in response, \ "'OpenSpending ETL' not in 500 page! Is this not a custom 500?" assert "Custom 500 error message" in response, \ "Custom error message was not passed through to 500 error page." assert "The Count" in response, \ "What have you done to The Count!? Put him back this instant!"
def test_diagnose_broken_package_no_hints(self): response = self.app.get(url(controller='load', action='diagnose', package='foo')) assert 'None set' in response, "'None set' not in response!"
def test_index_csv_import_link(self): response = self.app.get(url(controller='home', action='index')) load_url = url(controller='load', action='index') assert load_url in response, \ "No link to LoadController#index action in response!"
def test_index_remove_dataset_link(self): response = self.app.get(url(controller='home', action='index')) rmdataset_url = url(controller='task', action='remove_dataset') assert rmdataset_url in response, \ "No link to TaskController#remove_dataset action in response!"
def test_index_drop_database_link(self): response = self.app.get(url(controller='home', action='index')) dropdb_url = url(controller='task', action='drop_database') assert dropdb_url in response, \ "No link to TaskController#drop_database action in response!"