Esempio n. 1
0
def test_model_load(saved_model):
    assert len(get_redis_conn().keys(saved_model.key)) == 1
    loaded_model = TestModel('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
Esempio n. 2
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)
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
0
def simple_transaction_fn():
    loaded_model = TestModel('test_model_1')
    load(loaded_model)
    loaded_model.test_str_1 = "blah blah"
    save(loaded_model)
Esempio n. 6
0
def test_model_remote_key_value(saved_model):
    loaded_model = TestModel('test_model_1')
    load(loaded_model)
    loaded_remote_model = TestRemoteModel(loaded_model.test_remote_key_value)
    load(loaded_remote_model)
    assert loaded_remote_model.test_str_1 == 'd'