How to use _get_hash_list method in tempest

Best Python code snippet using tempest_python

test_accounts.py

Source:test_accounts.py Github

copy

Full Screen

...50 self.useFixture(mockpatch.Patch(51 'tempest.common.accounts.read_accounts_yaml',52 return_value=self.test_accounts))53 cfg.CONF.set_default('test_accounts_file', '', group='auth')54 def _get_hash_list(self, accounts_list):55 hash_list = []56 for account in accounts_list:57 hash = hashlib.md5()58 hash.update(str(account))59 hash_list.append(hash.hexdigest())60 return hash_list61 def test_get_hash(self):62 self.stubs.Set(http.ClosingHttp, 'request',63 fake_identity._fake_v2_response)64 test_account_class = accounts.Accounts('test_name')65 hash_list = self._get_hash_list(self.test_accounts)66 test_cred_dict = self.test_accounts[3]67 test_creds = auth.get_credentials(**test_cred_dict)68 results = test_account_class.get_hash(test_creds)69 self.assertEqual(hash_list[3], results)70 def test_get_hash_dict(self):71 test_account_class = accounts.Accounts('test_name')72 hash_dict = test_account_class.get_hash_dict(self.test_accounts)73 hash_list = self._get_hash_list(self.test_accounts)74 for hash in hash_list:75 self.assertIn(hash, hash_dict.keys())76 self.assertIn(hash_dict[hash], self.test_accounts)77 def test_create_hash_file_previous_file(self):78 # Emulate the lock existing on the filesystem79 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))80 with mock.patch('__builtin__.open', mock.mock_open(), create=True):81 test_account_class = accounts.Accounts('test_name')82 res = test_account_class._create_hash_file('12345')83 self.assertFalse(res, "_create_hash_file should return False if the "84 "pseudo-lock file already exists")85 def test_create_hash_file_no_previous_file(self):86 # Emulate the lock not existing on the filesystem87 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))88 with mock.patch('__builtin__.open', mock.mock_open(), create=True):89 test_account_class = accounts.Accounts('test_name')90 res = test_account_class._create_hash_file('12345')91 self.assertTrue(res, "_create_hash_file should return True if the "92 "pseudo-lock doesn't already exist")93 @mock.patch('tempest.openstack.common.lockutils.lock')94 def test_get_free_hash_no_previous_accounts(self, lock_mock):95 # Emulate no pre-existing lock96 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=False))97 hash_list = self._get_hash_list(self.test_accounts)98 mkdir_mock = self.useFixture(mockpatch.Patch('os.mkdir'))99 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=False))100 test_account_class = accounts.Accounts('test_name')101 with mock.patch('__builtin__.open', mock.mock_open(),102 create=True) as open_mock:103 test_account_class._get_free_hash(hash_list)104 lock_path = os.path.join(accounts.CONF.lock_path, 'test_accounts',105 hash_list[0])106 open_mock.assert_called_once_with(lock_path, 'w')107 mkdir_path = os.path.join(accounts.CONF.lock_path, 'test_accounts')108 mkdir_mock.mock.assert_called_once_with(mkdir_path)109 @mock.patch('tempest.openstack.common.lockutils.lock')110 def test_get_free_hash_no_free_accounts(self, lock_mock):111 hash_list = self._get_hash_list(self.test_accounts)112 # Emulate pre-existing lock dir113 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))114 # Emulate all lcoks in list are in use115 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))116 test_account_class = accounts.Accounts('test_name')117 self.assertRaises(exceptions.InvalidConfiguration,118 test_account_class._get_free_hash, hash_list)119 @mock.patch('tempest.openstack.common.lockutils.lock')120 def test_get_free_hash_some_in_use_accounts(self, lock_mock):121 # Emulate no pre-existing lock122 self.useFixture(mockpatch.Patch('os.path.isdir', return_value=True))123 hash_list = self._get_hash_list(self.test_accounts)124 test_account_class = accounts.Accounts('test_name')125 def _fake_is_file(path):126 # Fake isfile() to return that the path exists unless a specific127 # hash is in the path128 if hash_list[3] in path:129 return False130 return True131 self.stubs.Set(os.path, 'isfile', _fake_is_file)132 with mock.patch('__builtin__.open', mock.mock_open(),133 create=True) as open_mock:134 test_account_class._get_free_hash(hash_list)135 lock_path = os.path.join(accounts.CONF.lock_path, 'test_accounts',136 hash_list[3])137 open_mock.assert_called_once_with(lock_path, 'w')138 @mock.patch('tempest.openstack.common.lockutils.lock')139 def test_remove_hash_last_account(self, lock_mock):140 hash_list = self._get_hash_list(self.test_accounts)141 # Pretend the pseudo-lock is there142 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))143 # Pretend the lock dir is empty144 self.useFixture(mockpatch.Patch('os.listdir', return_value=[]))145 test_account_class = accounts.Accounts('test_name')146 remove_mock = self.useFixture(mockpatch.Patch('os.remove'))147 rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))148 test_account_class.remove_hash(hash_list[2])149 hash_path = os.path.join(accounts.CONF.lock_path, 'test_accounts',150 hash_list[2])151 lock_path = os.path.join(accounts.CONF.lock_path, 'test_accounts')152 remove_mock.mock.assert_called_once_with(hash_path)153 rmdir_mock.mock.assert_called_once_with(lock_path)154 @mock.patch('tempest.openstack.common.lockutils.lock')155 def test_remove_hash_not_last_account(self, lock_mock):156 hash_list = self._get_hash_list(self.test_accounts)157 # Pretend the pseudo-lock is there158 self.useFixture(mockpatch.Patch('os.path.isfile', return_value=True))159 # Pretend the lock dir is empty160 self.useFixture(mockpatch.Patch('os.listdir', return_value=[161 hash_list[1], hash_list[4]]))162 test_account_class = accounts.Accounts('test_name')163 remove_mock = self.useFixture(mockpatch.Patch('os.remove'))164 rmdir_mock = self.useFixture(mockpatch.Patch('os.rmdir'))165 test_account_class.remove_hash(hash_list[2])166 hash_path = os.path.join(accounts.CONF.lock_path, 'test_accounts',167 hash_list[2])168 remove_mock.mock.assert_called_once_with(hash_path)169 rmdir_mock.mock.assert_not_called()170 def test_is_multi_user(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful