Make test_revoke_cert_project_not_found_chdir_fails deterministic

Commit b64cebe2eb removed the mock on
os.chdir to always fail with OSError in the test.

The revoke_cert method is using the ca_folder method to get the path and
that checks CONF.use_project_ca which is by default False, so the
project_id isn't even used in the path we're changing to before running
the command, it just uses the global static CONF.ca_path.  If that path
exists when this test runs, os.chdir won't raise OSError and the
assertion in the test will fail.

This change makes the test deterministic by (1) setting
use_project_ca=True and (2) using a random project_id uuid.

Closes-Bug: #1495547

Change-Id: I0dc6574b6644aa09028a07503a3d0b82e68e69d2
This commit is contained in:
Matt Riedemann 2015-09-14 09:04:51 -07:00
parent ad38851d31
commit f8f822afaf
1 changed files with 3 additions and 1 deletions

View File

@ -17,6 +17,7 @@ Tests for Crypto module.
"""
import os
import uuid
from cryptography.hazmat import backends
from cryptography.hazmat.primitives import serialization
@ -164,8 +165,9 @@ class RevokeCertsTest(test.TestCase):
2, 'test_file')
def test_revoke_cert_project_not_found_chdir_fails(self, *args, **kargs):
self.flags(use_project_ca=True)
self.assertRaises(exception.ProjectNotFound, crypto.revoke_cert,
2, 'test_file')
str(uuid.uuid4()), 'test_file')
class CertExceptionTests(test.TestCase):