예제 #1
0
 def test_excluded_pk_with_allow_pk_will_not_be_changed(self):
     named = Named('a name')
     self.session.add(named)
     self.session.commit()
     original_id = named.id
     named.fromdict({'id': original_id + 1}, allow_pk=True, exclude=['id'])
     assert named.id == original_id
예제 #2
0
 def test_dictalchemy_include_doesnt_override_pk(self):
     h = Named('a name')
     try:
         h.fromdict({'id': 1}, include=['id'])
         assert False
     except DictalchemyError:
         assert True
예제 #3
0
 def test_fromdict_allow_pk(self):
     s = self.session
     named = Named('a name')
     s.add(named)
     s.commit()
     new = {'id': 7}
     named.fromdict(new, allow_pk=True)
     assert named.asdict() == {'id': new['id'], 'name': named.name}
예제 #4
0
 def test_simple(self):
     s = self.session
     named = Named('a name')
     s.add(named)
     s.commit()
     new = {'name': 'other name'}
     named.fromdict(new)
     assert named.asdict() == {'id': named.id, 'name': new['name']}
예제 #5
0
    def test_exluded_pk_will_not_raise_exception(self):
        named = Named('a name')
        self.session.add(named)
        self.session.commit()
        original_id = named.id

        named.fromdict({'id': original_id + 1}, exclude=['id'])
        assert named.id == original_id
예제 #6
0
 def test_simple_aborts_on_pk(self):
     s = self.session
     named = Named('a name')
     s.add(named)
     s.commit()
     new = {'id': 7}
     try:
         named.fromdict(new)
     except:
         pass
     else:
         assert False
예제 #7
0
 def test_exclude(self):
     h = Named('a name')
     h.fromdict({'name': 'other name'}, exclude=['name'])
     assert h.name == 'a name'
예제 #8
0
 def test_only_overrides_exclude(self):
     named = Named('a name')
     named.fromdict({'name': 'other name'}, exclude='name', only=['name'])
     assert named.name == 'other name'
예제 #9
0
 def test_only(self):
     named = Named('a name')
     named.fromdict({'name': 'other name'}, only=['name'])
     assert named.name == 'other name'
     named.fromdict({'name': 'other name'}, only=['id'])
     assert named.name == 'other name'