• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python item.ItemModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.item.ItemModel的典型用法代码示例。如果您正苦于以下问题:Python ItemModel类的具体用法?Python ItemModel怎么用?Python ItemModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ItemModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_unserialization

def test_unserialization():

    item = ItemModel('item_name', 10, True, '12345')

    serialized = item.serialize()

    assert item == ItemModel.unserialize(serialized)
开发者ID:fpischedda,项目名称:lsystem,代码行数:7,代码来源:test_item.py


示例2: unlock

 def unlock(self, filter, user, etag):
     item_model = ItemModel(self.data_layer)
     filter[LOCK_USER] = user
     # filter[ETAG] = etag
     item = item_model.find_one(filter)
     if item:
         updates = {LOCK_USER: None, 'lock_time': None}
         item_model.update(filter, updates)
开发者ID:PythonCharmers,项目名称:superdesk-server,代码行数:8,代码来源:item_lock.py


示例3: test_store_relationship

    def test_store_relationship(self):
        with self.app_context():
            store = StoreModel('test_store')
            item = ItemModel('test', 19.99, 1)

            store.save_to_db()
            item.save_to_db()

            self.assertEqual(item.store.name, 'test_store')
开发者ID:senarclens,项目名称:testing-python-apps,代码行数:9,代码来源:item_test.py


示例4: test_store_relationship

    def test_store_relationship(self):
        with self.app_context():
            store = StoreModel('test')
            item = ItemModel('test_item', 19.99, 1)
            store.save_to_db()
            item.save_to_db()

            self.assertEqual(store.items.count(), 1)
            self.assertEqual(store.items.first().name, 'test_item')
开发者ID:b9007,项目名称:Python,代码行数:9,代码来源:test_store.py


示例5: test_put_update_item

 def test_put_update_item(self):
     with self.app() as client:
         with self.app_context():
             StoreModel('test').save_to_db()
             ItemModel('test', 19, 1).save_to_db()
             self.assertEqual(ItemModel.find_by_name('test').price, 19)
             response = client.put('/item/test', data={'name': 'test', 'price': 17, 'store_id': 1})
             self.assertEqual(response.status_code, 200)
             self.assertDictEqual({'name': 'test', 'price': 17}, json.loads(response.data))
             self.assertEqual(ItemModel.find_by_name('test').price, 17)
开发者ID:lilitam,项目名称:stores_rest_api_test,代码行数:10,代码来源:test_item.py


示例6: test_item_json

    def test_item_json(self):
        item = ItemModel('test', 19.99, 1)
        expected = {
            'name': 'test',
            'price': 19.99
        }

        self.assertEqual(item.json(), expected,
                         f'The JSON export of the item is incorrect. '
                         f'Received {item.json()}, expected {expected}')
开发者ID:b9007,项目名称:Python,代码行数:10,代码来源:test_item.py


示例7: test_serialization

def test_serialization():

    item = ItemModel('item_name', 10, True, '12345')

    expected_serialization = {'name': 'item_name',
                              'quantity': 10,
                              'usable': True,
                              'user_id': '12345'}

    assert item.serialize() == expected_serialization
开发者ID:fpischedda,项目名称:lsystem,代码行数:10,代码来源:test_item.py


示例8: test_item_json

    def test_item_json(self):
        item = ItemModel('test', 19.99)
        expected = {
            'name': 'test',
            'price': 19.99
        }

        self.assertEqual(
            item.json(),
            expected,
            "The JSON export of the item is incorrect. Received {}, expected {}.".format(item.json(), expected))
开发者ID:senarclens,项目名称:testing-python-apps,代码行数:11,代码来源:item_test.py


示例9: lock

 def lock(self, filter, user, etag):
     item_model = ItemModel(self.data_layer)
     item = item_model.find_one(filter)
     if item and self._can_lock(item, user):
         # filter[ETAG] = etag
         updates = {LOCK_USER: user, 'lock_time': utcnow()}
         item_model.update(filter, updates)
         item[LOCK_USER] = user
     else:
         raise SuperdeskError('Item locked by another user')
     return item
开发者ID:PythonCharmers,项目名称:superdesk-server,代码行数:11,代码来源:item_lock.py


示例10: put

    def put(self, name):
        data = Item.parser.parse_args()

        item = ItemModel.find_by_name(name)

        if item:
            item.price = data['price']
        else:
            item = ItemModel(name, **data)

        item.save_to_db()

        return item.json()
开发者ID:tecladocode,项目名称:flask-jwt-extended-section-lectures,代码行数:13,代码来源:item.py


示例11: post

    def post(self, name):
        if ItemModel.find_by_name(name):
            return {'message': "An item with name '{}' already exists.".format(name)}

        data = Item.parser.parse_args()

        item = ItemModel(name, data['price'], data['store_id'])

        try:
            item.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}

        return item.json()
