Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Test find or create key.

  • Loading branch information...
commit 6e6574fefd211e8292b252efcf2f7b98a85e07d9 1 parent a8e84ef
Cory Benfield authored March 07, 2013

Showing 1 changed file with 19 additions and 0 deletions. Show diff stats Hide diff stats

  1. 19  test_collectr.py
19  test_collectr.py
@@ -83,6 +83,25 @@ def test_key_name_from_path(self):
83 83
         result = self.dir.key_name_from_path(path)
84 84
         self.assertEqual(result, expected_result)
85 85
 
  86
+    @mock.patch('boto.s3.key.Key')
  87
+    def test_find_or_create_key(self, mock_key):
  88
+        # Set up.
  89
+        instance = mock_key.return_value
  90
+        instance.key = 'test_key'
  91
+        bucket = mock.MagicMock()
  92
+        bucket.lookup.return_value = None
  93
+
  94
+        # First, test when we can't find the key.
  95
+        result = self.dir.find_or_create_key('/test', bucket)
  96
+        bucket.lookup.assert_called_once_with('/test')
  97
+        self.assertEqual(result.key, '/test')
  98
+
  99
+        # Next, test when we can.
  100
+        bucket.lookup.return_value = mock.MagicMock()
  101
+        result = self.dir.find_or_create_key('/test', bucket)
  102
+        bucket.lookup.assert_called_with('/test')
  103
+        self.assertEqual(result.key, '/test')
  104
+
86 105
 
87 106
 if __name__ == '__main__':
88 107
     unittest.main()

0 notes on commit 6e6574f

Please sign in to comment.
Something went wrong with that request. Please try again.