|
6 | 6 | # You may obtain a copy of the License at |
7 | 7 | # |
8 | 8 | # http://www.datastax.com/terms/datastax-dse-driver-license-terms |
| 9 | +import tempfile |
| 10 | +import os |
| 11 | +import shutil |
| 12 | +import six |
| 13 | + |
9 | 14 | try: |
10 | 15 | import unittest2 as unittest |
11 | 16 | except ImportError: |
12 | 17 | import unittest # noqa |
13 | 18 |
|
14 | | -import os |
15 | | - |
| 19 | +from cassandra import DriverException |
16 | 20 | from cassandra.datastax import cloud |
17 | 21 |
|
18 | 22 | from mock import patch |
19 | 23 |
|
| 24 | +from tests import notwindows |
20 | 25 |
|
21 | 26 | class CloudTests(unittest.TestCase): |
22 | 27 |
|
23 | 28 | current_path = os.path.dirname(os.path.abspath(__file__)) |
| 29 | + creds_path = os.path.join(current_path, './creds.zip') |
24 | 30 | config_zip = { |
25 | | - 'secure_connect_bundle': os.path.join(current_path, './creds.zip') |
| 31 | + 'secure_connect_bundle': creds_path |
26 | 32 | } |
27 | 33 | metadata_json = """ |
28 | 34 | {"region":"local", |
@@ -75,3 +81,33 @@ def test_parse_metadata_info(self): |
75 | 81 | ] |
76 | 82 | for host_id in host_ids: |
77 | 83 | self.assertIn(host_id, config.host_ids) |
| 84 | + |
| 85 | + @notwindows |
| 86 | + def test_use_default_tempdir(self): |
| 87 | + tmpdir = tempfile.mkdtemp() |
| 88 | + |
| 89 | + def clean_tmp_dir(): |
| 90 | + os.chmod(tmpdir, 0o777) |
| 91 | + shutil.rmtree(tmpdir) |
| 92 | + self.addCleanup(clean_tmp_dir) |
| 93 | + |
| 94 | + tmp_creds_path = os.path.join(tmpdir, 'creds.zip') |
| 95 | + shutil.copyfile(self.creds_path, tmp_creds_path) |
| 96 | + os.chmod(tmpdir, 0o544) |
| 97 | + config = { |
| 98 | + 'secure_connect_bundle': tmp_creds_path |
| 99 | + } |
| 100 | + |
| 101 | + # The directory is not writtable.. we expect a permission error |
| 102 | + exc = PermissionError if six.PY3 else OSError |
| 103 | + with self.assertRaises(exc): |
| 104 | + cloud.get_cloud_config(config) |
| 105 | + |
| 106 | + # With use_default_tempdir, we expect an connection refused |
| 107 | + # since the cluster doesn't exist |
| 108 | + with self.assertRaises(DriverException): |
| 109 | + config = { |
| 110 | + 'secure_connect_bundle': tmp_creds_path, |
| 111 | + 'use_default_tempdir': True |
| 112 | + } |
| 113 | + cloud.get_cloud_config(config) |
0 commit comments