Beispiel #1
0
    def update(cls, model: str, pk: int, obj: dict, *args, session: Session,
               base: Type[Base], **kwargs) -> DBRes:
        assert session is not None
        first = session.query(base).filter(base.id == pk).first()
        if first is None:
            return DBRes.not_found()

        if first.is_locked and obj.get('is_locked') is True:
            return DBRes.resource_locked()

        for k, v in obj.items():
            if k not in ['id', 'create_at', 'update_at'
                         ] and not cls.is_null_foreign_key(k, v):
                setattr(first, k, v)
        return DBRes(data=first.as_dict())
Beispiel #2
0
 def test_not_found(self):
     self.assertEqual(DBDao.update(model='connection', pk=1, obj=dict()),
                      DBRes.not_found())
Beispiel #3
0
 def test_not_init_session(self):
     DBSession.init_engine(None)
     with self.assertRaises(AssertionError):
         self.assertEqual(
             DBDao.update(model='connection', pk=1, obj=dict()),
             DBRes.not_found())