Beispiel #1
0
def test_subfield_invalidate():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(UserModel, db.subfieldtest)

    m = mapper({'bar': 'baz'})
    m.save()
    m.name.set({'firstname': 'foo'})
    sf = m.name['firstname']

    m.reload()
    m.name.set({'firstname': 'bar'})
    m.save()
Beispiel #2
0
def test_subfield_invalidate():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(UserModel, db.subfieldtest)

    m = mapper({'bar': 'baz'})
    m.save()
    m.name.set({'firstname': 'foo'})
    sf = m.name['firstname']

    m.reload()
    m.name.set({'firstname': 'bar'})
    m.save()
Beispiel #3
0
def test_modelpapper_reload_inc():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    # this is intentional and triggers a model reload
    m.counter.value

    m.counter.inc(1)
    m.save()
Beispiel #4
0
def test_modelpapper_reload_inc():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    # this is intentional and triggers a model reload
    m.counter.value

    m.counter.inc(1)
    m.save()
Beispiel #5
0
def test_modelmapper_unsafe_update():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.counter.set(1)
    m.save()

    m._update.inc('counter', 41)
    m.save()

    expected = {'foo': 'bar', 'counter': 42}
    assert_dict_contains_subset(expected, dict(m))
Beispiel #6
0
def test_modelpapper_reload_multifield_add_to_set():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    m.bar.add_to_set('foo')

    eq_(m.foo.value, 'bar')
    eq_(m.bar.value, ['foo'])

    m.save()
Beispiel #7
0
def test_modelpapper_reload_multifield_push_all():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    m.bar.push_all(['foo', 'bar', 'baz'])

    eq_(m.foo.value, 'bar')
    eq_(m.bar.value, ['foo', 'bar', 'baz'])

    m.save()
Beispiel #8
0
def test_modelpapper_reload_multifield_inc():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    m.counter.inc(1)

    eq_(m.foo.value, 'bar')
    eq_(m.counter.value, 1)

    m.save()
Beispiel #9
0
def test_modelmapper_unsafe_update():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.counter.set(1)
    m.save()

    m._update.inc('counter', 41)
    m.save()

    expected = {'foo': 'bar', 'counter': 42}
    assert_dict_contains_subset(expected, dict(m))
Beispiel #10
0
def test_modelpapper_reload_multifield_add_to_set():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    m.bar.add_to_set('foo')

    eq_(m.foo.value, 'bar')
    eq_(m.bar.value, ['foo'])

    m.save()
Beispiel #11
0
def test_modelpapper_reload_multifield_push_all():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    m.bar.push_all(['foo', 'bar', 'baz'])

    eq_(m.foo.value, 'bar')
    eq_(m.bar.value, ['foo', 'bar', 'baz'])

    m.save()
Beispiel #12
0
def test_modelpapper_reload_multifield_inc():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.save()

    m.counter.inc(1)

    eq_(m.foo.value, 'bar')
    eq_(m.counter.value, 1)

    m.save()
Beispiel #13
0
def test_modelpapper_reload_multifield_unset():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.bar.set('foo')
    m.save()

    m.bar.unset()

    eq_(m.foo.value, 'bar')
    eq_(m.bar.defined, False)

    m.save()
Beispiel #14
0
def test_modelpapper_reload_multifield_unset():
    db = get_db()
    mapper = dibble.mapper.ModelMapper(ReloadTestModel, db.reloadtest)

    m = mapper()
    m.foo.set('bar')
    m.bar.set('foo')
    m.save()

    m.bar.unset()

    eq_(m.foo.value, 'bar')
    eq_(m.bar.defined, False)

    m.save()