def test_sysadmin_can_create_via_api(self): sysadmin = factories.Sysadmin() context = {"user": sysadmin["name"], "model": model, "api_version": 3} assert helpers.call_auth("user_create", context)
def sysadmin_env(): user = factories.Sysadmin() env = {"REMOTE_USER": six.ensure_str(user["name"])} return env
def _reset_config(app): """Reset config via action""" user = factories.Sysadmin() env = {"REMOTE_USER": six.ensure_str(user["name"])} app.post(url=url_for("admin.reset_config"), extra_environ=env)
def test_sysadmin_can_create_group_when_config_is_True(self): sysadmin = factories.Sysadmin() context = {'ignore_auth': False, 'user': sysadmin['name']} helpers.call_action('group_create', context, name='test-group')
def test_config_option_list_sysadmin(self): '''A sysadmin is authorized to use config_option_list action.''' factories.Sysadmin(name='fred') context = {'user': '******', 'model': None} assert helpers.call_auth('config_option_list', context=context)
def test_apikey_in_authorization_header(app): user = factories.Sysadmin() request_headers = {"Authorization": str(user["apikey"])} app.get("/dataset/new", headers=request_headers)
def test_apikey_in_x_ckan_header(app): user = factories.Sysadmin() # non-standard header name is defined in test-core.ini request_headers = {"X-Non-Standard-CKAN-API-Key": str(user["apikey"])} app.get("/dataset/new", headers=request_headers)
def test_config_option_update_sysadmin(self): """A sysadmin is authorized to use config_option_update action.""" factories.Sysadmin(name="fred") context = {"user": "******", "model": None} assert helpers.call_auth("config_option_update", context=context)
def test_news_subscription_show_not_found(self): user = factories.Sysadmin() context = {'user': user['name']} result = helpers.call_action('news_subscription_show', context=context) assert result == None
def test_sorting(): testsysadmin = factories.Sysadmin(name=u"testsysadmin") pkg1 = model.Package(name="pkg1") pkg2 = model.Package(name="pkg2") model.Session.add(pkg1) model.Session.add(pkg2) CreateTestData.create_groups( [ { "name": "alpha", "title": "Alpha", "packages": [] }, { "name": "beta", "title": "Beta", "packages": ["pkg1", "pkg2"] }, { "name": "delta", "title": "Delta", "packages": ["pkg1"] }, { "name": "gamma", "title": "Gamma", "packages": [] }, ], admin_user_name="testsysadmin", ) context = { "model": model, "session": model.Session, "user": "******", "for_view": True, "with_private": False, } data_dict = {"all_fields": True} results = get_action("group_list")(context, data_dict) assert results[0]["name"] == u"alpha", results[0]["name"] assert results[-1]["name"] == u"gamma", results[-1]["name"] # Test title forward data_dict = {"all_fields": True, "sort": "title asc"} results = get_action("group_list")(context, data_dict) assert results[0]["name"] == u"alpha", results[0]["name"] assert results[-1]["name"] == u"gamma", results[-1]["name"] # Test title reverse data_dict = {"all_fields": True, "sort": "title desc"} results = get_action("group_list")(context, data_dict) assert results[0]["name"] == u"gamma", results[0]["name"] assert results[-1]["name"] == u"alpha", results[-1]["name"] # Test name reverse data_dict = {"all_fields": True, "sort": "name desc"} results = get_action("group_list")(context, data_dict) assert results[0]["name"] == u"gamma", results[0]["name"] assert results[-1]["name"] == u"alpha", results[-1]["name"] # Test packages reversed data_dict = {"all_fields": True, "sort": "package_count desc"} results = get_action("group_list")(context, data_dict) assert results[0]["name"] == u"beta", results[0]["name"] assert results[1]["name"] == u"delta", results[1]["name"] # Test packages forward data_dict = {"all_fields": True, "sort": "package_count asc"} results = get_action("group_list")(context, data_dict) assert results[-2]["name"] == u"delta", results[-2]["name"] assert results[-1]["name"] == u"beta", results[-1]["name"] # Default ordering for packages data_dict = {"all_fields": True, "sort": "package_count"} results = get_action("group_list")(context, data_dict) assert results[0]["name"] == u"beta", results[0]["name"] assert results[1]["name"] == u"delta", results[1]["name"]
def setup(self): super(TestPages, self).setup() if db.pages_table is None: db.init_db(model) self.user = factories.Sysadmin() self.app = self._get_test_app()
def test_sysadmin_can_list_followees(self, func): sysadmin = factories.Sysadmin() context = {"user": sysadmin["name"], "model": model} assert helpers.call_auth(func, context=context)
def test_config_option_list_sysadmin(self): """A sysadmin is authorized to use config_option_list action.""" fred = factories.Sysadmin() context = {"user": fred["name"], "model": None} assert helpers.call_auth("config_option_list", context=context)
def test_list_fails_if_resource_does_not_exist(self): user = factories.Sysadmin() with pytest.raises(toolkit.ObjectNotFound) as e: resource_version_list(get_context(user), {'resource_id': 'fake-resource-id'}) assert e.msg == 'Resource not found'