How to use get_workspace method in tempest

Best Python code snippet using tempest_python

test_workspace.py

Source:test_workspace.py Github

copy

Full Screen

...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

views.py

Source:views.py Github

copy

Full Screen

...30 return queryset31 def perform_create(self, serializer):32 serializer.save(owner_id=self.request.user.id)33class BaseWorkspaceMixin:34 def get_workspace(self):35 if self.request.method == 'GET':36 workspace = Workspace.objects.filter(id=self.kwargs.get('w_id')).filter(37 Q(members__in=[self.request.user]) | Q(owner=self.request.user)).first()38 else:39 workspace = Workspace.objects.filter(id=self.kwargs.get('w_id')).filter(owner=self.request.user).first()40 if workspace:41 return workspace42 else:43 raise PermissionDenied()44class WorkspaceDetailView(RetrieveUpdateDestroyAPIView, BaseWorkspaceMixin):45 parser_classes = [MultiPartParser]46 permission_classes = [IsAuthenticated]47 queryset = Workspace.objects.all()48 serializer_class = serializers.WorkspaceDetailSerializer49 def get_object(self):50 return self.get_workspace()51class WorkspaceMembersListCreateView(ListAPIView, BaseWorkspaceMixin):52 parser_classes = [JSONParser]53 permission_classes = [IsAuthenticated]54 queryset = User.objects.all()55 serializer_class = UserSerializer56 def filter_queryset(self, queryset):57 return queryset.filter(workspaces_as_member__in=[self.get_workspace()])58 def post(self, request, *args, **kwargs):59 workspace = self.get_workspace()60 try:61 workspace.members.add(request.data.get('user_id'))62 except IntegrityError:63 return Response(status=status.HTTP_404_NOT_FOUND)64 return Response(status=status.HTTP_201_CREATED)65class RemoveMemberFromWorkspaceView(APIView, BaseWorkspaceMixin):66 permission_classes = [IsAuthenticated]67 def delete(self, request, *args, **kwargs):68 workspace = self.get_workspace()69 workspace.members.remove(self.kwargs.get('u_id'))70 return Response(status=status.HTTP_204_NO_CONTENT)71class WorkspaceBoardsListView(ListAPIView, BaseWorkspaceMixin):72 permission_classes = [IsAuthenticated]73 queryset = Board.objects.all()74 serializer_class = BoardsListSerializer75 def filter_queryset(self, queryset):76 return queryset.filter(workspace=self.get_workspace())77@api_view(["GET"])78def load_test(request, query_count):79 datas = []80 for i in range(query_count):81 datas.append(serializers.WorkspaceListSerializer(Workspace.objects.all(), many=True).data)...

Full Screen

Full Screen

asana.py

Source:asana.py Github

copy

Full Screen

2from django.conf import settings3class Asana:4 def _client(self):5 return asana.Client.access_token(settings.PERSONAL_ACCESS_TOKEN)6 def get_workspace(self):7 return self._client().users.me()['workspaces'][0]['gid']8 def get_project_by_id(self, project_id):9 return self._client().projects.find_by_id(project_id)10 def create_project(self, title):11 return self._client().projects.create_in_workspace(self.get_workspace(), {'name': title})12 def update_project(self, project_id, title):13 return self._client().projects.update(project_id, {'name': title})14 def get_all_projects(self):15 return list(self._client().projects.find_all({'workspace': self.get_workspace()}))16 def create_task(self, projects_ids, title, executor_id=None, description=None):17 return self._client().tasks.create_in_workspace(18 self.get_workspace(),19 {20 'projects': projects_ids,21 'name': title,22 'assignee': executor_id,23 'notes': description24 }25 )26 def update_task(self, task_id, title, executor_id=None, description=None):27 return self._client().tasks.update(28 task_id,29 {30 'name': title,31 'assignee': executor_id,32 'notes': description33 }34 )35 def get_tasks_by_project(self, project_id):36 return list(self._client().tasks.find_all({'project': project_id}))37 def add_task_to_project(self, task_id, project_id):38 return self._client().tasks.add_project(task_id, {'project': project_id})39 def get_task_by_id(self, task_id):40 return self._client().tasks.find_by_id(task_id)41 def get_all_users(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