Example #1
0
def test_list_of_strings_and_ints_only_model():
    list_fixture = ["one", "two", "three", 1, 2, 3]
    a = redis_model.RedisModel(namespace="test", key="test9")
    a.things = list_fixture

    for entry in list_fixture:
        ok_(entry in a.things,
            "Item missing from model list data: {}".format(entry))
Example #2
0
def test_list_of_ints_only_model():
    list_fixture = [1, 2, 3]
    a = redis_model.RedisModel(namespace="test", key="test8")
    a.things = list_fixture

    for entry in list_fixture:
        ok_(entry in a.things,
            "Item missing from model list data: {}".format(entry))
Example #3
0
def test_existing_data():
    redis_model.redis.set("test:test10:fname", "Josh")
    redis_model.redis.set("test:test10:lname", "Ashby")
    redis_model.redis.set("test:test10:major", "ECE - Computer Engineer")
    redis_model.redis.rpush("test:test10:hobbies", "Programming",
                            "Electronics", "Photography")

    a = redis_model.RedisModel(namespace="test", key="test10")
    eq_(a.fname, "Josh")
    eq_(a.lname, "Ashby")
    eq_(a.major, "ECE - Computer Engineer")
    eq_(a.hobbies, ["Programming", "Electronics", "Photography"])
Example #4
0
def test_string_only_model():
    a = redis_model.RedisModel(namespace="test", key="test5")

    a.time = "now"
    eq_(a.time, "now", "setattr - Model data doesn't match - getattr")
    eq_(a["time"], "now", "setattr - Model data doesn't match - getitem")
    b = redis_model.redis.get("test:test5:time")
    eq_(b, "now", "Raw redis data doesn't match")

    a["date"] = "then"
    eq_(a.date, "then", "setitem - Model data doesn't match - getattr")
    eq_(a["date"], "then", "setitem - Model data doesn't match - getitem")
    b = redis_model.redis.get("test:test5:date")
    eq_(b, "then", "Raw redis data doesn't match")
Example #5
0
def test_new_model():
    a = redis_model.RedisModel(namespace="test", key="test1", month="April")
    ok_(a.month, "Kwarg didn't make it into model data")
    eq_(a.month, "April", "Model data doesn't match")
Example #6
0
def test_delitem():
    a = redis_model.RedisModel(namespace="test", key="test6")
    a.time = "now"
    del a["time"]
    assert a.time is not None
Example #7
0
def test_del_model():
    a = redis_model.RedisModel(namespace="test", key="test4")
    a.delete()
Example #8
0
def test_model_property():
    a = redis_model.RedisModel(namespace="test", key="test2")
    eq_(a.key, "test2", "Model key doesn't match")
Example #9
0
def test_in_model():
    a = redis_model.RedisModel(namespace="test", key="test3")
    a.time = "five o'clock"
    ok_("time" in a, "__contains__ doesn't work")
Example #10
0
def test_no_key():
    redis_model.RedisModel(namespace="test")
Example #11
0
def test_model_get():
    a = redis_model.RedisModel(namespace="test", key="test14")
    a.name = "Dan"
    eq_(a.get("Meyrl"), None)
    eq_(a.get("James", "Fred"), "Fred")
Example #12
0
def test_none_attribute():
    a = redis_model.RedisModel(namespace="test", key="test13")
    a.ship = None
    eq_(a.ship, "")
Example #13
0
def test_delete_with_keys():
    a = redis_model.RedisModel(namespace="test", key="test12")
    a.name = "Fred"
    a.who = "Fred?"
    a.nickname = "fred"
    a.delete()
Example #14
0
def test_existing_data_other_types():
    redis_model.redis.sadd("test:test11:wat", "this")
    redis_model.RedisModel(namespace="test", key="test11")