Anonymous avatar Anonymous committed e614802 Draft

Hum, previous commit was meant to establish a connection ONCE and for all, not once for EACH connection... Never work late a Friday :D

Comments (0)

Files changed (2)

dynamodb_mapper/model.py

 
 import json
 import logging
-import threading
 from datetime import datetime, timedelta, tzinfo
 
 import boto
         """Return the DynamoDB connection for the mapper
         """
         if self._connection is None:
-            self._connections = boto.connect_dynamodb(
+            self._connection = boto.connect_dynamodb(
                 aws_access_key_id=self._aws_access_key_id,
                 aws_secret_access_key=self._aws_secret_access_key,
                 region=self._region,
             )
-        return self._connections
+        return self._connection
 
     def _create_autoincrement_magic_item(self, table):
         item = table.new_item(hash_key=MAGIC_KEY, attrs={

dynamodb_mapper/tests/test_model.py

         self.assertEquals(borg2._aws_secret_access_key, aws_secret_access_key)
 
     @mock.patch("dynamodb_mapper.model.boto")
+    def test_get_connection(self, m_boto):
+        CONNECTION = "JJG"
+        REGION = "La bas, tout est neuf et tout est sauvage."
+        KEY_ID = "foo"
+        KEY_VALUE = "bar"
+
+        m_boto.connect_dynamodb.return_value = "JJG"
+
+        borg1 = ConnectionBorg()
+        borg2 = ConnectionBorg()
+
+        borg1._region = REGION
+        borg1._aws_access_key_id = KEY_ID
+        borg1._aws_secret_access_key = KEY_VALUE
+
+        self.assertIsNone(borg1._connection)
+        self.assertEqual(CONNECTION, borg2._get_connection())
+        self.assertEqual(CONNECTION, borg1._get_connection())
+        self.assertEqual(CONNECTION, borg1._connection)
+
+        m_boto.connect_dynamodb.assert_called_once_with(
+                aws_access_key_id=KEY_ID,
+                aws_secret_access_key=KEY_VALUE,
+                region=REGION,
+                )
+
+    @mock.patch("dynamodb_mapper.model.boto")
     def test_set_region_valid(self, m_boto):
         # Make sure internal state is set and shared
         m_regions = [
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.