How to use register_new_workspace method in tempest

Best Python code snippet using tempest_python

test_workspace.py

Source:test_workspace.py Github

copy

Full Screen

...33 self.addCleanup(shutil.rmtree, store_dir, ignore_errors=True)34 self.store_file = os.path.join(store_dir, 'workspace.yaml')35 self.workspace_manager = workspace.WorkspaceManager(36 path=self.store_file)37 self.workspace_manager.register_new_workspace(self.name, self.path)38class TestTempestWorkspace(TestTempestWorkspaceBase):39 def _run_cmd_gets_return_code(self, cmd, expected):40 process = subprocess.Popen(cmd, stdout=subprocess.PIPE,41 stderr=subprocess.PIPE)42 stdout, stderr = process.communicate()43 return_code = process.returncode44 msg = ("%s failed with:\nstdout: %s\nstderr: %s" % (' '.join(cmd),45 stdout, stderr))46 self.assertEqual(return_code, expected, msg)47 def test_run_workspace_list(self):48 cmd = ['tempest', 'workspace', 'list',49 '--workspace-path', self.store_file]50 self._run_cmd_gets_return_code(cmd, 0)51 def test_run_workspace_register(self):52 name = data_utils.rand_uuid()53 path = tempfile.mkdtemp()54 self.addCleanup(shutil.rmtree, path, ignore_errors=True)55 cmd = ['tempest', 'workspace', 'register',56 '--workspace-path', self.store_file,57 '--name', name, '--path', path]58 self._run_cmd_gets_return_code(cmd, 0)59 self.assertIsNotNone(self.workspace_manager.get_workspace(name))60 def test_run_workspace_rename(self):61 new_name = data_utils.rand_uuid()62 cmd = ['tempest', 'workspace', 'rename',63 '--workspace-path', self.store_file,64 '--old-name', self.name, '--new-name', new_name]65 self._run_cmd_gets_return_code(cmd, 0)66 self.assertIsNone(self.workspace_manager.get_workspace(self.name))67 self.assertIsNotNone(self.workspace_manager.get_workspace(new_name))68 def test_run_workspace_move(self):69 new_path = tempfile.mkdtemp()70 self.addCleanup(shutil.rmtree, new_path, ignore_errors=True)71 cmd = ['tempest', 'workspace', 'move',72 '--workspace-path', self.store_file,73 '--name', self.name, '--path', new_path]74 self._run_cmd_gets_return_code(cmd, 0)75 self.assertEqual(76 self.workspace_manager.get_workspace(self.name), new_path)77 def test_run_workspace_remove_entry(self):78 cmd = ['tempest', 'workspace', 'remove',79 '--workspace-path', self.store_file,80 '--name', self.name]81 self._run_cmd_gets_return_code(cmd, 0)82 self.assertIsNone(self.workspace_manager.get_workspace(self.name))83 def test_run_workspace_remove_directory(self):84 cmd = ['tempest', 'workspace', 'remove',85 '--workspace-path', self.store_file,86 '--name', self.name, '--rmdir']87 self._run_cmd_gets_return_code(cmd, 0)88 self.assertIsNone(self.workspace_manager.get_workspace(self.name))89class TestTempestWorkspaceManager(TestTempestWorkspaceBase):90 def setUp(self):91 super(TestTempestWorkspaceManager, self).setUp()92 self.name = data_utils.rand_uuid()93 self.path = tempfile.mkdtemp()94 self.addCleanup(shutil.rmtree, self.path, ignore_errors=True)95 store_dir = tempfile.mkdtemp()96 self.addCleanup(shutil.rmtree, store_dir, ignore_errors=True)97 self.store_file = os.path.join(store_dir, 'workspace.yaml')98 self.workspace_manager = workspace.WorkspaceManager(99 path=self.store_file)100 self.workspace_manager.register_new_workspace(self.name, self.path)101 def test_workspace_manager_get(self):102 self.assertIsNotNone(self.workspace_manager.get_workspace(self.name))103 def test_workspace_manager_rename(self):104 new_name = data_utils.rand_uuid()105 self.workspace_manager.rename_workspace(self.name, new_name)106 self.assertIsNone(self.workspace_manager.get_workspace(self.name))107 self.assertIsNotNone(self.workspace_manager.get_workspace(new_name))108 def test_workspace_manager_rename_no_name_exist(self):109 no_name = ""110 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:111 ex = self.assertRaises(SystemExit,112 self.workspace_manager.rename_workspace,113 self.name, no_name)114 self.assertEqual(1, ex.code)115 self.assertEqual(mock_stdout.getvalue(),116 "None or empty name is specified."117 " Please specify correct name for workspace.\n")118 def test_workspace_manager_rename_with_existing_name(self):119 new_name = self.name120 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:121 ex = self.assertRaises(SystemExit,122 self.workspace_manager.rename_workspace,123 self.name, new_name)124 self.assertEqual(1, ex.code)125 self.assertEqual(mock_stdout.getvalue(),126 "A workspace already exists with name: %s.\n"127 % new_name)128 def test_workspace_manager_rename_no_exist_old_name(self):129 old_name = ""130 new_name = data_utils.rand_uuid()131 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:132 ex = self.assertRaises(SystemExit,133 self.workspace_manager.rename_workspace,134 old_name, new_name)135 self.assertEqual(1, ex.code)136 self.assertEqual(mock_stdout.getvalue(),137 "A workspace was not found with name: %s\n"138 % old_name)139 def test_workspace_manager_rename_integer_data(self):140 old_name = self.name141 new_name = 12345142 self.workspace_manager.rename_workspace(old_name, new_name)143 self.assertIsNone(self.workspace_manager.get_workspace(old_name))144 self.assertIsNotNone(self.workspace_manager.get_workspace(new_name))145 def test_workspace_manager_rename_alphanumeric_data(self):146 old_name = self.name147 new_name = 'abc123'148 self.workspace_manager.rename_workspace(old_name, new_name)149 self.assertIsNone(self.workspace_manager.get_workspace(old_name))150 self.assertIsNotNone(self.workspace_manager.get_workspace(new_name))151 def test_workspace_manager_move(self):152 new_path = tempfile.mkdtemp()153 self.addCleanup(shutil.rmtree, new_path, ignore_errors=True)154 self.workspace_manager.move_workspace(self.name, new_path)155 self.assertEqual(156 self.workspace_manager.get_workspace(self.name), new_path)157 # NOTE(mbindlish): Also checking for the workspace that it158 # shouldn't exist in old path159 self.assertNotEqual(160 self.workspace_manager.get_workspace(self.name), self.path)161 def test_workspace_manager_move_wrong_path(self):162 new_path = 'wrong/path'163 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:164 ex = self.assertRaises(SystemExit,165 self.workspace_manager.move_workspace,166 self.name, new_path)167 self.assertEqual(1, ex.code)168 self.assertEqual(mock_stdout.getvalue(),169 "Path does not exist.\n")170 def test_workspace_manager_move_wrong_workspace(self):171 workspace_name = "wrong_workspace_name"172 new_path = tempfile.mkdtemp()173 self.addCleanup(shutil.rmtree, new_path, ignore_errors=True)174 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:175 ex = self.assertRaises(SystemExit,176 self.workspace_manager.move_workspace,177 workspace_name, new_path)178 self.assertEqual(1, ex.code)179 self.assertEqual(mock_stdout.getvalue(),180 "A workspace was not found with name: %s\n"181 % workspace_name)182 def test_workspace_manager_move_no_workspace_name(self):183 workspace_name = ""184 new_path = tempfile.mkdtemp()185 self.addCleanup(shutil.rmtree, new_path, ignore_errors=True)186 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:187 ex = self.assertRaises(SystemExit,188 self.workspace_manager.move_workspace,189 workspace_name, new_path)190 self.assertEqual(1, ex.code)191 self.assertEqual(mock_stdout.getvalue(),192 "A workspace was not found with name: %s\n"193 % workspace_name)194 def test_workspace_manager_move_no_workspace_path(self):195 new_path = ""196 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:197 ex = self.assertRaises(SystemExit,198 self.workspace_manager.move_workspace,199 self.name, new_path)200 self.assertEqual(1, ex.code)201 self.assertEqual(mock_stdout.getvalue(),202 "None or empty path is specified for workspace."203 " Please specify correct workspace path.\n")204 def test_workspace_manager_remove_entry(self):205 self.workspace_manager.remove_workspace_entry(self.name)206 self.assertIsNone(self.workspace_manager.get_workspace(self.name))207 def test_workspace_manager_remove_entry_no_name(self):208 no_name = ""209 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:210 ex = self.assertRaises(SystemExit,211 self.workspace_manager.212 remove_workspace_entry,213 no_name)214 self.assertEqual(1, ex.code)215 self.assertEqual(mock_stdout.getvalue(),216 "A workspace was not found with name: %s\n"217 % no_name)218 def test_workspace_manager_remove_entry_wrong_name(self):219 wrong_name = "wrong_name"220 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:221 ex = self.assertRaises(SystemExit,222 self.workspace_manager.223 remove_workspace_entry,224 wrong_name)225 self.assertEqual(1, ex.code)226 self.assertEqual(mock_stdout.getvalue(),227 "A workspace was not found with name: %s\n"228 % wrong_name)229 def test_workspace_manager_remove_directory(self):230 path = self.workspace_manager.remove_workspace_entry(self.name)231 self.workspace_manager.remove_workspace_directory(path)232 self.assertIsNone(self.workspace_manager.get_workspace(self.name))233 def test_workspace_manager_remove_directory_no_path(self):234 no_path = ""235 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:236 ex = self.assertRaises(SystemExit,237 self.workspace_manager.238 remove_workspace_directory,239 no_path)240 self.assertEqual(1, ex.code)241 self.assertEqual(mock_stdout.getvalue(),242 "None or empty path is specified for workspace."243 " Please specify correct workspace path.\n")244 def test_path_expansion(self):245 name = data_utils.rand_uuid()246 path = os.path.join("~", name)247 os.makedirs(os.path.expanduser(path))248 self.addCleanup(shutil.rmtree, path, ignore_errors=True)249 self.workspace_manager.register_new_workspace(name, path)250 self.assertIsNotNone(self.workspace_manager.get_workspace(name))251 def test_workspace_name_not_exists(self):252 nonexistent_name = data_utils.rand_uuid()253 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:254 ex = self.assertRaises(SystemExit,255 self.workspace_manager._name_exists,256 nonexistent_name)257 self.assertEqual(1, ex.code)258 self.assertEqual(mock_stdout.getvalue(),259 "A workspace was not found with name: %s\n"260 % nonexistent_name)261 def test_workspace_name_exists(self):262 self.assertIsNone(self.workspace_manager._name_exists(self.name))263 def test_workspace_name_already_exists(self):264 duplicate_name = self.name265 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:266 ex = self.assertRaises(SystemExit,267 self.workspace_manager.268 _workspace_name_exists,269 duplicate_name)270 self.assertEqual(1, ex.code)271 self.assertEqual(mock_stdout.getvalue(),272 "A workspace already exists with name: %s.\n"273 % duplicate_name)274 def test_workspace_name_exists_check_new_name(self):275 new_name = "fake_name"276 self.assertIsNone(self.workspace_manager.277 _workspace_name_exists(new_name))278 def test_workspace_manager_path_not_exist(self):279 fake_path = "fake_path"280 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:281 ex = self.assertRaises(SystemExit,282 self.workspace_manager._validate_path,283 fake_path)284 self.assertEqual(1, ex.code)285 self.assertEqual(mock_stdout.getvalue(),286 "Path does not exist.\n")287 def test_validate_path_exists(self):288 new_path = self.path289 self.assertIsNone(self.workspace_manager.290 _validate_path(new_path))291 def test_workspace_manager_list_workspaces(self):292 listed = self.workspace_manager.list_workspaces()293 self.assertEqual(1, len(listed))294 self.assertIn(self.name, listed)295 self.assertEqual(self.path, listed.get(self.name))296 def test_register_new_workspace_no_name(self):297 no_name = ""298 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:299 ex = self.assertRaises(SystemExit,300 self.workspace_manager.301 register_new_workspace,302 no_name, self.path)303 self.assertEqual(1, ex.code)304 self.assertEqual(mock_stdout.getvalue(),305 "None or empty name is specified."306 " Please specify correct name for workspace.\n")307 def test_register_new_workspace_no_path(self):308 no_path = ""309 with patch('sys.stdout', new_callable=StringIO) as mock_stdout:310 ex = self.assertRaises(SystemExit,311 self.workspace_manager.312 register_new_workspace,313 self.name, no_path)314 self.assertEqual(1, ex.code)315 self.assertEqual(mock_stdout.getvalue(),316 "None or empty path is specified for workspace."317 " Please specify correct workspace path.\n")318 def test_register_new_workspace_integer_data(self):319 workspace_name = 12345320 self.workspace_manager.register_new_workspace(321 workspace_name, self.path)322 self.assertIsNotNone(323 self.workspace_manager.get_workspace(workspace_name))324 self.assertEqual(325 self.workspace_manager.get_workspace(workspace_name), self.path)326 def test_register_new_workspace_alphanumeric_data(self):327 workspace_name = 'abc123'328 self.workspace_manager.register_new_workspace(329 workspace_name, self.path)330 self.assertIsNotNone(331 self.workspace_manager.get_workspace(workspace_name))332 self.assertEqual(...

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