Пример #1
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 == []
Пример #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")