예제 #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 update_tree_status(session, tree, status=None, reason=None,
                       tags=[], message_of_the_day=None):
    """Update the given tree's status; note that this does not commit
    the session.  Supply a tree object or name."""
    if status is not None:
        tree.status = status
    if reason is not None:
        tree.reason = reason
    if message_of_the_day is not None:
        tree.message_of_the_day = message_of_the_day

    # log it if the reason or status have changed
    if status or reason:
        if status is None:
            status = 'no change'
        if reason is None:
            reason = 'no change'
        l = model.DbLog(
            tree=tree.tree,
            when=relengapi_time.now(),
            who=str(current_user),
            status=status,
            reason=reason,
            tags=tags)
        session.add(l)

    tree_cache_invalidate(tree.tree)
예제 #3
0
def test_get_logs_all(client, app):
    """Getting /treestatus/trees/tree1/logs with over 5 logs present
    results in only 5 logs, unless given ?all=1"""
    # add the log entries
    session = app.db.session('relengapi')
    for ln in range(5):
        l = model.DbLog(tree='tree1',
                        when=datetime.datetime(2015, 6, 15, 17, 44, 00),
                        who='jimmy',
                        status='halfopen',
                        reason='being difficult',
                        tags=[])
        session.add(l)
    session.commit()

    resp = client.get('/treestatus/trees/tree1/logs')
    eq_(len(json.loads(resp.data)['result']), 5)

    resp = client.get('/treestatus/trees/tree1/logs?all=1')
    eq_(len(json.loads(resp.data)['result']), 8)
예제 #4
0
def test_delete_tree(app, client):
    """Deleting a tree deletes the tree and any associated logs
    and changes"""
    with app.app_context():
        session = app.db.session('relengapi')
        l = model.DbLog(tree='tree1',
                        when=datetime.datetime(2015, 6, 15, 17, 44, 00),
                        who='jimmy',
                        status='halfopen',
                        reason='being difficult',
                        tags=[])
        session.add(l)
        session.commit()

    resp = client.get('/treestatus/trees/tree1')
    eq_(resp.status_code, 200)
    resp = client.delete('/treestatus/trees/tree1')
    eq_(resp.status_code, 204)
    resp = client.get('/treestatus/trees/tree1')
    eq_(resp.status_code, 404)

    with app.app_context():
        eq_(model.DbLog.query.filter_by(tree='tree1')[:], [])
        eq_(model.DbStatusChangeTree.query.filter_by(tree='tree1')[:], [])