Commits

Max Noel committed c8bc9db

* autoincrement_int: it's better if we actually *raise* MaxRetriesExceededError. That'll teach me to commit untested code -- there, have a unit test too.

Comments (0)

Files changed (2)

dynamodb_mapper/model.py

                 log.debug(
                     "table=%s, max hash key has changed. Retrying (%s).",
                     item.table, tries)
+        else:
+            raise MaxRetriesExceededError()
 
     def save(self, allow_overwrite=True, expected_values=None):
         """Save the object to the database.

dynamodb_mapper/tests/test_model.py

 import mock
 
 from dynamodb_mapper.model import (ConnectionBorg, DynamoDBModel, json_list,
-    json_dict, autoincrement_int)
+    json_dict, autoincrement_int, MaxRetriesExceededError, MAX_RETRIES)
 from boto.exception import DynamoDBResponseError
 
 
         m_item.return_value.__setitem__.assert_called_with("id", 3)
         self.assertEquals(m_item.return_value.__setitem__.call_count, 2)
 
+    @mock.patch("dynamodb_mapper.model.Item")
+    @mock.patch("dynamodb_mapper.model.boto")
+    def test_save_autoincrement_int_max_retries(self, m_boto, m_item):
+        m_item_instance = m_item.return_value
+        m_item_instance.hash_key_name = "id"
+        max_item = m_item_instance.table.get_item.return_value
+        max_item.__getitem__.return_value = 2
+        error = DynamoDBResponseError(
+            None, None, {"__type": "ConditionalCheckFailedException"})
+        # the put call will never succeed
+        m_item_instance.put.side_effect = error
+
+        l = LogEntry()
+        l.text = "Everybody's dead, Dave."
+        self.assertRaises(MaxRetriesExceededError, l.save)
+
+        self.assertEquals(m_item_instance.put.call_count, MAX_RETRIES)
+
     def test_query(self):
         pass
 
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.