當前位置: 首頁>>代碼示例>>Python>>正文


Python dynamo3.ItemUpdate類代碼示例

本文整理匯總了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])
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:9,代碼來源:test_write.py

示例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])})
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:10,代碼來源:test_write.py

示例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})
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:10,代碼來源:test_write.py

示例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])
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:7,代碼來源:test_write.py

示例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])
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:7,代碼來源:test_write.py

示例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)
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:7,代碼來源:test_write.py

示例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])
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:7,代碼來源:test_write.py

示例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'})
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:8,代碼來源:test_write.py

示例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'})
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:8,代碼來源:test_write.py

示例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'})
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:8,代碼來源:test_write.py

示例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'}])
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:9,代碼來源:test_write.py

示例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)
開發者ID:numberoverzero,項目名稱:flywheel,代碼行數:19,代碼來源:test_models.py

示例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))
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:12,代碼來源:test_write.py

示例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)
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:6,代碼來源:test_write.py

示例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)
開發者ID:mnpk,項目名稱:dynamo3,代碼行數:4,代碼來源:test_write.py


注:本文中的dynamo3.ItemUpdate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。