当前位置: 首页>>代码示例>>Python>>正文


Python item.ItemModel类代码示例

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


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


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