コード例 #1
0
def update_node(nodeid, paramdict):
    """Update node for passed node.

    Args:
        nodeid: Node ID to update for new column values as passed
        paramdict: Dictionary of column:columnvalue

    Returns:
        response.Response: the node data for the said nodeid.
    """
    if paramdict == {}:
        return response.create_error_response(message='Update data invalid',
                                              code=500)

    with mysql.db_session() as session:
        result_set = session.query(Node).get(nodeid)
        if result_set:
            for colname, colval in paramdict.items():
                setattr(result_set, colname, colval)
            session.merge(result_set)

            response_message = response.Response(message=result_set.to_dict())
        else:
            return response.create_not_found_response(
                'No such node found to update')

    return response_message
コード例 #2
0
def seed_models(models):
    """Save the given model(s) to the DB."""
    if not hasattr(models, '__iter__'):
        models = [models]

    with db_session() as session:
        _exit_if_not_test_environment(session)
        for model in models:
            session.merge(model)
        session.commit()
コード例 #3
0
def get_nodes_all():
    """Get all nodes.

    Args:

    Returns:
        response.Response: All the nodes from the table
    """
    with mysql.db_session() as session:
        result_set = session.query(Node).all()

        if not result_set:
            return response.create_not_found_response('No nodes found')

        total_records = [r.to_dict() for r in result_set]
        return response.Response(message=total_records)
コード例 #4
0
def get_node_for(nodeid):
    """Get node for passed node id.

    Args:
        nodeid (int): the id of the node.

    Returns:
        response.Response: the node data for the said nodeid.
    """
    with mysql.db_session() as session:
        result_set = session.query(Node).get(nodeid)
        if result_set:
            response_message = response.Response(message=result_set.to_dict())
        else:
            response_message = response.create_not_found_response(
                message='No Node exists for given nodeid')

    return response_message
コード例 #5
0
def delete_node(nodeid):
    """Delete node for passed node id.

    Args:
        nodeid (int): the id of the node.

    Returns:
        response.Response: the node data for the said nodeid.
    """
    with mysql.db_session() as session:
        result_set = session.query(Node).get(nodeid)
        if result_set:
            session.delete(result_set)
            response_message = response.Response(
                message='Node deleted successfully')
        else:
            response_message = response.create_not_found_response(
                'No node found to delete')

    return response_message
コード例 #6
0
def create_node(paramdict):
    """Update node for passed node id.

    Args:
            paramdict: Dictionary column value pairs to be added as a row
    Returns:
        response.Response: the node
    """
    if paramdict is None or 'name' not in paramdict or 'surname' \
    not in paramdict:
        return response.create_error_response(
            message='Name and surname is mandatory', code=500)

    with mysql.db_session() as session:
        new_node = Node(name=paramdict.get('name'),
                        surname=paramdict.get('surname'))
        session.add(new_node)
        response_message = response.Response(message=paramdict)

    return response_message
コード例 #7
0
def drop_test_data():
    """Drop the supreet_node table."""
    with db_session() as session:
        _exit_if_not_test_environment(session)
        session.execute(DROP_TABLE_TEST_DATA)
コード例 #8
0
def create_test_data():
    """Create the supreet_node table."""
    with db_session() as session:
        _exit_if_not_test_environment(session)
        drop_test_data()
        session.execute(CREATE_TABLE_TEST_DATA)
コード例 #9
0
def insert_test_alldata():
    """Insert data into supreet_node table."""
    with db_session() as session:
        session.execute(INSERT_TEST_ALL_DATA)