summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-04-06 14:10:05 +0000
committerGerrit Code Review <review@openstack.org>2016-04-06 14:10:05 +0000
commit81e37a2dce174a1f8e2f1da6aebd9c921bf5f7de (patch)
tree19260640901ed1842b3fbc9e7f73acba807dac02
parent492aa74fed53eb4c0cf8ac9a7dc0e3faa13bd9a1 (diff)
parent3c82c0e62e5b661d03ad7d9a3e93f95876805c2d (diff)
downloadpython-openstackclient-81e37a2dce174a1f8e2f1da6aebd9c921bf5f7de.tar.gz
Merge "Improve tmpfile cleanup in functests"
-rw-r--r--functional/tests/compute/v2/test_keypair.py23
-rw-r--r--functional/tests/object/v1/test_object.py30
2 files changed, 26 insertions, 27 deletions
diff --git a/functional/tests/compute/v2/test_keypair.py b/functional/tests/compute/v2/test_keypair.py
index c9e8f3bc..d6c5ad28 100644
--- a/functional/tests/compute/v2/test_keypair.py
+++ b/functional/tests/compute/v2/test_keypair.py
@@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-import os
+import tempfile
import uuid
from functional.common import test
@@ -44,19 +44,18 @@ class KeypairTests(test.TestCase):
cls.assertOutput('', raw_output)
def test_keypair_create(self):
- TMP_FILE = uuid.uuid4().hex
- self.addCleanup(os.remove, TMP_FILE)
- with open(TMP_FILE, 'w') as f:
+ with tempfile.NamedTemporaryFile() as f:
f.write(PUBLIC_KEY)
+ f.flush()
- raw_output = self.openstack(
- 'keypair create --public-key ' + TMP_FILE + ' tmpkey',
- )
- self.addCleanup(
- self.openstack,
- 'keypair delete tmpkey',
- )
- self.assertIn('tmpkey', raw_output)
+ raw_output = self.openstack(
+ 'keypair create --public-key %s tmpkey' % f.name,
+ )
+ self.addCleanup(
+ self.openstack,
+ 'keypair delete tmpkey',
+ )
+ self.assertIn('tmpkey', raw_output)
def test_keypair_list(self):
opts = self.get_list_opts(self.HEADERS)
diff --git a/functional/tests/object/v1/test_object.py b/functional/tests/object/v1/test_object.py
index cd98012c..8ea16da7 100644
--- a/functional/tests/object/v1/test_object.py
+++ b/functional/tests/object/v1/test_object.py
@@ -11,6 +11,7 @@
# under the License.
import os
+import tempfile
import uuid
from functional.common import test
@@ -24,17 +25,14 @@ class ObjectTests(test.TestCase):
"""Functional tests for Object commands. """
CONTAINER_NAME = uuid.uuid4().hex
- OBJECT_NAME = uuid.uuid4().hex
- TMP_FILE = 'tmp.txt'
-
- def setUp(self):
- super(ObjectTests, self).setUp()
- self.addCleanup(os.remove, self.OBJECT_NAME)
- self.addCleanup(os.remove, self.TMP_FILE)
- with open(self.OBJECT_NAME, 'w') as f:
- f.write('test content')
def test_object(self):
+ with tempfile.NamedTemporaryFile() as f:
+ f.write('test content')
+ f.flush()
+ self._test_object(f.name)
+
+ def _test_object(self, object_file):
raw_output = self.openstack('container create ' + self.CONTAINER_NAME)
items = self.parse_listing(raw_output)
self.assert_show_fields(items, CONTAINER_FIELDS)
@@ -50,7 +48,7 @@ class ObjectTests(test.TestCase):
# TODO(stevemar): Assert returned fields
raw_output = self.openstack('object create ' + self.CONTAINER_NAME
- + ' ' + self.OBJECT_NAME)
+ + ' ' + object_file)
items = self.parse_listing(raw_output)
self.assert_show_fields(items, OBJECT_FIELDS)
@@ -59,23 +57,25 @@ class ObjectTests(test.TestCase):
self.assert_table_structure(items, BASIC_LIST_HEADERS)
self.openstack('object save ' + self.CONTAINER_NAME
- + ' ' + self.OBJECT_NAME)
+ + ' ' + object_file)
# TODO(stevemar): Assert returned fields
+ tmp_file = 'tmp.txt'
+ self.addCleanup(os.remove, tmp_file)
self.openstack('object save ' + self.CONTAINER_NAME
- + ' ' + self.OBJECT_NAME + ' --file ' + self.TMP_FILE)
+ + ' ' + object_file + ' --file ' + tmp_file)
# TODO(stevemar): Assert returned fields
self.openstack('object show ' + self.CONTAINER_NAME
- + ' ' + self.OBJECT_NAME)
+ + ' ' + object_file)
# TODO(stevemar): Assert returned fields
raw_output = self.openstack('object delete ' + self.CONTAINER_NAME
- + ' ' + self.OBJECT_NAME)
+ + ' ' + object_file)
self.assertEqual(0, len(raw_output))
self.openstack('object create ' + self.CONTAINER_NAME
- + ' ' + self.OBJECT_NAME)
+ + ' ' + object_file)
raw_output = self.openstack('container delete -r ' +
self.CONTAINER_NAME)
self.assertEqual(0, len(raw_output))