예제 #1
0
def db_setup(app):
    session = app.db.session('relengapi')
    tree = model.DbTree(tree=tree1_json['tree'],
                        status=tree1_json['status'],
                        reason=tree1_json['reason'],
                        message_of_the_day=tree1_json['message_of_the_day'])
    session.add(tree)

    def when(day):
        return datetime.datetime(2015, 7, day, 17, 44, 00)

    for tree, status, when, reason, tags in [
        ('tree1', 'opened', when(13), 'i wanted to', ['a']),
        ('tree1', 'opened', when(15), 'i really wanted to', []),
        ('tree1', 'closed', when(14), 'because', ['a', 'b']),
        ('tree2', 'approval required', when(11), 'so there', []),
    ]:
        l = model.DbLog(tree=tree,
                        when=when,
                        who='dustin',
                        status=status,
                        reason=reason,
                        tags=tags)
        session.add(l)
        when += datetime.timedelta(days=1)
    session.commit()
예제 #2
0
def make_tree(tree_name, body):
    """Make a new tree."""
    session = current_app.db.session('relengapi')
    if body.tree != tree_name:
        raise BadRequest("Tree names must match")
    t = model.DbTree(
        tree=tree_name,
        status=body.status,
        reason=body.reason,
        message_of_the_day=body.message_of_the_day)
    try:
        session.add(t)
        session.commit()
    except (sa.exc.IntegrityError, sa.exc.ProgrammingError):
        raise BadRequest("tree already exists")
    return None, 204
예제 #3
0
def db_setup_stack(app):
    for tn in range(3):
        session = app.db.session('relengapi')
        tree = model.DbTree(tree='tree%d' % tn,
                            status='closed',
                            reason=['bug 123', 'bug 456', 'bug 456'][tn],
                            message_of_the_day='tree %d' % tn)
        session.add(tree)

    def ls(status, reason):
        return json.dumps({'status': status, 'reason': reason})

    # first change closed tree0 and tree1
    stack = model.DbStatusChange(who='dustin',
                                 reason='bug 123',
                                 status='closed',
                                 when=datetime.datetime(2015, 7, 14))
    session.add(stack)
    for tree in 'tree0', 'tree1':
        session.add(
            model.DbStatusChangeTree(tree=tree,
                                     stack=stack,
                                     last_state=ls('open', tree)))

    # second change closed tree1 and tree2
    stack = model.DbStatusChange(who='dustin',
                                 reason='bug 456',
                                 status='closed',
                                 when=datetime.datetime(2015, 7, 16))
    session.add(stack)
    session.add(
        model.DbStatusChangeTree(tree='tree1',
                                 stack=stack,
                                 last_state=ls('closed', 'bug 123')))
    session.add(
        model.DbStatusChangeTree(tree='tree2',
                                 stack=stack,
                                 last_state=ls('open', 'tree2')))

    session.commit()