summaryrefslogtreecommitdiff
path: root/tests/integration/dynamodb2/test_highlevel.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration/dynamodb2/test_highlevel.py')
-rw-r--r--tests/integration/dynamodb2/test_highlevel.py77
1 files changed, 73 insertions, 4 deletions
diff --git a/tests/integration/dynamodb2/test_highlevel.py b/tests/integration/dynamodb2/test_highlevel.py
index eed46efa..46848fae 100644
--- a/tests/integration/dynamodb2/test_highlevel.py
+++ b/tests/integration/dynamodb2/test_highlevel.py
@@ -23,11 +23,14 @@
"""
Tests for DynamoDB v2 high-level abstractions.
"""
+from __future__ import with_statement
+
import time
from tests.unit import unittest
from boto.dynamodb2 import exceptions
from boto.dynamodb2.fields import HashKey, RangeKey, KeysOnlyIndex
+from boto.dynamodb2.items import Item
from boto.dynamodb2.table import Table
from boto.dynamodb2.types import NUMBER
@@ -43,12 +46,12 @@ class DynamoDBv2Test(unittest.TestCase):
], throughput={
'read': 5,
'write': 5,
- }, indexes={
+ }, indexes=[
KeysOnlyIndex('LastNameIndex', parts=[
HashKey('username'),
RangeKey('last_name')
]),
- })
+ ])
self.addCleanup(users.delete)
self.assertEqual(len(users.schema), 2)
@@ -146,7 +149,10 @@ class DynamoDBv2Test(unittest.TestCase):
self.assertEqual(check_name_again['first_name'], 'Joan')
# Reset it.
- jane.mark_dirty()
+ jane['username'] = 'jane'
+ jane['first_name'] = 'Jane'
+ jane['last_name'] = 'Doe'
+ jane['friend_count'] = 3
self.assertTrue(jane.save(overwrite=True))
# Test the partial update behavior.
@@ -176,9 +182,27 @@ class DynamoDBv2Test(unittest.TestCase):
self.assertEqual(partial_jane['first_name'], 'Jacqueline')
# Reset it.
- jane.mark_dirty()
+ jane['username'] = 'jane'
+ jane['first_name'] = 'Jane'
+ jane['last_name'] = 'Doe'
+ jane['friend_count'] = 3
self.assertTrue(jane.save(overwrite=True))
+ # Ensure that partial saves of a brand-new object work.
+ sadie = Item(users, data={
+ 'username': 'sadie',
+ 'first_name': 'Sadie',
+ 'favorite_band': 'Zedd',
+ 'friend_count': 7
+ })
+ self.assertTrue(sadie.partial_save())
+ serverside_sadie = users.get_item(
+ username='sadie',
+ friend_count=7,
+ consistent=True
+ )
+ self.assertEqual(serverside_sadie['first_name'], 'Sadie')
+
# Test the eventually consistent query.
results = users.query(
username__eq='johndoe',
@@ -274,3 +298,48 @@ class DynamoDBv2Test(unittest.TestCase):
)
# But it shouldn't break on more complex tables.
res = users.query(username__eq='johndoe')
+
+ # Test putting with/without sets.
+ mau5_created = users.put_item(data={
+ 'username': 'mau5',
+ 'first_name': 'dead',
+ 'last_name': 'mau5',
+ 'friend_count': 2,
+ 'friends': set(['skrill', 'penny']),
+ })
+ self.assertTrue(mau5_created)
+
+ penny_created = users.put_item(data={
+ 'username': 'penny',
+ 'first_name': 'Penny',
+ 'friend_count': 0,
+ 'friends': set([]),
+ })
+ self.assertTrue(penny_created)
+
+ def test_unprocessed_batch_writes(self):
+ # Create a very limited table w/ low throughput.
+ users = Table.create('slow_users', schema=[
+ HashKey('user_id'),
+ ], throughput={
+ 'read': 1,
+ 'write': 1,
+ })
+ self.addCleanup(users.delete)
+
+ # Wait for it.
+ time.sleep(60)
+
+ with users.batch_write() as batch:
+ for i in range(500):
+ batch.put_item(data={
+ 'user_id': str(i),
+ 'name': 'Droid #{0}'.format(i),
+ })
+
+ # Before ``__exit__`` runs, we should have a bunch of unprocessed
+ # items.
+ self.assertTrue(len(batch._unprocessed) > 0)
+
+ # Post-__exit__, they should all be gone.
+ self.assertEqual(len(batch._unprocessed), 0)