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()
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()
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))
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()
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()
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()
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()