开发者ID:harrysoer,项目名称:flask-api,代码行数:14,代码来源:item.py


示例12: post

    def post(self, name):
        if ItemModel.find_by_name(name):
            return {'message': "An item with name '{}' already exists.".format(name)}, 400

        data = Item.parser.parse_args()

        item = ItemModel(name, **data)

        try:
            item.save_to_db()
        except:
            return {"message": "An error occurred inserting the item."}, 500

        return item.json(), 201
开发者ID:tecladocode,项目名称:flask-jwt-extended-section-lectures,代码行数:14,代码来源:item.py


示例13: test_store_json_with_item

    def test_store_json_with_item(self):
        with self.app_context():

            store = StoreModel('test')
            item = ItemModel('test_item', 19.99, 1)

            store.save_to_db()
            item.save_to_db()

            expected = {
                'name': 'test',
                'items': [{'name': 'test_item', 'price': 19.99}]
            }

            self.assertDictEqual(store.json(), expected)
开发者ID:b9007,项目名称:Python,代码行数:15,代码来源:test_store.py


示例14: test_put_update_item

    def test_put_update_item(self):
        with self.app() as c:
            with self.app_context():
                StoreModel('test').save_to_db()
                c.put('/item/test', data={'price': 17.99, 'store_id': 1})
                r = c.put('/item/test', data={'price': 18.99, 'store_id': 1})

                self.assertEqual(r.status_code, 200)
                self.assertEqual(ItemModel.find_by_name('test').price, 18.99)
开发者ID:senarclens,项目名称:testing-python-apps,代码行数:9,代码来源:item_test.py


示例15: get

 def get(self):
     user_id = get_jwt_identity()
     items = [item.json() for item in ItemModel.find_all()]
     if user_id:
         return {'items': items}, 200
     return {
         'items': [item['name'] for item in items],
         'message': 'More data available if you log in.'
     }, 200
开发者ID:kpgdsc,项目名称:rest-api-sections,代码行数:9,代码来源:item.py


示例16: delete

    def delete(self, name):
        claims = get_jwt_claims()
        if not claims['is_admin']:
            return {'message': 'Admin privilege required.'}, 401

        item = ItemModel.find_by_name(name)
        if item:
            item.delete_from_db()
            return {'message': 'Item deleted.'}
        return {'message': 'Item not found.'}, 404
开发者ID:tecladocode,项目名称:flask-jwt-extended-section-lectures,代码行数:10,代码来源:item.py


示例17: test_put_item

    def test_put_item(self):
        with self.app() as c:
            with self.app_context():
                StoreModel('test').save_to_db()
                r = c.put('/item/test', data={'price': 17.99, 'store_id': 1})

                self.assertEqual(r.status_code, 200)
                self.assertEqual(ItemModel.find_by_name('test').price, 17.99)
                self.assertDictEqual(d1={'name': 'test', 'price': 17.99},
                                     d2=json.loads(r.data))
开发者ID:senarclens,项目名称:testing-python-apps,代码行数:10,代码来源:item_test.py


示例18: test_crud

    def test_crud(self):
        with self.app_context():
            item = ItemModel('test', 19.99)

            self.assertIsNone(ItemModel.find_by_name('test'),
                              "Found an item with name {}, but expected not to.".format(item.name))

            item.save_to_db()

            self.assertIsNotNone(ItemModel.find_by_name('test'))

            item.delete_from_db()

            self.assertIsNone(ItemModel.find_by_name('test'))
开发者ID:senarclens,项目名称:testing-python-apps,代码行数:14,代码来源:item_test.py


示例19: test_crud

    def test_crud(self):
        with self.app_context():
            store = StoreModel('test')
            store.save_to_db()
            item = ItemModel('test', 19.99, 1)

            self.assertIsNone(ItemModel.find_by_name('test'), "Found an item with name 'test' before save_to_db")

            item.save_to_db()

            self.assertIsNotNone(ItemModel.find_by_name('test'),
                                 "Did not find an item with name 'test' after save_to_db")

            item.delete_from_db()

            self.assertIsNone(ItemModel.find_by_name('test'), "Found an item with name 'test' after delete_from_db")
开发者ID:senarclens,项目名称:testing-python-apps,代码行数:16,代码来源:item_test.py


示例20: put

    def put(self, name):
        data = Item.parser.parse_args()
        item = ItemModel.find_by_name(name)
        if item is None:
            item = ItemModel(name, data['price'], data['store_id'])
        else:
            item.price = data['price']

        item.save_to_db()
        return item.json()
开发者ID:harrysoer,项目名称:flask-api,代码行数:10,代码来源:item.py



注:本文中的models.item.ItemModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python logger.exception函数代码示例发布时间:2022-05-27
下一篇:
Python insight.Insight类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap