Пример #1
0
def test_create_channel_channel_name_incorrect_length():
    server = Camelot_Server()
    mydb = Camelot_Database()

    client_request = json.loads(
        json.dumps(
            {
                "create_channel":
                "Test Channel Name with incorrect length-----------"
            },
            indent=4))

    expected_response = json.dumps(
        {
            "error":
            "The name of the channel isn't of the correct length (0 < len(channel_name) <= 40)."
        },
        indent=4)

    mydb.create_account("username", "password")
    server, mydb = login(server, mydb, 'username', 'password')

    result = server.create_channel(mydb, client_request)

    assert expected_response == result
    mydb.empty_tables()
Пример #2
0
def test_create_channel_that_already_exists():
    server = Camelot_Server()
    mydb = Camelot_Database()

    client_request = json.loads(
        json.dumps({"create_channel": "Test Channel Name"}, indent=4))

    expected_response = json.dumps(
        {"error": "The specified channel already exists in the database."},
        indent=4)

    mydb.create_account("username", "password")
    server, mydb = login(server, mydb, 'username', 'password')

    server.create_channel(mydb, client_request)
    result = server.create_channel(mydb, client_request)

    assert expected_response == result
    mydb.empty_tables()
Пример #3
0
def test_create_channel_not_logged_in():
    server = Camelot_Server()
    mydb = Camelot_Database()

    client_request = json.loads(
        json.dumps(
            {
                "create_channel":
                "Test Channel Name with incorrect length-----------"
            },
            indent=4))

    expected_response = json.dumps(
        {"error": "A user must be signed in to access this function."},
        indent=4)

    result = server.create_channel(mydb, client_request)

    assert expected_response == result
    mydb.empty_tables()
Пример #4
0
def test_create_channel_success():
    server = Camelot_Server()
    mydb = Camelot_Database()

    client_request = json.loads(
        json.dumps({"create_channel": "Test Channel Name"}, indent=4))

    expected_response = json.dumps(
        {
            "channel_created": {
                "channel": "Test Channel Name",
                "message":
                "A new channel has been created: 'Test Channel Name'."
            }
        },
        indent=4)

    mydb.create_account("username", "password")
    server, mydb = login(server, mydb, 'username', 'password')

    result = server.create_channel(mydb, client_request)

    assert expected_response == result
    mydb.empty_tables()