Jean-Tiare Le Bigot committed ec402ab

make DynamoDB._internal_delete_table idempotent in case table ref has already been deleted manually (cf unit testing). issue #8

Comments (0)

Files changed (3)


     # FIXME: what if the table ref changed in the mean time ?
-    def _internal_delete_table(self, name):
-        """This is ran only after the timer is exhausted"""
-        if name in
+    def _internal_delete_table(self, table):
+        """This is ran only after the timer is exhausted.
+        Important note: this function is idempotent. If another table with the
+        same name has been created in the mean time, it won't be overwrittem.
+        This is the kind of special cases you might encounter in testing
+        environenment"""
+        name =
+        if name in and[name] is table:
   [name].store.truncate()  # FIXME: should be moved in table
             del[name, False]


         self.status = "DELETING"
-        Timer(config.DELAY_DELETING, callback, []).start()
+        Timer(config.DELAY_DELETING, callback, [self]).start()
     def activate(self):
         self.status = "ACTIVE"


     def setUp(self):
         from ddbmock.database import dynamodb
-[TABLE_NAME] = mock.Mock()
+        self.t1 = mock.Mock()
+[TABLE_NAME] = self.t1[TABLE_NAME, False] =[TABLE_NAME]
     def test_internal_delete_table(self):
         from ddbmock.database import dynamodb
+        # make sure that deleting another table with the same name does nothing
+        t2 = mock.Mock()
         # delete a table
-        dynamodb._internal_delete_table(TABLE_NAME)
-        self.assertNotIn(TABLE_NAME,
+        dynamodb._internal_delete_table(t2)
+        self.assertIn(TABLE_NAME,
         # make sure deleting already deleted table does not harm
-        dynamodb._internal_delete_table(TABLE_NAME)
+        dynamodb._internal_delete_table(self.t1)
     def test_delete_table(self):
         from ddbmock.database import dynamodb