Ejemplo n.º 1
0
def setup_command():
    """
    Run this command to initialize all database tables. Can be run multiple times safely.
    """
    ado_dir = setting("ado-dir")
    if not os.path.exists(ado_dir):
        print "Creating directory", ado_dir
        os.mkdir(ado_dir)

    c = conn()
    Model.setup_tables(c, classes.values())
Ejemplo n.º 2
0
def test_metric():
    conn = Model.setup_db()
    Metric.create_table(conn)
    metric = Metric.create(conn,
            created_at = datetime.now(),
            name = "mood",
            description = "On a scale of 1 to 10, 10 being best, rate your mood."
            )
    assert metric.id > 0

    MetricData.create_table(conn)

    p1 = MetricData.create(conn,
            created_at = datetime.now(),
            value = 7,
            metric_id = metric.id
            )
    assert p1.id > 0

    p2 = MetricData.create(conn,
            created_at = datetime.now(),
            value = 8,
            metric_id = metric.id
            )
    assert p2.id > 0

    latest = metric.latest(conn)
    assert latest.value == 8
    assert latest.id == p2.id

    datetimes, values = metric.ts(conn)

    assert values == [7, 8]
Ejemplo n.º 3
0
def test_create_table():
    conn = Model.setup_db()
    Project.create_table(conn)
    sql = "select * from sqlite_master where type='table' and name='Project'"
    assert len(conn.execute(sql).fetchall()) == 1
    row = conn.execute(sql).fetchone()
    assert row['sql'] == Project.create_table_sql()
    conn.execute("select * from Project")
Ejemplo n.º 4
0
def test_survey():
    conn = Model.setup_db()
    Survey.create_table(conn)
    survey = Survey.create(conn,
            created_at = datetime.now(),
            name = "how do you feel",
            description = "How do you feel?")

    assert survey.id > 0

    SurveyData.create_table(conn)
    a1 = SurveyData.create(conn,
            survey_id = survey.id,
            value = "I feel fine."
            )

    assert a1.id > 0

    latest = survey.latest()
    assert latest.id == a1.id
    assert latest.value == "I feel fine."
Ejemplo n.º 5
0
def conn():
    return Model.setup_db(db_filepath)
Ejemplo n.º 6
0
def get_conn():
    conn = Model.setup_db()
    Model.setup_tables(conn, ado.commands.classes.values())
    return conn
Ejemplo n.º 7
0
from ado.model import Model
from ado.portfolio import Portfolio
from ado.task import Task
from ado.commands import db_filepath
import json

conn = Model.setup_db(db_filepath())

def dict_for_task(task):
    return {
            "name" : "[%d] %s" % (task.id, task.name_with_check()),
            "size" : 1,
            "title" : task.description,
            "state" : task.state()
            }

def dict_for_project(project):
    return {
            "name" : "[%d] %s" % (project.id, project.name),
            "title" : project.description,
            "state" : "child"
            }

def dict_for_portfolio(portfolio):
    return {
            "name" : "[%d] %s" % (portfolio.id, portfolio.name),
            "title" : portfolio.description,
            "state" : "child"
            }

inbox = {
Ejemplo n.º 8
0
def test_table_name():
    assert Model.table_name() == "Model"
    assert Project.table_name() == "Project"
Ejemplo n.º 9
0
def test_persist_instance():
    conn = Model.setup_db()
    Project.create_table(conn)
    project = Project.create(conn, name="My New Project")
    print project.persist_instance_sql()
    print project.persist(conn)