diff options
author | Mitch Garnaat <mitch@garnaat.com> | 2012-05-15 18:59:46 -0700 |
---|---|---|
committer | Mitch Garnaat <mitch@garnaat.com> | 2012-05-15 18:59:46 -0700 |
commit | 1aa1133e8502ea6c95e49ac34681569df5ace46b (patch) | |
tree | a25397b20d7d409131ccfbfce5d4dca23d7e52a4 /tests/s3/test_key.py | |
parent | 911f42b97fdccbc55e160ec323df0cad6fe64c6b (diff) | |
parent | 6588ea270bfc9e0bb4d17263b72ee8b5255545c5 (diff) | |
download | boto-2.4.0.tar.gz |
Merge branch 'release-2.4.0'2.4.0
Diffstat (limited to 'tests/s3/test_key.py')
-rw-r--r-- | tests/s3/test_key.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/s3/test_key.py b/tests/s3/test_key.py index c961b317..2e823182 100644 --- a/tests/s3/test_key.py +++ b/tests/s3/test_key.py @@ -45,6 +45,36 @@ class S3KeyTest (unittest.TestCase): key.delete() self.bucket.delete() + def test_set_contents_from_file_dataloss(self): + # Create an empty stringio and write to it. + content = "abcde" + sfp = StringIO.StringIO() + sfp.write(content) + # Try set_contents_from_file() without rewinding sfp + k = self.bucket.new_key("k") + try: + k.set_contents_from_file(sfp) + self.fail("forgot to rewind so should fail.") + except AttributeError: + pass + # call with rewind and check if we wrote 5 bytes + k.set_contents_from_file(sfp, rewind=True) + self.assertEqual(k.size, 5) + # check actual contents by getting it. + kn = self.bucket.new_key("k") + ks = kn.get_contents_as_string() + self.assertEqual(ks, content) + + # finally, try with a 0 length string + sfp = StringIO.StringIO() + k = self.bucket.new_key("k") + k.set_contents_from_file(sfp) + self.assertEqual(k.size, 0) + # check actual contents by getting it. + kn = self.bucket.new_key("k") + ks = kn.get_contents_as_string() + self.assertEqual(ks, "") + def test_set_contents_as_file(self): content="01234567890123456789" sfp = StringIO.StringIO(content) |