]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_client.py: cleanups to S3 config tests.
authorDaira Hopwood <daira@jacaranda.org>
Tue, 5 Feb 2013 19:42:01 +0000 (19:42 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 16 Oct 2015 16:45:29 +0000 (17:45 +0100)
Signed-off-by: David-Sarah Hopwood <david-sarah@jacaranda.org>
src/allmydata/test/test_client.py

index 2f3ec972e0ce1e229c06eed46ebebe82946a2b9b..75070ad01a71f5983035ab8eee29b4734f926f1b 100644 (file)
@@ -202,15 +202,15 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
                                     "reserved_space = bogus\n")
         self.failUnlessRaises(InvalidValueError, client.Client, basedir)
 
-    def _write_s3secret(self, basedir, secret="dummy"):
-        os.mkdir(os.path.join(basedir, "private"))
-        fileutil.write(os.path.join(basedir, "private", "s3secret"), secret)
+    def _write_secret(self, basedir, filename, secret="dummy"):
+        fileutil.make_dirs(os.path.join(basedir, "private"))
+        fileutil.write(os.path.join(basedir, "private", filename), secret)
 
     @mock.patch('allmydata.storage.backends.cloud.s3.s3_container.S3Container')
     def test_s3_config_good_defaults(self, mock_S3Container):
         basedir = "client.Basic.test_s3_config_good_defaults"
         os.mkdir(basedir)
-        self._write_s3secret(basedir)
+        self._write_secret(basedir, "s3secret")
         config = (BASECONFIG +
                   "[storage]\n" +
                   "enabled = true\n" +
@@ -225,11 +225,11 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
         self.failUnless(isinstance(server.backend, CloudBackend), server.backend)
 
         mock_S3Container.reset_mock()
-        fileutil.write(os.path.join(basedir, "private", "s3producttoken"), "{ProductToken}")
+        self._write_secret(basedir, "s3producttoken", secret="{ProductToken}")
         self.failUnlessRaises(InvalidValueError, client.Client, basedir)
 
         mock_S3Container.reset_mock()
-        fileutil.write(os.path.join(basedir, "private", "s3usertoken"), "{UserToken}")
+        self._write_secret(basedir, "s3usertoken", secret="{UserToken}")
         fileutil.write(os.path.join(basedir, "tahoe.cfg"), config + "s3.url = http://s3.example.com\n")
 
         c = client.Client(basedir)
@@ -239,7 +239,7 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
     def test_s3_readonly_bad(self):
         basedir = "client.Basic.test_s3_readonly_bad"
         os.mkdir(basedir)
-        self._write_s3secret(basedir)
+        self._write_secret(basedir, "s3secret")
         fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                                     BASECONFIG +
                                     "[storage]\n" +
@@ -319,7 +319,7 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
     def test_s3_config_no_access_key_id(self):
         basedir = "client.Basic.test_s3_config_no_access_key_id"
         os.mkdir(basedir)
-        self._write_s3secret(basedir)
+        self._write_secret(basedir, "s3secret")
         fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                                     BASECONFIG +
                                     "[storage]\n" +
@@ -331,7 +331,7 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
     def test_s3_config_no_bucket(self):
         basedir = "client.Basic.test_s3_config_no_bucket"
         os.mkdir(basedir)
-        self._write_s3secret(basedir)
+        self._write_secret(basedir, "s3secret")
         fileutil.write(os.path.join(basedir, "tahoe.cfg"),
                                     BASECONFIG +
                                     "[storage]\n" +