Ejemplo n.º 1
0
 def test_resource_pks(self):
     """Test the pk creation"""
     res = ResourceModel(_pks='["id", "pk"]')
     self.assertListEqual(res.pks, ['id', 'pk'])
     res.pks = ['id']
     self.assertListEqual(res.pks, ['id'])
     self.assertEqual('["id"]', res._pks)
Ejemplo n.º 2
0
 def test_resource_construction(self):
     """Simple Resource construction"""
     with self.app.app_context():
         user = self.db.session.query(User).filter_by(username='******').first()
         man_model = ManagerModel(model_name='blah', owner=user, fields=('id',))
         self.db.session.add(man_model)
         self.db.session.commit()
         res = ResourceModel(restmixin='CRUDL', manager=man_model, owner=user)
         res.pks = ['id']
         resource_class = res.resource
         self.assertEqual(restmixins.CRUDL, res.restmixin_class)
         self.assertIsInstance(resource_class, ResourceMetaClass)
         req = RequestContainer()
         resource_instance = resource_class.create(req)
         self.assertIsInstance(resource_instance, resource_class)
         id_ = resource_instance.properties['id']
         engine = get_database_engine(user)
         session = ScopedSessionHandler(engine).get_session()
         model = session.query(self.model).get(id_)
         self.assertIsNotNone(model)
         self.assertListEqual(res.pks, ['id'])
         self.assertEqual(res._pks, '["id"]')