def test_user_sync(self, details_data, monkeypatch, ckan_config): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) user = model.User.get(userdict["id"]) user.email = "hello@world" user.name = "hello" model.Session.commit() userdict = utils.get_or_create_from_details(details) assert userdict["name"] != details_data["name"] assert userdict["name"] == "hello" user = model.User.get(userdict["id"]) assert user.email != details_data["email"] assert user.email == "hello@world" utils.synchronize(userdict, details) userdict = utils.get_or_create_from_details(details) assert userdict["name"] == details_data["name"] user = model.User.get(userdict["id"]) assert user.email == details_data["email"] assert (model.Session.query( model.User).filter_by(name="hello").count() == 0) assert (model.Session.query( model.User).filter_by(name=details_data["name"]).count() == 1)
def test_user_created(self, details_data): assert model.User.get(details_data["name"]) is None details = utils.Details(**details_data) utils.get_or_create_from_details(details) user = model.User.get(details_data["name"]) assert user.name == details_data["name"] assert user.plugin_extras["drupal_idp"] == details_data
def test_plugin_extras_not_erased(self, details_data): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) user = model.User.get(userdict["id"]) user.plugin_extras = {"test": {"key": "value"}} utils.synchronize(userdict, details, force=True) user = model.User.get(userdict["id"]) assert "drupal_idp" in user.plugin_extras assert "test" in user.plugin_extras
def test_into_user(self, details_data): details = utils.Details(**details_data) userdict = details.make_userdict() assert userdict == { "email": details_data["email"], "name": munge.munge_name(details_data["name"]), "sysadmin": False, "plugin_extras": { "drupal_idp": details_data }, }
def test_init(self, details_data): details = utils.Details(**details_data) for prop in details_data: assert getattr(details, prop) == details_data[prop]
def test_sysadmin_with_custom_role(self, details_data): details_data["roles"].append(utils.DEFAULT_ADMIN_ROLE) assert not utils.Details(**details_data).is_sysadmin() details_data["roles"].append("custom-admin") assert utils.Details(**details_data).is_sysadmin()
def test_sysadmin(self, details_data): assert not utils.Details(**details_data).is_sysadmin() details_data["roles"].append("not-an-admin") assert not utils.Details(**details_data).is_sysadmin() details_data["roles"].append(utils.DEFAULT_ADMIN_ROLE) assert utils.Details(**details_data).is_sysadmin()
def test_sysadmin_ignored_by_default(self, details_data): details_data["roles"].append(utils.DEFAULT_ADMIN_ROLE) assert not utils.Details(**details_data).is_sysadmin()
def test_same_id(self, details_data): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) assert userdict["id"] == str(details_data["id"])
def test_default_native_id(self, details_data): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) assert userdict["id"] != details_data["id"]
def test_no_user_raises_an_error(self, details_data): details = utils.Details(**details_data) userdict = utils.get_or_create_from_details(details) user = call_action('drupal_idp_user_show', id=details.id) assert user["id"] == userdict["id"]