本文整理汇总了Python中dynamo3.ItemUpdate类的典型用法代码示例。如果您正苦于以下问题:Python ItemUpdate类的具体用法?Python ItemUpdate怎么用?Python ItemUpdate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ItemUpdate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_condition_converts_eq_null
def test_condition_converts_eq_null(self):
""" Conditional converts eq=None to null=True """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
update = ItemUpdate.put('foo', set([1, 2]), eq=set())
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
update = ItemUpdate.put('foo', set([2]), eq=set())
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例2: test_atomic_add_set
def test_atomic_add_set(self):
""" Update can atomically add to a set """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.add('foo', set([1]))])
self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.add('foo', set([1, 2]))])
item = list(self.dynamo.scan('foobar'))[0]
self.assertEqual(item, {'id': 'a', 'foo': set([1, 2])})
示例3: test_atomic_add_num
def test_atomic_add_num(self):
""" Update can atomically add to a number """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.add('foo', 1)])
self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.add('foo', 2)])
item = list(self.dynamo.scan('foobar'))[0]
self.assertEqual(item, {'id': 'a', 'foo': 3})
示例4: test_expect_condition
def test_expect_condition(self):
""" Update can expect a field to meet a condition """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 5})
update = ItemUpdate.put('foo', 10, lt=5)
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例5: test_expect_not_exists_deprecated
def test_expect_not_exists_deprecated(self):
""" Update can expect a field to not exist """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 'bar'})
update = ItemUpdate.put('foo', 'baz', expected=None)
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例6: test_expect_condition_or
def test_expect_condition_or(self):
""" Expected conditionals can be OR'd together """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 5})
update = ItemUpdate.put('foo', 10, lt=5)
self.dynamo.update_item('foobar', {'id': 'a'}, [update],
expect_or=True, baz__null=True)
示例7: test_expect_field_deprecated
def test_expect_field_deprecated(self):
""" Update can expect a field to have a value """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 'bar'})
update = ItemUpdate.put('foo', 'baz', expected='wat')
with self.assertRaises(CheckFailed):
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
示例8: test_return_item
def test_return_item(self):
""" Update can return the updated item """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
ret = self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.put('foo', 'bar')],
returns=ALL_NEW)
self.assertEqual(ret, {'id': 'a', 'foo': 'bar'})
示例9: test_delete_field
def test_delete_field(self):
""" Update can delete fields from an item """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 'bar'})
self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.delete('foo')])
item = list(self.dynamo.scan('foobar'))[0]
self.assertEqual(item, {'id': 'a'})
示例10: test_update_field
def test_update_field(self):
""" Update an item field """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.put('foo', 'bar')])
item = list(self.dynamo.scan('foobar'))[0]
self.assertEqual(item, {'id': 'a', 'foo': 'bar'})
示例11: test_write_converts_none
def test_write_converts_none(self):
""" Write operation converts None values to a DELETE """
hash_key = DynamoKey('id', data_type=STRING)
self.dynamo.create_table('foobar', hash_key=hash_key)
self.dynamo.put_item('foobar', {'id': 'a', 'foo': 'bar'})
update = ItemUpdate.put('foo', None)
self.dynamo.update_item('foobar', {'id': 'a'}, [update])
ret = list(self.dynamo.scan('foobar'))
self.assertItemsEqual(ret, [{'id': 'a'}])
示例12: test_sync_only_updates_changed
def test_sync_only_updates_changed(self):
""" Sync only updates fields that have been changed """
with patch.object(self.engine, 'dynamo') as dynamo:
captured_updates = []
def update_item(_, __, updates, *___, **____):
""" Mock update_item and capture the passed updateds """
captured_updates.extend(updates)
return {}
dynamo.update_item.side_effect = update_item
p = Post('a', 'b', 4)
self.engine.save(p)
p.foobar = set('a')
p.points = Decimal('2')
p.sync(raise_on_conflict=False)
self.assertEqual(len(captured_updates), 2)
self.assertTrue(ItemUpdate.put('foobar', ANY) in captured_updates)
self.assertTrue(ItemUpdate.put('points', ANY) in captured_updates)
示例13: test_return_metadata
def test_return_metadata(self):
""" The Update return value contains capacity metadata """
self.make_table()
self.dynamo.put_item('foobar', {'id': 'a'})
ret = self.dynamo.update_item('foobar', {'id': 'a'},
[ItemUpdate.put('foo', 'bar')],
returns=ALL_NEW,
return_capacity=TOTAL)
self.assertTrue(is_number(ret.capacity))
self.assertTrue(is_number(ret.table_capacity))
self.assertTrue(isinstance(ret.indexes, dict))
self.assertTrue(isinstance(ret.global_indexes, dict))
示例14: test_item_update_eq
def test_item_update_eq(self):
""" ItemUpdates should be equal """
a, b = ItemUpdate.put('foo', 'bar'), ItemUpdate.put('foo', 'bar')
self.assertEqual(a, b)
self.assertEqual(hash(a), hash(b))
self.assertFalse(a != b)
示例15: test_write_add_require_value
def test_write_add_require_value(self):
""" Doing an ADD requires a non-null value """
with self.assertRaises(ValueError):
ItemUpdate.add('foo', None)