def test_channels_create():
    helper.reset_data()
    user = helper.token_admin()

    # Invalid token
    with pytest.raises(validation_helper.AccessError):
        stub.channels_create("fake token", "name", True)

    with pytest.raises(validation_helper.ValueError):
        # check that validation_helper.ValueError is raised if name is more than 20 characters long
        stub.channels_create(user["token"], "123456789012345678901", True)

    with pytest.raises(validation_helper.ValueError):
        # check that validation_helper.ValueError is raised if name is an empty string (assumption)
        stub.channels_create(user["token"], "", True)

    # check that call is successful otherwise
    public_channel_id = stub.channels_create(user["token"], "Public Channel", True)["channel_id"]
    private_channel_id = stub.channels_create(user["token"], "Private Channel", False)["channel_id"]

    assert stub.channels_listall(user["token"]) == {
        "channels": [
            {"channel_id": public_channel_id, "name": "Public Channel"},
            {"channel_id": private_channel_id, "name": "Private Channel"}
        ]
    }
Exemple #2
0
def get_valid_channel(token):
    """
    This function returns a valid channel_id for the provided token. The token would be
    guaranteed to be in that channel.
    usage: pass in a valid token

    Notes: It will try and find a valid channel to join, else it will create one and return that.
    This is to prevent creating more unnecessesary channels

    This makes sure the channel_id is valid for the user.
    """
    # token = token_account_1()

    # No channels exist
    if stub.channels_listall(token)["channels"] == []:

        # Create a new channel
        channel_id = stub.channels_create(token, "test_channel", True)["channel_id"]

    # There is at least 1 channel so we will join the first one we find
    else:
        channel_id = stub.channels_listall(token)["channels"][0]["channel_id"]
        stub.channel_join(token, channel_id)

    return channel_id
Exemple #3
0
def channels_create():
    """ uses stub.py interface function to create a channel """
    # print(request.form.get('is_public'))
    # print(request.form.get('is_public') == "true")
    if request.form.get('is_public') == "false":
        is_public = False
    else: 
        is_public = True
    
    return dumps(
        stub.channels_create(request.form.get('token'),
                             request.form.get('name'),
                             is_public))
Exemple #4
0
def channelid_private(token):
    """
    A helper function used for TESTING only
    :return: channel_id for a private channel
    """
    return stub.channels_create(token, "Private Channel", False)["channel_id"]
Exemple #5
0
def channelid_public(token):
    """
    A helper function used for TESTING only
    :return: channel_id for a public channel
    """
    return stub.channels_create(token, "Public Channel", True)["channel_id"]