Commits

Jean-Tiare Le Bigot committed e1f54c2

same with tests and without the bugs

Comments (0)

Files changed (3)

ddbmock/database/table.py

 
         size = ItemSize(0)
         scanned = 0
-        lek = None
+        lek = {}
         results = []
         skip = start is not None
+        hk_name = self.hash_key.name
+        rk_name = self.range_key.name if self.range_key else None
 
         for item in self.store:
             # first, skip all items before start
             if skip:
-                if start['HashKeyElement'] != item[self.hash_key.name]:
+                if start['HashKeyElement'] != item[hk_name]:
                     continue
-                if self.range_key and start['RangeKeyElement'] == item[self.range_key.name]:
+                if rk_name and start['RangeKeyElement'] != item[rk_name]:
                     continue
                 skip = False
                 continue
 
             # quit ?
             if scanned == limit:
-                lek = {
-                    u'HashKeyElement': hash_key,
-                    u'RangeKeyElement': item[rk_name],
-                }
+                lek[u'HashKeyElement'] = item[hk_name]
+                if rk_name:
+                    lek[u'RangeKeyElement'] = item[rk_name]
                 break
 
         return Results(results, size, lek, scanned)

ddbmock/operations/scan.py

         "ConsumedCapacityUnits": capacity,
     }
 
-    if results.last_key is not None:
+    if results.last_key:
         ret['LastEvaluatedKey'] = results.last_key
 
     if not post[u'Count']:

tests/functional/boto/test_scan.py

         ret = db.layer1.scan(TABLE_NAME, None)
         self.assertEqual(expected, ret)
 
+    def test_scan_paged(self):
+        from ddbmock import connect_boto_patch
+        from ddbmock.database.db import dynamodb
+        from boto.dynamodb.exceptions import DynamoDBValidationError
+
+        esk = {
+            u'HashKeyElement': {u'N': u'789'},
+            u'RangeKeyElement': {u'S': u'Waldo-5'},
+        }
+
+        expected1 = {
+            u"Count": 4,
+            u"ScannedCount": 4,
+            u"Items": [ITEM2, ITEM1, ITEM6, ITEM5],
+            u"ConsumedCapacityUnits": 1.5,
+            u'LastEvaluatedKey': esk,
+        }
+        expected2 = {
+            u"Count": 2,
+            u"ScannedCount": 2,
+            u"Items": [ITEM4, ITEM3],
+            u"ConsumedCapacityUnits": 0.5,
+        }
+
+        db = connect_boto_patch()
+
+        ret = db.layer1.scan(TABLE_NAME, limit=4)
+        self.assertEqual(expected1, ret)
+        ret = db.layer1.scan(TABLE_NAME, exclusive_start_key=esk)
+        self.assertEqual(expected2, ret)
+
     def test_scan_all_filter_fields(self):
         from ddbmock import connect_boto_patch
         from ddbmock.database.db import dynamodb
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.