コード例 #1
0
def test__load():
    sess = mod.Session('id', {}, 'expires')

    assert sess._load('{"a": 1}') == {"a": 1}
    assert sess._load({"a": 1}) == {"a": 1}
    assert sess._load(None) == {}
    assert sess._load(111) == {}
コード例 #2
0
def test_rotate(delete, generate_session_id, save):
    sess = mod.Session('id', {'a': 1}, 'expires')
    assert sess.rotate() == save.return_value

    delete.assert_called_once_with()
    assert sess.id == generate_session_id.return_value
    save.assert_called_once_with()
コード例 #3
0
def test___setattr__():
    sess = mod.Session('id', {}, 'expires')
    assert sess.modified is False
    # should still show False
    sess.non_modifiable = 'test'
    assert sess.modified is False
    # should record modification
    sess.data = 'test'
    assert sess.modified is True
コード例 #4
0
def test_save(request, _dump):
    sess = mod.Session('id', {'a': 1}, 'expires')
    sess.modified = True
    assert sess.save() is sess

    db = request.db.sessions
    db.Replace.assert_called_once_with('sessions',
                                       cols=['session_id', 'data', 'expires'])
    db.query.assert_called_once_with(db.Replace.return_value,
                                     session_id=sess.id,
                                     data=_dump.return_value,
                                     expires=sess.expires)
コード例 #5
0
def test_reset(generate_session_id, get_expiry):
    sess = mod.Session('id', {'a': 1}, 'expires')
    assert sess.reset() is sess
    assert sess.id == generate_session_id.return_value
    assert sess.expires == get_expiry.return_value
    assert sess.data == {}
コード例 #6
0
def test_expire_expired(delete):
    sess = mod.Session('id', {'a': 1}, mod.utcnow() - datetime.timedelta(100))
    with pytest.raises(mod.SessionExpired):
        sess.expire()

    delete.assert_called_once_with()
コード例 #7
0
def test_expire_not_expired(delete):
    sess = mod.Session('id', {'a': 1}, mod.utcnow() + datetime.timedelta(100))
    assert sess.expire() is sess
    assert not delete.called
コード例 #8
0
def test_delete(request):
    sess = mod.Session('id', {'a': 1}, 'expires')
    assert sess.delete() is sess
    db = request.db.sessions
    db.Delete.assert_called_once_with('sessions', where='session_id = ?')
    db.query.assert_called_once_with(db.Delete.return_value, sess.id)
コード例 #9
0
def test__dump():
    sess = mod.Session('id', {'a': 1}, 'expires')
    assert sess._dump() == '{"a": 1}'
コード例 #10
0
def test___init__(_load):
    data = 'data'
    sess = mod.Session('id', data, 'expires')
    sess._load.assert_called_once_with(data)
    assert sess.data == _load.return_value