]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Simplify cxt test_create_export() unit test
authorAnish Bhatt <anish@chelsio.com>
Wed, 25 Feb 2015 00:14:35 +0000 (16:14 -0800)
committerAnish Bhatt <anish@chelsio.com>
Wed, 4 Mar 2015 23:54:52 +0000 (15:54 -0800)
Reduce the amount of mocking required by returning a chap tuple directly
by mocking _get_target_chap_auth() instead of mocking generate_username and
generate_password inside _get_target_chap_auth()

Change-Id: I1e6f6c0a538cf3f0be90f8f471522cfe60321a1d

cinder/tests/targets/test_cxt_driver.py

index e62af497c34251468487ac0a1cd643268c0bc9f7..bf495554f0af59498439cbc1d156c6e2dff9ef7d 100644 (file)
@@ -172,13 +172,12 @@ class TestCxtAdmDriver(test.TestCase):
     @mock.patch('cinder.volume.targets.cxt.CxtAdm._get_target',
                 return_value=1)
     @mock.patch('cinder.utils.execute')
-    @mock.patch('cinder.volume.utils.generate_password',
-                return_value="P68eE7u9eFqDGexd28DQ")
-    @mock.patch('cinder.volume.utils.generate_username',
-                return_value="QZJbisGmn9AL954FNF4D")
-    def test_create_export(self, mock_user, mock_pass, mock_execute,
+    @mock.patch.object(cxt.CxtAdm, '_get_target_chap_auth')
+    def test_create_export(self, mock_chap, mock_execute,
                            mock_get_targ):
         mock_execute.return_value = ('', '')
+        mock_chap.return_value = ('QZJbisGmn9AL954FNF4D',
+                                  'P68eE7u9eFqDGexd28DQ')
         with mock.patch.object(self.target, '_get_volumes_dir') as mock_get:
             mock_get.return_value = self.fake_volumes_dir