Example #1
0
def test_get_available_username_wrong_format():
    with pytest.raises(ValueError,
                       match="User Profile data missing name information"):
        get_available_username({
            "display_name_normalized": None,
            "real_name_normalized": None
        })
Example #2
0
    def _create_karma_user(self, user_id):
        user_info = SLACK_CLIENT.api_call("users.info", user=user_id)

        error = user_info.get("error")
        if error is not None:
            logging.info(f"Cannot get user info for {user_id} - error: {error}")
            raise GetUserInfoException

        slack_id = user_info["user"]["id"]
        username = get_available_username(user_info)

        new_user = KarmaUser(user_id=slack_id, username=username)
        self.session.add(new_user)
        self.session.commit()

        logging.info(f"Created new KarmaUser: {repr(new_user)}")
        return new_user
Example #3
0
    def _create_karma_user(self, user_id):
        response = bot.app.client.users_profile_get(user=user_id)
        status = response.status_code

        if status != 200:
            logging.info("Cannot get user info for %s - API error: %s", user_id, status)
            raise GetUserInfoException

        user_profile = response.data["profile"]
        username = slack.get_available_username(user_profile)

        new_user = KarmaUser(user_id=user_id, username=username)
        self.session.add(new_user)
        self.session.commit()

        logging.info("Created new KarmaUser: %s", repr(new_user))
        return new_user
Example #4
0
def test_get_available_username(test_profile, expected):
    assert get_available_username(test_profile) == expected
Example #5
0
def test_get_available_username(mock_slack_api_call, test_user_id, expected):
    user_info = SLACK_CLIENT.api_call("users.info", user=test_user_id)
    assert get_available_username(user_info) == expected