Ejemplo n.º 1
0
def delete_in_transaction_fn():
    loaded_model = TestModel('test_model_1')
    load(loaded_model)
    loaded_list_model = TestListModel('test_list_model_1')
    load(loaded_list_model)
    loaded_list_model.l.remove(loaded_model.key)
    delete(loaded_model)
    save(loaded_list_model)
Ejemplo n.º 2
0
def test_model_save(model):
    assert len(get_redis_conn().keys(model.key)) == 0
    save(model)
    assert len(get_redis_conn().keys(model.key)) == 1
    db_model = get_redis_conn().hgetall(model.key)
    assert db_model is not None
    assert model.test_str_1 == json.loads(db_model['t1'])
    assert model.test_str_2 == json.loads(db_model['t2'])
    assert model.test_str_3 == json.loads(db_model['t3'])
Ejemplo n.º 3
0
def saved_list_model(request):
    model = TestListModel('test_list_model_1', [])
    save(model)

    def fin():
        try:
            get_redis_conn().delete(model.key)
        except Exception:
            pass
    request.addfinalizer(fin)
    return model
Ejemplo n.º 4
0
def test_delete_in_transaction(saved_model, saved_list_model):
    t = TestListModel(saved_list_model.key)
    load(t)
    t.l.append(saved_model.key)
    save(t)
    t = TestListModel(saved_list_model.key)
    load(t)
    assert len(t.l) == 1
    delete_in_transaction_fn()
    db_model = get_redis_conn().hgetall(saved_model.key)
    assert len(db_model.keys()) == 0
    saved_list_db_model = get_redis_conn().hgetall(saved_list_model.key)
    assert len(json.loads(saved_list_db_model['l'])) == 0
Ejemplo n.º 5
0
def saved_model(request):
    model = TestModel('test_model_1', 'a', 'b', 'c')
    remote_model = TestRemoteModel(model.test_remote_key_value, 'd')
    save(model)
    save(remote_model)

    def fin():
        try:
            get_redis_conn().delete(model.key)
            get_redis_conn().delete(remote_model.key)
        except Exception:
            pass
    request.addfinalizer(fin)
    return model
Ejemplo n.º 6
0
def test_model_migration(saved_model):
    assert saved_model.version == 0
    loaded_model = TestMigratedModel('test_model_1')
    load(loaded_model)
    assert loaded_model.test_str_1 == saved_model.test_str_1
    assert loaded_model.test_str_2 == saved_model.test_str_2
    assert loaded_model.test_str_3 == saved_model.test_str_3
    assert loaded_model.test_extra_value_1 == "TEST_MIGRATION_VALUE_1"
    assert loaded_model.test_extra_value_2 == "TEST_MIGRATION_VALUE_2"
    assert loaded_model.version == 2

    # Verify migration doesn't happen next time
    loaded_model.test_extra_value_1 = 'different value 1'
    loaded_model.test_extra_value_2 = 'different value 2'
    save(loaded_model)
    new_loaded_model = TestMigratedModel('test_model_1')
    load(new_loaded_model)
    assert new_loaded_model.test_extra_value_1 != "TEST_MIGRATION_VALUE_1"
    assert new_loaded_model.test_extra_value_2 != "TEST_MIGRATION_VALUE_2"
    assert new_loaded_model.test_extra_value_1 == loaded_model.test_extra_value_1
    assert new_loaded_model.test_extra_value_2 == loaded_model.test_extra_value_2
    assert new_loaded_model.version == 2
Ejemplo n.º 7
0
def simple_transaction_fn():
    loaded_model = TestModel('test_model_1')
    load(loaded_model)
    loaded_model.test_str_1 = "blah blah"
    save(loaded_model)