Exemplo n.º 1
0
 def to_jsontask(self, with_jobs=False):
     runtime_task = badpenny.Task.get(self.name)
     task = rest.BadpennyTask(name=self.name,
                              last_success=self.last_success,
                              active=bool(runtime_task))
     if runtime_task:
         task.schedule = runtime_task.schedule
     if with_jobs:
         task.jobs = [j.to_jsonjob() for j in self.jobs]
     return task
Exemplo n.º 2
0
def test_to_jsontask(app):
    """Converting a tables.BadpennyTask to a rest.BadpennyTask produces well-formed output"""
    with app.test_request_context():
        t = tables.BadpennyTask.query.filter(
            tables.BadpennyTask.name == 'cleanup').first()
        eq_(json.dumps(t.to_jsontask()), json.dumps(cleanup_task))
        t = tables.BadpennyTask.query.filter(
            tables.BadpennyTask.name == 'report').first()
        eq_(
            json.dumps(t.to_jsontask(with_jobs=True)),
            json.dumps(
                rest.BadpennyTask(active=False,
                                  name="report",
                                  last_success=1,
                                  jobs=[report_job_1])))
Exemplo n.º 3
0
    session = app.db.session('relengapi')
    l = tables.BadpennyJobLog(id=job_id, content=content)
    session.add(l)
    session.commit()
    return l


def insert_task(app, name):
    session = app.db.session('relengapi')
    t = tables.BadpennyTask(name=name)
    session.add(t)
    session.commit()
    return t


cleanup_task = rest.BadpennyTask(active=False, name="cleanup", last_success=0)
cleanup_job_1 = rest.BadpennyJob(id=1,
                                 successful=True,
                                 task_name='cleanup',
                                 created_at=dt(1978, 6, 15),
                                 started_at=dt(1978, 6, 15, 12),
                                 completed_at=dt(1978, 6, 15, 13))
cleanup_job_2 = rest.BadpennyJob(id=2,
                                 successful=False,
                                 task_name='cleanup',
                                 created_at=dt(1978, 6, 16),
                                 started_at=dt(1978, 6, 16, 12),
                                 completed_at=dt(1978, 6, 16, 13))

report_task = rest.BadpennyTask(active=False, name="report", last_success=1)
report_job_1 = rest.BadpennyJob(id=3,