Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    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
            },
        }
Exemplo n.º 5
0
 def test_init(self, details_data):
     details = utils.Details(**details_data)
     for prop in details_data:
         assert getattr(details, prop) == details_data[prop]
Exemplo n.º 6
0
 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()
Exemplo n.º 7
0
 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()
Exemplo n.º 8
0
 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()
Exemplo n.º 9
0
 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"])
Exemplo n.º 10
0
 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"]
Exemplo n.º 11
0
    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"]