Beispiel #1
0
def test_get_notes():
    my_backend = Backend(cfg, init=True)
    #create sleep survey
    my_backend.create_survey(sleep_survey)
    #save a few answers
    my_backend.save_answer(
        user_id, sleep_survey["id"], {
            "sleep_hours": 9,
            "sleep_quality": 5,
            "ts": 200,
            "notes": u"this a nifty note"
        })
    my_backend.save_answer(
        user_id, sleep_survey["id"], {
            "sleep_hours": 8,
            "sleep_quality": 4,
            "ts": 300,
            "notes": u"this a another note"
        })
    my_backend.save_answer(
        user_id, sleep_survey["id"], {
            "sleep_hours": 7,
            "sleep_quality": 3,
            "ts": 400,
            "notes": u"this a neatfull note"
        })
    #check answers ok
    report = my_backend.get_notes(user_id, sleep_survey["id"])
    print "rep", report
    assert report[0] == (u'400', u"this a neatfull note")
    assert report[1] == (u'300', u"this a another note")
    assert report[2] == (u'200', u"this a nifty note")
Beispiel #2
0
def test_get_report():
    my_backend = Backend(cfg, init=True)
    #create sleep survey
    my_backend.create_survey(sleep_survey)
    #save a few answers
    my_backend.save_answer(
        user_id, sleep_survey["id"], {
            "sleep_hours": 9,
            "sleep_quality": 5,
            "ts": 200,
            "notes": u"don’t look at this wáilde note"
        })

    my_backend.save_answer(
        user_id, sleep_survey["id"], {
            "sleep_hours": 8,
            "sleep_quality": 4,
            "ts": 300,
            "notes": u"this a another note"
        })

    my_backend.save_answer(
        user_id, sleep_survey["id"], {
            "sleep_hours": 7,
            "sleep_quality": 3,
            "ts": 400,
            "notes": u"this a nifty note"
        })
    #check answers ok
    report = my_backend.get_report(user_id, sleep_survey["id"])
    print "rep", report
    assert report[0][1:] == (user_id, u'400', '7', '3', u"this a nifty note")
    assert report[1][1:] == (user_id, u'300', '8', '4', u"this a another note")
    assert report[2][1:] == (user_id, u'200', '9', '5',
                             u"don’t look at this wáilde note")
Beispiel #3
0
def test_delete_answers():
    my_backend = Backend(cfg, init=True)
    #create sleep survey
    my_backend.create_survey(sleep_survey)
    #save a few answers
    my_backend.save_answer(user_id, sleep_survey["id"], {
        "sleep_hours": 9,
        "sleep_quality": 5,
        "ts": 200
    })
    my_backend.save_answer(user_id, sleep_survey["id"], {
        "sleep_hours": 8,
        "sleep_quality": 4,
        "ts": 300
    })
    my_backend.save_answer(user_id, sleep_survey["id"], {
        "sleep_hours": 7,
        "sleep_quality": 3,
        "ts": 400
    })
    #check answers ok
    report = my_backend.get_report(user_id, sleep_survey["id"])
    print "rep", report
    assert report[0][1:] == (user_id, u'400', '7', '3', None)
    assert report[1][1:] == (user_id, u'300', '8', '4', None)
    assert report[2][1:] == (user_id, u'200', '9', '5', None)
    #delete answers
    my_backend.delete_answers(user_id, sleep_survey["id"])
    #check no answers
    report = my_backend.get_report(user_id, sleep_survey["id"])
    assert report == []
Beispiel #4
0
def test_save_answer():
    my_backend = Backend(cfg, init=True)
    my_backend.create_survey(sleep_survey)
    sql = '''SELECT * FROM survey_sleep WHERE user_id=? and id=?'''
    db = sqlite3.connect(DB_path)
    cursor = db.cursor()
    #save
    resp_id = my_backend.save_answer(user_id, sleep_survey["id"], {
        "sleep_hours": 9,
        "sleep_quality": 5,
        "ts": 200
    })
    cursor.execute(sql, (user_id, resp_id))
    resp = cursor.fetchall()
    assert resp[0] == (resp_id, user_id, u'200', '9', '5', None)