Ejemplo n.º 1
0
def test_create_account_success_with_default_channels_added_to_account():
    server = Camelot_Server()
    mydb = Camelot_Database()
    mydb.insert_data('data.sql')

    expected_response = json.dumps(
        {"channels": ["Server Team", "Client Team", "Software Eng. Group"]},
        indent=4)

    mydb.create_account("username", "password")
    result = mydb.get_channels_for_user("username")

    assert expected_response == result
    mydb.empty_tables()
Ejemplo n.º 2
0
def test_get_channels_for_user():
    server = Camelot_Server()
    mydb = Camelot_Database()
    mydb.insert_data('data.sql')

    client_request = json.dumps(
        {"get_channels_for_user": "******"}, indent=4)

    expected_response = json.dumps(
        {"channels": ["Server Team", "Client Team", "Software Eng. Group"]},
        indent=4)

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

    assert expected_response == result
    mydb.empty_tables()
Ejemplo n.º 3
0
            # Receive the data from that socket
            request = json.loads(self.conn.recv(4096).decode('ascii'))
            print("Received `{}` from `{}`".format(json.dumps(request),
                                                   thread_name))

        except:
            error = True
            request = json.dumps({"error": "Something went wrong"}, indent=4)

        return (error, request)


if __name__ == '__main__':
    # Add some initial channels to the database
    mydb = Camelot_Database()
    mydb.insert_data('data.sql')

    host = '127.0.0.1'
    port = 12345

    soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    # this is for easy starting/killing the app
    soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    soc.bind((host, port))
    soc.listen(10)

    try:
        # Accept new incoming clients
        while True: