本文整理汇总了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)
示例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)
示例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')
示例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')
示例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)
示例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}')
示例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
示例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))
示例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
示例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()
示例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()
示例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
示例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)
示例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)
示例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