| Total Complexity | 101 | 
| Total Lines | 4372 | 
| Duplicated Lines | 46.68 % | 
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like backend.tracim_backend.tests.functional.test_workspaces often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | """ | ||
| 3 | Tests for /api/v2/workspaces subpath endpoints. | ||
| 4 | """ | ||
| 5 | import requests | ||
| 6 | import transaction | ||
| 7 | from depot.io.utils import FileIntent | ||
| 8 | |||
| 9 | from tracim_backend import models | ||
| 10 | from tracim_backend.app_models.contents import content_type_list | ||
| 11 | from tracim_backend import error | ||
| 12 | from tracim_backend.extensions import app_list | ||
| 13 | from tracim_backend.fixtures.content import Content as ContentFixtures | ||
| 14 | from tracim_backend.fixtures.users_and_groups import Base as BaseFixture | ||
| 15 | from tracim_backend.lib.core.application import ApplicationApi | ||
| 16 | from tracim_backend.lib.core.content import ContentApi | ||
| 17 | from tracim_backend.lib.core.group import GroupApi | ||
| 18 | from tracim_backend.lib.core.user import UserApi | ||
| 19 | from tracim_backend.lib.core.userworkspace import RoleApi | ||
| 20 | from tracim_backend.lib.core.workspace import WorkspaceApi | ||
| 21 | from tracim_backend.models import get_tm_session | ||
| 22 | from tracim_backend.models.data import UserRoleInWorkspace | ||
| 23 | from tracim_backend.models.revision_protection import new_revision | ||
| 24 | from tracim_backend.tests import FunctionalTest | ||
| 25 | from tracim_backend.tests import set_html_document_slug_to_legacy | ||
| 26 | |||
| 27 | |||
| 28 | class TestWorkspaceEndpoint(FunctionalTest): | ||
| 29 | """ | ||
| 30 |     Tests for /api/v2/workspaces/{workspace_id} endpoint | ||
| 31 | """ | ||
| 32 | |||
| 33 | fixtures = [BaseFixture, ContentFixtures] | ||
| 34 | |||
| 35 | def test_api__get_workspace__ok_200__nominal_case(self) -> None: | ||
| 36 | """ | ||
| 37 | Check obtain workspace reachable for user. | ||
| 38 | """ | ||
| 39 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 40 | admin = dbsession.query(models.User) \ | ||
| 41 | .filter(models.User.email == '[email protected]') \ | ||
| 42 | .one() | ||
| 43 | uapi = UserApi( | ||
| 44 | current_user=admin, | ||
| 45 | session=dbsession, | ||
| 46 | config=self.app_config, | ||
| 47 | ) | ||
| 48 | gapi = GroupApi( | ||
| 49 | current_user=admin, | ||
| 50 | session=dbsession, | ||
| 51 | config=self.app_config, | ||
| 52 | ) | ||
| 53 |         groups = [gapi.get_one_with_name('users')] | ||
| 54 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 55 | workspace_api = WorkspaceApi( | ||
| 56 | current_user=admin, | ||
| 57 | session=dbsession, | ||
| 58 | config=self.app_config, | ||
| 59 | show_deleted=True, | ||
| 60 | ) | ||
| 61 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 62 | rapi = RoleApi( | ||
| 63 | current_user=admin, | ||
| 64 | session=dbsession, | ||
| 65 | config=self.app_config, | ||
| 66 | ) | ||
| 67 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 68 | workspace_api = WorkspaceApi( | ||
| 69 | session=dbsession, | ||
| 70 | current_user=admin, | ||
| 71 | config=self.app_config, | ||
| 72 | ) | ||
| 73 | workspace = workspace_api.get_one(workspace.workspace_id) | ||
| 74 | app_api = ApplicationApi( | ||
| 75 | app_list | ||
| 76 | ) | ||
| 77 | default_sidebar_entry = app_api.get_default_workspace_menu_entry(workspace=workspace) # nope8 | ||
| 78 | transaction.commit() | ||
| 79 | |||
| 80 | self.testapp.authorization = ( | ||
| 81 | 'Basic', | ||
| 82 | ( | ||
| 83 | '[email protected]', | ||
| 84 | '[email protected]' | ||
| 85 | ) | ||
| 86 | ) | ||
| 87 |         res = self.testapp.get('/api/v2/workspaces/{}'.format(workspace.workspace_id), status=200) | ||
| 88 | workspace_dict = res.json_body | ||
| 89 | assert workspace_dict['workspace_id'] == workspace.workspace_id | ||
| 90 | assert workspace_dict['label'] == workspace.label | ||
| 91 | assert workspace_dict['description'] == workspace.description | ||
| 92 | assert workspace_dict['is_deleted'] is False | ||
| 93 | |||
| 94 | assert len(workspace_dict['sidebar_entries']) == len(default_sidebar_entry) | ||
| 95 | for counter, sidebar_entry in enumerate(default_sidebar_entry): | ||
| 96 | workspace_dict['sidebar_entries'][counter]['slug'] = sidebar_entry.slug | ||
| 97 | workspace_dict['sidebar_entries'][counter]['label'] = sidebar_entry.label | ||
| 98 | workspace_dict['sidebar_entries'][counter]['route'] = sidebar_entry.route | ||
| 99 | workspace_dict['sidebar_entries'][counter]['hexcolor'] = sidebar_entry.hexcolor # nopep8 | ||
| 100 | workspace_dict['sidebar_entries'][counter]['fa_icon'] = sidebar_entry.fa_icon # nopep8 | ||
| 101 | |||
| 102 | def test_api__get_workspace__ok_200__admin_and_not_in_workspace(self) -> None: | ||
| 103 | """ | ||
| 104 | Check obtain workspace reachable for user. | ||
| 105 | """ | ||
| 106 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 107 | admin = dbsession.query(models.User) \ | ||
| 108 | .filter(models.User.email == '[email protected]') \ | ||
| 109 | .one() | ||
| 110 | uapi = UserApi( | ||
| 111 | current_user=admin, | ||
| 112 | session=dbsession, | ||
| 113 | config=self.app_config, | ||
| 114 | ) | ||
| 115 | gapi = GroupApi( | ||
| 116 | current_user=admin, | ||
| 117 | session=dbsession, | ||
| 118 | config=self.app_config, | ||
| 119 | ) | ||
| 120 |         groups = [gapi.get_one_with_name('users')] | ||
| 121 | workspace_api = WorkspaceApi( | ||
| 122 | current_user=admin, | ||
| 123 | session=dbsession, | ||
| 124 | config=self.app_config, | ||
| 125 | show_deleted=True, | ||
| 126 | ) | ||
| 127 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 128 | rapi = RoleApi( | ||
| 129 | current_user=None, | ||
| 130 | session=dbsession, | ||
| 131 | config=self.app_config, | ||
| 132 | ) | ||
| 133 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 134 | workspace_api = WorkspaceApi( | ||
| 135 | session=dbsession, | ||
| 136 | current_user=admin, | ||
| 137 | config=self.app_config, | ||
| 138 | ) | ||
| 139 | workspace = workspace_api.get_one(workspace.workspace_id) | ||
| 140 | app_api = ApplicationApi( | ||
| 141 | app_list | ||
| 142 | ) | ||
| 143 | default_sidebar_entry = app_api.get_default_workspace_menu_entry(workspace=workspace) # nope8 | ||
| 144 | transaction.commit() | ||
| 145 | |||
| 146 | self.testapp.authorization = ( | ||
| 147 | 'Basic', | ||
| 148 | ( | ||
| 149 | '[email protected]', | ||
| 150 | '[email protected]' | ||
| 151 | ) | ||
| 152 | ) | ||
| 153 |         res = self.testapp.get('/api/v2/workspaces/{}'.format(workspace.workspace_id), status=200) | ||
| 154 | workspace_dict = res.json_body | ||
| 155 | assert workspace_dict['workspace_id'] == workspace.workspace_id | ||
| 156 | assert workspace_dict['label'] == workspace.label | ||
| 157 | assert workspace_dict['description'] == workspace.description | ||
| 158 | assert workspace_dict['is_deleted'] is False | ||
| 159 | |||
| 160 | assert len(workspace_dict['sidebar_entries']) == len(default_sidebar_entry) | ||
| 161 | for counter, sidebar_entry in enumerate(default_sidebar_entry): | ||
| 162 | workspace_dict['sidebar_entries'][counter]['slug'] = sidebar_entry.slug | ||
| 163 | workspace_dict['sidebar_entries'][counter]['label'] = sidebar_entry.label | ||
| 164 | workspace_dict['sidebar_entries'][counter]['route'] = sidebar_entry.route | ||
| 165 | workspace_dict['sidebar_entries'][counter]['hexcolor'] = sidebar_entry.hexcolor # nopep8 | ||
| 166 | workspace_dict['sidebar_entries'][counter]['fa_icon'] = sidebar_entry.fa_icon # nopep8 | ||
| 167 | |||
| 168 | def test_api__update_workspace__ok_200__nominal_case(self) -> None: | ||
| 169 | """ | ||
| 170 | Test update workspace | ||
| 171 | """ | ||
| 172 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 173 | admin = dbsession.query(models.User) \ | ||
| 174 | .filter(models.User.email == '[email protected]') \ | ||
| 175 | .one() | ||
| 176 | |||
| 177 | workspace_api = WorkspaceApi( | ||
| 178 | session=dbsession, | ||
| 179 | current_user=admin, | ||
| 180 | config=self.app_config, | ||
| 181 | ) | ||
| 182 | workspace = workspace_api.get_one(1) | ||
| 183 | app_api = ApplicationApi( | ||
| 184 | app_list | ||
| 185 | ) | ||
| 186 | default_sidebar_entry = app_api.get_default_workspace_menu_entry(workspace=workspace) # nope8 | ||
| 187 | |||
| 188 | self.testapp.authorization = ( | ||
| 189 | 'Basic', | ||
| 190 | ( | ||
| 191 | '[email protected]', | ||
| 192 | '[email protected]' | ||
| 193 | ) | ||
| 194 | ) | ||
| 195 |         params = { | ||
| 196 | 'label': 'superworkspace', | ||
| 197 | 'description': 'mysuperdescription' | ||
| 198 | } | ||
| 199 | # Before | ||
| 200 | res = self.testapp.get( | ||
| 201 | '/api/v2/workspaces/1', | ||
| 202 | status=200 | ||
| 203 | ) | ||
| 204 | assert res.json_body | ||
| 205 | workspace = res.json_body | ||
| 206 | assert workspace['workspace_id'] == 1 | ||
| 207 | assert workspace['slug'] == 'business' | ||
| 208 | assert workspace['label'] == 'Business' | ||
| 209 | assert workspace['description'] == 'All importants documents' | ||
| 210 | assert len(workspace['sidebar_entries']) == len(default_sidebar_entry) | ||
| 211 | assert workspace['is_deleted'] is False | ||
| 212 | |||
| 213 | # modify workspace | ||
| 214 | res = self.testapp.put_json( | ||
| 215 | '/api/v2/workspaces/1', | ||
| 216 | status=200, | ||
| 217 | params=params, | ||
| 218 | ) | ||
| 219 | assert res.json_body | ||
| 220 | workspace = res.json_body | ||
| 221 | assert workspace['workspace_id'] == 1 | ||
| 222 | assert workspace['slug'] == 'superworkspace' | ||
| 223 | assert workspace['label'] == 'superworkspace' | ||
| 224 | assert workspace['description'] == 'mysuperdescription' | ||
| 225 | assert len(workspace['sidebar_entries']) == len(default_sidebar_entry) | ||
| 226 | assert workspace['is_deleted'] is False | ||
| 227 | |||
| 228 | # after | ||
| 229 | res = self.testapp.get( | ||
| 230 | '/api/v2/workspaces/1', | ||
| 231 | status=200 | ||
| 232 | ) | ||
| 233 | assert res.json_body | ||
| 234 | workspace = res.json_body | ||
| 235 | assert workspace['workspace_id'] == 1 | ||
| 236 | assert workspace['slug'] == 'superworkspace' | ||
| 237 | assert workspace['label'] == 'superworkspace' | ||
| 238 | assert workspace['description'] == 'mysuperdescription' | ||
| 239 | assert len(workspace['sidebar_entries']) == len(default_sidebar_entry) | ||
| 240 | assert workspace['is_deleted'] is False | ||
| 241 | |||
| 242 | def test_api__update_workspace__err_400__empty_label(self) -> None: | ||
| 243 | """ | ||
| 244 | Test update workspace with empty label | ||
| 245 | """ | ||
| 246 | self.testapp.authorization = ( | ||
| 247 | 'Basic', | ||
| 248 | ( | ||
| 249 | '[email protected]', | ||
| 250 | '[email protected]' | ||
| 251 | ) | ||
| 252 | ) | ||
| 253 |         params = { | ||
| 254 | 'label': '', | ||
| 255 | 'description': 'mysuperdescription' | ||
| 256 | } | ||
| 257 | res = self.testapp.put_json( | ||
| 258 | '/api/v2/workspaces/1', | ||
| 259 | status=400, | ||
| 260 | params=params, | ||
| 261 | ) | ||
| 262 | assert isinstance(res.json, dict) | ||
| 263 | assert 'code' in res.json.keys() | ||
| 264 | assert res.json_body['code'] == error.GENERIC_SCHEMA_VALIDATION_ERROR # nopep8 | ||
| 265 | |||
| 266 | def test_api__create_workspace__ok_200__nominal_case(self) -> None: | ||
| 267 | """ | ||
| 268 | Test create workspace | ||
| 269 | """ | ||
| 270 | self.testapp.authorization = ( | ||
| 271 | 'Basic', | ||
| 272 | ( | ||
| 273 | '[email protected]', | ||
| 274 | '[email protected]' | ||
| 275 | ) | ||
| 276 | ) | ||
| 277 |         params = { | ||
| 278 | 'label': 'superworkspace', | ||
| 279 | 'description': 'mysuperdescription' | ||
| 280 | } | ||
| 281 | res = self.testapp.post_json( | ||
| 282 | '/api/v2/workspaces', | ||
| 283 | status=200, | ||
| 284 | params=params, | ||
| 285 | ) | ||
| 286 | assert res.json_body | ||
| 287 | workspace = res.json_body | ||
| 288 | workspace_id = res.json_body['workspace_id'] | ||
| 289 | res = self.testapp.get( | ||
| 290 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 291 | status=200 | ||
| 292 | ) | ||
| 293 | workspace_2 = res.json_body | ||
| 294 | assert workspace == workspace_2 | ||
| 295 | |||
| 296 | def test_api__create_workspace_err_400__label_already_used(self) -> None: | ||
| 297 | """ | ||
| 298 | Test create workspace : label already used | ||
| 299 | """ | ||
| 300 | self.testapp.authorization = ( | ||
| 301 | 'Basic', | ||
| 302 | ( | ||
| 303 | '[email protected]', | ||
| 304 | '[email protected]' | ||
| 305 | ) | ||
| 306 | ) | ||
| 307 |         params = { | ||
| 308 | 'label': 'superworkspace', | ||
| 309 | 'description': 'mysuperdescription' | ||
| 310 | } | ||
| 311 | res = self.testapp.post_json( | ||
| 312 | '/api/v2/workspaces', | ||
| 313 | status=200, | ||
| 314 | params=params, | ||
| 315 | ) | ||
| 316 | res = self.testapp.post_json( | ||
| 317 | '/api/v2/workspaces', | ||
| 318 | status=400, | ||
| 319 | params=params, | ||
| 320 | ) | ||
| 321 | assert isinstance(res.json, dict) | ||
| 322 | assert 'code' in res.json.keys() | ||
| 323 | assert res.json_body['code'] == error.WORKSPACE_LABEL_ALREADY_USED | ||
| 324 | |||
| 325 | def test_api__create_workspace__err_400__empty_label(self) -> None: | ||
| 326 | """ | ||
| 327 | Test create workspace with empty label | ||
| 328 | """ | ||
| 329 | self.testapp.authorization = ( | ||
| 330 | 'Basic', | ||
| 331 | ( | ||
| 332 | '[email protected]', | ||
| 333 | '[email protected]' | ||
| 334 | ) | ||
| 335 | ) | ||
| 336 |         params = { | ||
| 337 | 'label': '', | ||
| 338 | 'description': 'mysuperdescription' | ||
| 339 | } | ||
| 340 | res = self.testapp.post_json( | ||
| 341 | '/api/v2/workspaces', | ||
| 342 | status=400, | ||
| 343 | params=params, | ||
| 344 | ) | ||
| 345 | assert isinstance(res.json, dict) | ||
| 346 | assert 'code' in res.json.keys() | ||
| 347 | assert res.json_body['code'] == error.GENERIC_SCHEMA_VALIDATION_ERROR # nopep8 | ||
| 348 | |||
| 349 | View Code Duplication | def test_api__delete_workspace__ok_200__admin(self) -> None: | |
|  | |||
| 350 | """ | ||
| 351 | Test delete workspace as admin | ||
| 352 | """ | ||
| 353 | self.testapp.authorization = ( | ||
| 354 | 'Basic', | ||
| 355 | ( | ||
| 356 | '[email protected]', | ||
| 357 | '[email protected]' | ||
| 358 | ) | ||
| 359 | ) | ||
| 360 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 361 | admin = dbsession.query(models.User) \ | ||
| 362 | .filter(models.User.email == '[email protected]') \ | ||
| 363 | .one() | ||
| 364 | uapi = UserApi( | ||
| 365 | current_user=admin, | ||
| 366 | session=dbsession, | ||
| 367 | config=self.app_config, | ||
| 368 | ) | ||
| 369 | gapi = GroupApi( | ||
| 370 | current_user=admin, | ||
| 371 | session=dbsession, | ||
| 372 | config=self.app_config, | ||
| 373 | ) | ||
| 374 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 375 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 376 | workspace_api = WorkspaceApi( | ||
| 377 | current_user=admin, | ||
| 378 | session=dbsession, | ||
| 379 | config=self.app_config, | ||
| 380 | show_deleted=True, | ||
| 381 | ) | ||
| 382 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 383 | transaction.commit() | ||
| 384 | workspace_id = int(workspace.workspace_id) | ||
| 385 | self.testapp.authorization = ( | ||
| 386 | 'Basic', | ||
| 387 | ( | ||
| 388 | '[email protected]', | ||
| 389 | '[email protected]' | ||
| 390 | ) | ||
| 391 | ) | ||
| 392 | # delete | ||
| 393 | res = self.testapp.put( | ||
| 394 |             '/api/v2/workspaces/{}/trashed'.format(workspace_id), | ||
| 395 | status=204 | ||
| 396 | ) | ||
| 397 | self.testapp.authorization = ( | ||
| 398 | 'Basic', | ||
| 399 | ( | ||
| 400 | '[email protected]', | ||
| 401 | '[email protected]' | ||
| 402 | ) | ||
| 403 | ) | ||
| 404 | res = self.testapp.get( | ||
| 405 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 406 | status=400 | ||
| 407 | ) | ||
| 408 | assert isinstance(res.json, dict) | ||
| 409 | assert 'code' in res.json.keys() | ||
| 410 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND # nopep8 | ||
| 411 | self.testapp.authorization = ( | ||
| 412 | 'Basic', | ||
| 413 | ( | ||
| 414 | '[email protected]', | ||
| 415 | '[email protected]' | ||
| 416 | ) | ||
| 417 | ) | ||
| 418 | res = self.testapp.get( | ||
| 419 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 420 | status=200 | ||
| 421 | ) | ||
| 422 | workspace = res.json_body | ||
| 423 | assert workspace['is_deleted'] is True | ||
| 424 | |||
| 425 | View Code Duplication | def test_api__delete_workspace__ok_200__manager_workspace_manager(self) -> None: | |
| 426 | """ | ||
| 427 | Test delete workspace as global manager and workspace manager | ||
| 428 | """ | ||
| 429 | self.testapp.authorization = ( | ||
| 430 | 'Basic', | ||
| 431 | ( | ||
| 432 | '[email protected]', | ||
| 433 | '[email protected]' | ||
| 434 | ) | ||
| 435 | ) | ||
| 436 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 437 | admin = dbsession.query(models.User) \ | ||
| 438 | .filter(models.User.email == '[email protected]') \ | ||
| 439 | .one() | ||
| 440 | uapi = UserApi( | ||
| 441 | current_user=admin, | ||
| 442 | session=dbsession, | ||
| 443 | config=self.app_config, | ||
| 444 | ) | ||
| 445 | gapi = GroupApi( | ||
| 446 | current_user=admin, | ||
| 447 | session=dbsession, | ||
| 448 | config=self.app_config, | ||
| 449 | ) | ||
| 450 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 451 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 452 | workspace_api = WorkspaceApi( | ||
| 453 | current_user=admin, | ||
| 454 | session=dbsession, | ||
| 455 | config=self.app_config, | ||
| 456 | show_deleted=True, | ||
| 457 | ) | ||
| 458 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 459 | rapi = RoleApi( | ||
| 460 | current_user=admin, | ||
| 461 | session=dbsession, | ||
| 462 | config=self.app_config, | ||
| 463 | ) | ||
| 464 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 465 | transaction.commit() | ||
| 466 | workspace_id = int(workspace.workspace_id) | ||
| 467 | self.testapp.authorization = ( | ||
| 468 | 'Basic', | ||
| 469 | ( | ||
| 470 | '[email protected]', | ||
| 471 | '[email protected]' | ||
| 472 | ) | ||
| 473 | ) | ||
| 474 | # delete | ||
| 475 | res = self.testapp.put( | ||
| 476 |             '/api/v2/workspaces/{}/trashed'.format(workspace_id), | ||
| 477 | status=204 | ||
| 478 | ) | ||
| 479 | res = self.testapp.get( | ||
| 480 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 481 | status=200 | ||
| 482 | ) | ||
| 483 | workspace = res.json_body | ||
| 484 | assert workspace['is_deleted'] is True | ||
| 485 | |||
| 486 | def test_api__delete_workspace__err_403__user_workspace_manager(self) -> None: | ||
| 487 | """ | ||
| 488 | Test delete workspace as simple user and workspace manager | ||
| 489 | """ | ||
| 490 | self.testapp.authorization = ( | ||
| 491 | 'Basic', | ||
| 492 | ( | ||
| 493 | '[email protected]', | ||
| 494 | '[email protected]' | ||
| 495 | ) | ||
| 496 | ) | ||
| 497 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 498 | admin = dbsession.query(models.User) \ | ||
| 499 | .filter(models.User.email == '[email protected]') \ | ||
| 500 | .one() | ||
| 501 | uapi = UserApi( | ||
| 502 | current_user=admin, | ||
| 503 | session=dbsession, | ||
| 504 | config=self.app_config, | ||
| 505 | ) | ||
| 506 | gapi = GroupApi( | ||
| 507 | current_user=admin, | ||
| 508 | session=dbsession, | ||
| 509 | config=self.app_config, | ||
| 510 | ) | ||
| 511 |         groups = [gapi.get_one_with_name('users')] | ||
| 512 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 513 | workspace_api = WorkspaceApi( | ||
| 514 | current_user=admin, | ||
| 515 | session=dbsession, | ||
| 516 | config=self.app_config, | ||
| 517 | show_deleted=True, | ||
| 518 | ) | ||
| 519 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 520 | rapi = RoleApi( | ||
| 521 | current_user=admin, | ||
| 522 | session=dbsession, | ||
| 523 | config=self.app_config, | ||
| 524 | ) | ||
| 525 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 526 | transaction.commit() | ||
| 527 | workspace_id = int(workspace.workspace_id) | ||
| 528 | self.testapp.authorization = ( | ||
| 529 | 'Basic', | ||
| 530 | ( | ||
| 531 | '[email protected]', | ||
| 532 | '[email protected]' | ||
| 533 | ) | ||
| 534 | ) | ||
| 535 | # delete | ||
| 536 | res = self.testapp.put( | ||
| 537 |             '/api/v2/workspaces/{}/trashed'.format(workspace_id), | ||
| 538 | status=403 | ||
| 539 | ) | ||
| 540 | assert isinstance(res.json, dict) | ||
| 541 | assert 'code' in res.json.keys() | ||
| 542 | assert res.json_body['code'] == error.INSUFFICIENT_USER_PROFILE | ||
| 543 | res = self.testapp.get( | ||
| 544 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 545 | status=200 | ||
| 546 | ) | ||
| 547 | workspace = res.json_body | ||
| 548 | assert workspace['is_deleted'] is False | ||
| 549 | |||
| 550 | View Code Duplication | def test_api__delete_workspace__err_403__manager_reader(self) -> None: | |
| 551 | """ | ||
| 552 | Test delete workspace as manager and reader of the workspace | ||
| 553 | """ | ||
| 554 | self.testapp.authorization = ( | ||
| 555 | 'Basic', | ||
| 556 | ( | ||
| 557 | '[email protected]', | ||
| 558 | '[email protected]' | ||
| 559 | ) | ||
| 560 | ) | ||
| 561 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 562 | admin = dbsession.query(models.User) \ | ||
| 563 | .filter(models.User.email == '[email protected]') \ | ||
| 564 | .one() | ||
| 565 | uapi = UserApi( | ||
| 566 | current_user=admin, | ||
| 567 | session=dbsession, | ||
| 568 | config=self.app_config, | ||
| 569 | ) | ||
| 570 | gapi = GroupApi( | ||
| 571 | current_user=admin, | ||
| 572 | session=dbsession, | ||
| 573 | config=self.app_config, | ||
| 574 | ) | ||
| 575 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 576 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False)  # nopep8 | ||
| 577 | workspace_api = WorkspaceApi( | ||
| 578 | current_user=admin, | ||
| 579 | session=dbsession, | ||
| 580 | config=self.app_config, | ||
| 581 | show_deleted=True, | ||
| 582 | ) | ||
| 583 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 584 | rapi = RoleApi( | ||
| 585 | current_user=admin, | ||
| 586 | session=dbsession, | ||
| 587 | config=self.app_config, | ||
| 588 | ) | ||
| 589 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 590 | transaction.commit() | ||
| 591 | workspace_id = int(workspace.workspace_id) | ||
| 592 | self.testapp.authorization = ( | ||
| 593 | 'Basic', | ||
| 594 | ( | ||
| 595 | '[email protected]', | ||
| 596 | '[email protected]' | ||
| 597 | ) | ||
| 598 | ) | ||
| 599 | # delete | ||
| 600 | res = self.testapp.put( | ||
| 601 |             '/api/v2/workspaces/{}/trashed'.format(workspace_id), | ||
| 602 | status=403 | ||
| 603 | ) | ||
| 604 | assert isinstance(res.json, dict) | ||
| 605 | assert 'code' in res.json.keys() | ||
| 606 | assert res.json_body['code'] == error.INSUFFICIENT_USER_PROFILE | ||
| 607 | res = self.testapp.get( | ||
| 608 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 609 | status=200 | ||
| 610 | ) | ||
| 611 | workspace = res.json_body | ||
| 612 | assert workspace['is_deleted'] is False | ||
| 613 | |||
| 614 | View Code Duplication | def test_api__delete_workspace__err_400__manager(self) -> None: | |
| 615 | """ | ||
| 616 | Test delete workspace as global manager without having any role in the | ||
| 617 | workspace | ||
| 618 | """ | ||
| 619 | self.testapp.authorization = ( | ||
| 620 | 'Basic', | ||
| 621 | ( | ||
| 622 | '[email protected]', | ||
| 623 | '[email protected]' | ||
| 624 | ) | ||
| 625 | ) | ||
| 626 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 627 | admin = dbsession.query(models.User) \ | ||
| 628 | .filter(models.User.email == '[email protected]') \ | ||
| 629 | .one() | ||
| 630 | uapi = UserApi( | ||
| 631 | current_user=admin, | ||
| 632 | session=dbsession, | ||
| 633 | config=self.app_config, | ||
| 634 | ) | ||
| 635 |         user = uapi.create_user('[email protected]', password='[email protected]', | ||
| 636 | do_save=True, do_notify=False) # nopep8 | ||
| 637 | workspace_api = WorkspaceApi( | ||
| 638 | current_user=admin, | ||
| 639 | session=dbsession, | ||
| 640 | config=self.app_config, | ||
| 641 | show_deleted=True, | ||
| 642 | ) | ||
| 643 |         workspace = workspace_api.create_workspace('test', | ||
| 644 | save_now=True) # nopep8 | ||
| 645 | rapi = RoleApi( | ||
| 646 | current_user=admin, | ||
| 647 | session=dbsession, | ||
| 648 | config=self.app_config, | ||
| 649 | ) | ||
| 650 | transaction.commit() | ||
| 651 | workspace_id = int(workspace.workspace_id) | ||
| 652 | self.testapp.authorization = ( | ||
| 653 | 'Basic', | ||
| 654 | ( | ||
| 655 | '[email protected]', | ||
| 656 | '[email protected]' | ||
| 657 | ) | ||
| 658 | ) | ||
| 659 | # delete | ||
| 660 | res = self.testapp.put( | ||
| 661 |             '/api/v2/workspaces/{}/trashed'.format(workspace_id), | ||
| 662 | status=400 | ||
| 663 | ) | ||
| 664 | assert isinstance(res.json, dict) | ||
| 665 | assert 'code' in res.json.keys() | ||
| 666 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 667 | |||
| 668 | View Code Duplication | def test_api__undelete_workspace__ok_200__admin(self) -> None: | |
| 669 | """ | ||
| 670 | Test undelete workspace as admin | ||
| 671 | """ | ||
| 672 | self.testapp.authorization = ( | ||
| 673 | 'Basic', | ||
| 674 | ( | ||
| 675 | '[email protected]', | ||
| 676 | '[email protected]' | ||
| 677 | ) | ||
| 678 | ) | ||
| 679 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 680 | admin = dbsession.query(models.User) \ | ||
| 681 | .filter(models.User.email == '[email protected]') \ | ||
| 682 | .one() | ||
| 683 | uapi = UserApi( | ||
| 684 | current_user=admin, | ||
| 685 | session=dbsession, | ||
| 686 | config=self.app_config, | ||
| 687 | ) | ||
| 688 | gapi = GroupApi( | ||
| 689 | current_user=admin, | ||
| 690 | session=dbsession, | ||
| 691 | config=self.app_config, | ||
| 692 | ) | ||
| 693 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 694 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 695 | workspace_api = WorkspaceApi( | ||
| 696 | current_user=admin, | ||
| 697 | session=dbsession, | ||
| 698 | config=self.app_config, | ||
| 699 | show_deleted=True, | ||
| 700 | ) | ||
| 701 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 702 | workspace_api.delete(workspace, flush=True) | ||
| 703 | transaction.commit() | ||
| 704 | workspace_id = int(workspace.workspace_id) | ||
| 705 | # undelete | ||
| 706 | self.testapp.authorization = ( | ||
| 707 | 'Basic', | ||
| 708 | ( | ||
| 709 | '[email protected]', | ||
| 710 | '[email protected]' | ||
| 711 | ) | ||
| 712 | ) | ||
| 713 | res = self.testapp.put( | ||
| 714 |             '/api/v2/workspaces/{}/trashed/restore'.format(workspace_id), | ||
| 715 | status=204 | ||
| 716 | ) | ||
| 717 | self.testapp.authorization = ( | ||
| 718 | 'Basic', | ||
| 719 | ( | ||
| 720 | '[email protected]', | ||
| 721 | '[email protected]' | ||
| 722 | ) | ||
| 723 | ) | ||
| 724 | res = self.testapp.get( | ||
| 725 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 726 | status=400 | ||
| 727 | ) | ||
| 728 | assert isinstance(res.json, dict) | ||
| 729 | assert 'code' in res.json.keys() | ||
| 730 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND # nopep8 | ||
| 731 | |||
| 732 | self.testapp.authorization = ( | ||
| 733 | 'Basic', | ||
| 734 | ( | ||
| 735 | '[email protected]', | ||
| 736 | '[email protected]' | ||
| 737 | ) | ||
| 738 | ) | ||
| 739 | res = self.testapp.get( | ||
| 740 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 741 | status=200 | ||
| 742 | ) | ||
| 743 | workspace = res.json_body | ||
| 744 | assert workspace['is_deleted'] is False | ||
| 745 | |||
| 746 | View Code Duplication | def test_api__undelete_workspace__ok_200__manager_workspace_manager(self) -> None: | |
| 747 | """ | ||
| 748 | Test undelete workspace as global manager and workspace manager | ||
| 749 | """ | ||
| 750 | self.testapp.authorization = ( | ||
| 751 | 'Basic', | ||
| 752 | ( | ||
| 753 | '[email protected]', | ||
| 754 | '[email protected]' | ||
| 755 | ) | ||
| 756 | ) | ||
| 757 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 758 | admin = dbsession.query(models.User) \ | ||
| 759 | .filter(models.User.email == '[email protected]') \ | ||
| 760 | .one() | ||
| 761 | uapi = UserApi( | ||
| 762 | current_user=admin, | ||
| 763 | session=dbsession, | ||
| 764 | config=self.app_config, | ||
| 765 | ) | ||
| 766 | gapi = GroupApi( | ||
| 767 | current_user=admin, | ||
| 768 | session=dbsession, | ||
| 769 | config=self.app_config, | ||
| 770 | ) | ||
| 771 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 772 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 773 | workspace_api = WorkspaceApi( | ||
| 774 | current_user=admin, | ||
| 775 | session=dbsession, | ||
| 776 | config=self.app_config, | ||
| 777 | show_deleted=True, | ||
| 778 | ) | ||
| 779 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 780 | workspace_api.delete(workspace, flush=True) | ||
| 781 | rapi = RoleApi( | ||
| 782 | current_user=admin, | ||
| 783 | session=dbsession, | ||
| 784 | config=self.app_config, | ||
| 785 | ) | ||
| 786 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 787 | transaction.commit() | ||
| 788 | workspace_id = int(workspace.workspace_id) | ||
| 789 | self.testapp.authorization = ( | ||
| 790 | 'Basic', | ||
| 791 | ( | ||
| 792 | '[email protected]', | ||
| 793 | '[email protected]' | ||
| 794 | ) | ||
| 795 | ) | ||
| 796 | # delete | ||
| 797 | res = self.testapp.put( | ||
| 798 |             '/api/v2/workspaces/{}/trashed/restore'.format(workspace_id), | ||
| 799 | status=204 | ||
| 800 | ) | ||
| 801 | res = self.testapp.get( | ||
| 802 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 803 | status=200 | ||
| 804 | ) | ||
| 805 | workspace = res.json_body | ||
| 806 | assert workspace['is_deleted'] is False | ||
| 807 | |||
| 808 | def test_api__undelete_workspace__err_403__user_workspace_manager(self) -> None: | ||
| 809 | """ | ||
| 810 | Test undelete workspace as simple user and workspace manager | ||
| 811 | """ | ||
| 812 | self.testapp.authorization = ( | ||
| 813 | 'Basic', | ||
| 814 | ( | ||
| 815 | '[email protected]', | ||
| 816 | '[email protected]' | ||
| 817 | ) | ||
| 818 | ) | ||
| 819 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 820 | admin = dbsession.query(models.User) \ | ||
| 821 | .filter(models.User.email == '[email protected]') \ | ||
| 822 | .one() | ||
| 823 | uapi = UserApi( | ||
| 824 | current_user=admin, | ||
| 825 | session=dbsession, | ||
| 826 | config=self.app_config, | ||
| 827 | ) | ||
| 828 | gapi = GroupApi( | ||
| 829 | current_user=admin, | ||
| 830 | session=dbsession, | ||
| 831 | config=self.app_config, | ||
| 832 | ) | ||
| 833 |         groups = [gapi.get_one_with_name('users')] | ||
| 834 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 835 | workspace_api = WorkspaceApi( | ||
| 836 | current_user=admin, | ||
| 837 | session=dbsession, | ||
| 838 | config=self.app_config, | ||
| 839 | show_deleted=True, | ||
| 840 | ) | ||
| 841 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 842 | workspace_api.delete(workspace, flush=True) | ||
| 843 | rapi = RoleApi( | ||
| 844 | current_user=admin, | ||
| 845 | session=dbsession, | ||
| 846 | config=self.app_config, | ||
| 847 | ) | ||
| 848 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 849 | transaction.commit() | ||
| 850 | workspace_id = int(workspace.workspace_id) | ||
| 851 | self.testapp.authorization = ( | ||
| 852 | 'Basic', | ||
| 853 | ( | ||
| 854 | '[email protected]', | ||
| 855 | '[email protected]' | ||
| 856 | ) | ||
| 857 | ) | ||
| 858 | # delete | ||
| 859 | res = self.testapp.put( | ||
| 860 |             '/api/v2/workspaces/{}/trashed/restore'.format(workspace_id), | ||
| 861 | status=403 | ||
| 862 | ) | ||
| 863 | assert isinstance(res.json, dict) | ||
| 864 | assert 'code' in res.json.keys() | ||
| 865 | assert res.json_body['code'] == error.INSUFFICIENT_USER_PROFILE | ||
| 866 | res = self.testapp.get( | ||
| 867 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 868 | status=200 | ||
| 869 | ) | ||
| 870 | workspace = res.json_body | ||
| 871 | assert workspace['is_deleted'] is True | ||
| 872 | |||
| 873 | def test_api__undelete_workspace__err_403__manager_reader(self) -> None: | ||
| 874 | """ | ||
| 875 | Test undelete workspace as manager and reader of the workspace | ||
| 876 | """ | ||
| 877 | self.testapp.authorization = ( | ||
| 878 | 'Basic', | ||
| 879 | ( | ||
| 880 | '[email protected]', | ||
| 881 | '[email protected]' | ||
| 882 | ) | ||
| 883 | ) | ||
| 884 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 885 | admin = dbsession.query(models.User) \ | ||
| 886 | .filter(models.User.email == '[email protected]') \ | ||
| 887 | .one() | ||
| 888 | uapi = UserApi( | ||
| 889 | current_user=admin, | ||
| 890 | session=dbsession, | ||
| 891 | config=self.app_config, | ||
| 892 | ) | ||
| 893 | gapi = GroupApi( | ||
| 894 | current_user=admin, | ||
| 895 | session=dbsession, | ||
| 896 | config=self.app_config, | ||
| 897 | ) | ||
| 898 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 899 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False)  # nopep8 | ||
| 900 | workspace_api = WorkspaceApi( | ||
| 901 | current_user=admin, | ||
| 902 | session=dbsession, | ||
| 903 | config=self.app_config, | ||
| 904 | show_deleted=True, | ||
| 905 | ) | ||
| 906 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 907 | workspace_api.delete(workspace, flush=True) | ||
| 908 | rapi = RoleApi( | ||
| 909 | current_user=admin, | ||
| 910 | session=dbsession, | ||
| 911 | config=self.app_config, | ||
| 912 | ) | ||
| 913 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 914 | transaction.commit() | ||
| 915 | workspace_id = int(workspace.workspace_id) | ||
| 916 | self.testapp.authorization = ( | ||
| 917 | 'Basic', | ||
| 918 | ( | ||
| 919 | '[email protected]', | ||
| 920 | '[email protected]' | ||
| 921 | ) | ||
| 922 | ) | ||
| 923 | # delete | ||
| 924 | res = self.testapp.put( | ||
| 925 |             '/api/v2/workspaces/{}/trashed/restore'.format(workspace_id), | ||
| 926 | status=403 | ||
| 927 | ) | ||
| 928 | assert isinstance(res.json, dict) | ||
| 929 | assert 'code' in res.json.keys() | ||
| 930 | assert res.json_body['code'] == error.INSUFFICIENT_USER_PROFILE | ||
| 931 | res = self.testapp.get( | ||
| 932 |             '/api/v2/workspaces/{}'.format(workspace_id), | ||
| 933 | status=200 | ||
| 934 | ) | ||
| 935 | workspace = res.json_body | ||
| 936 | assert workspace['is_deleted'] is True | ||
| 937 | |||
| 938 | View Code Duplication | def test_api__undelete_workspace__err_400__manager(self) -> None: | |
| 939 | """ | ||
| 940 | Test delete workspace as global manager without having any role in the | ||
| 941 | workspace | ||
| 942 | """ | ||
| 943 | self.testapp.authorization = ( | ||
| 944 | 'Basic', | ||
| 945 | ( | ||
| 946 | '[email protected]', | ||
| 947 | '[email protected]' | ||
| 948 | ) | ||
| 949 | ) | ||
| 950 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 951 | admin = dbsession.query(models.User) \ | ||
| 952 | .filter(models.User.email == '[email protected]') \ | ||
| 953 | .one() | ||
| 954 | uapi = UserApi( | ||
| 955 | current_user=admin, | ||
| 956 | session=dbsession, | ||
| 957 | config=self.app_config, | ||
| 958 | ) | ||
| 959 |         user = uapi.create_user('[email protected]', password='[email protected]', | ||
| 960 | do_save=True, do_notify=False) # nopep8 | ||
| 961 | workspace_api = WorkspaceApi( | ||
| 962 | current_user=admin, | ||
| 963 | session=dbsession, | ||
| 964 | config=self.app_config, | ||
| 965 | show_deleted=True, | ||
| 966 | ) | ||
| 967 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 968 | workspace_api.delete(workspace, flush=True) | ||
| 969 | rapi = RoleApi( | ||
| 970 | current_user=admin, | ||
| 971 | session=dbsession, | ||
| 972 | config=self.app_config, | ||
| 973 | ) | ||
| 974 | transaction.commit() | ||
| 975 | workspace_id = int(workspace.workspace_id) | ||
| 976 | self.testapp.authorization = ( | ||
| 977 | 'Basic', | ||
| 978 | ( | ||
| 979 | '[email protected]', | ||
| 980 | '[email protected]' | ||
| 981 | ) | ||
| 982 | ) | ||
| 983 | # delete | ||
| 984 | res = self.testapp.put( | ||
| 985 |             '/api/v2/workspaces/{}/trashed/restore'.format(workspace_id), | ||
| 986 | status=400 | ||
| 987 | ) | ||
| 988 | assert isinstance(res.json, dict) | ||
| 989 | assert 'code' in res.json.keys() | ||
| 990 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 991 | |||
| 992 | def test_api__get_workspace__err_400__unallowed_user(self) -> None: | ||
| 993 | """ | ||
| 994 | Check obtain workspace unreachable for user | ||
| 995 | """ | ||
| 996 | self.testapp.authorization = ( | ||
| 997 | 'Basic', | ||
| 998 | ( | ||
| 999 | '[email protected]', | ||
| 1000 | 'foobarbaz' | ||
| 1001 | ) | ||
| 1002 | ) | ||
| 1003 |         res = self.testapp.get('/api/v2/workspaces/1', status=400) | ||
| 1004 | assert isinstance(res.json, dict) | ||
| 1005 | assert 'code' in res.json.keys() | ||
| 1006 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 1007 | assert 'message' in res.json.keys() | ||
| 1008 | assert 'details' in res.json.keys() | ||
| 1009 | |||
| 1010 | def test_api__get_workspace__err_401__unregistered_user(self) -> None: | ||
| 1011 | """ | ||
| 1012 | Check obtain workspace without registered user. | ||
| 1013 | """ | ||
| 1014 | self.testapp.authorization = ( | ||
| 1015 | 'Basic', | ||
| 1016 | ( | ||
| 1017 | '[email protected]', | ||
| 1018 | 'lapin' | ||
| 1019 | ) | ||
| 1020 | ) | ||
| 1021 |         res = self.testapp.get('/api/v2/workspaces/1', status=401) | ||
| 1022 | assert isinstance(res.json, dict) | ||
| 1023 | assert 'code' in res.json.keys() | ||
| 1024 | assert res.json_body['code'] is None | ||
| 1025 | assert 'message' in res.json.keys() | ||
| 1026 | assert 'details' in res.json.keys() | ||
| 1027 | |||
| 1028 | def test_api__get_workspace__err_400__workspace_does_not_exist(self) -> None: # nopep8 | ||
| 1029 | """ | ||
| 1030 | Check obtain workspace who does not exist with an existing user. | ||
| 1031 | """ | ||
| 1032 | self.testapp.authorization = ( | ||
| 1033 | 'Basic', | ||
| 1034 | ( | ||
| 1035 | '[email protected]', | ||
| 1036 | '[email protected]' | ||
| 1037 | ) | ||
| 1038 | ) | ||
| 1039 |         res = self.testapp.get('/api/v2/workspaces/5', status=400) | ||
| 1040 | assert isinstance(res.json, dict) | ||
| 1041 | assert 'code' in res.json.keys() | ||
| 1042 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 1043 | assert 'message' in res.json.keys() | ||
| 1044 | assert 'details' in res.json.keys() | ||
| 1045 | |||
| 1046 | |||
| 1047 | class TestWorkspacesEndpoints(FunctionalTest): | ||
| 1048 | """ | ||
| 1049 | Tests for /api/v2/workspaces | ||
| 1050 | """ | ||
| 1051 | fixtures = [BaseFixture] | ||
| 1052 | |||
| 1053 | def test_api__get_workspaces__ok_200__nominal_case(self): | ||
| 1054 | """ | ||
| 1055 | Check obtain all workspaces reachables for user with user auth. | ||
| 1056 | """ | ||
| 1057 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1058 | admin = dbsession.query(models.User) \ | ||
| 1059 | .filter(models.User.email == '[email protected]') \ | ||
| 1060 | .one() | ||
| 1061 | |||
| 1062 | workspace_api = WorkspaceApi( | ||
| 1063 | session=dbsession, | ||
| 1064 | current_user=admin, | ||
| 1065 | config=self.app_config, | ||
| 1066 | ) | ||
| 1067 |         workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 1068 |         workspace_api.create_workspace('test2', save_now=True)  # nopep8 | ||
| 1069 |         workspace_api.create_workspace('test3', save_now=True)  # nopep8 | ||
| 1070 | transaction.commit() | ||
| 1071 | self.testapp.authorization = ( | ||
| 1072 | 'Basic', | ||
| 1073 | ( | ||
| 1074 | '[email protected]', | ||
| 1075 | '[email protected]' | ||
| 1076 | ) | ||
| 1077 | ) | ||
| 1078 |         res = self.testapp.get('/api/v2/workspaces', status=200) | ||
| 1079 | res = res.json_body | ||
| 1080 | assert len(res) == 3 | ||
| 1081 | workspace = res[0] | ||
| 1082 | assert workspace['label'] == 'test' | ||
| 1083 | assert workspace['slug'] == 'test' | ||
| 1084 | workspace = res[1] | ||
| 1085 | assert workspace['label'] == 'test2' | ||
| 1086 | assert workspace['slug'] == 'test2' | ||
| 1087 | workspace = res[2] | ||
| 1088 | assert workspace['label'] == 'test3' | ||
| 1089 | assert workspace['slug'] == 'test3' | ||
| 1090 | |||
| 1091 | def test_api__get_workspaces__err_403__unallowed_user(self): | ||
| 1092 | """ | ||
| 1093 | Check obtain all workspaces reachables for one user | ||
| 1094 | with another non-admin user auth. | ||
| 1095 | """ | ||
| 1096 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1097 | admin = dbsession.query(models.User) \ | ||
| 1098 | .filter(models.User.email == '[email protected]') \ | ||
| 1099 | .one() | ||
| 1100 | uapi = UserApi( | ||
| 1101 | current_user=admin, | ||
| 1102 | session=dbsession, | ||
| 1103 | config=self.app_config, | ||
| 1104 | ) | ||
| 1105 | gapi = GroupApi( | ||
| 1106 | current_user=admin, | ||
| 1107 | session=dbsession, | ||
| 1108 | config=self.app_config, | ||
| 1109 | ) | ||
| 1110 |         groups = [gapi.get_one_with_name('users')] | ||
| 1111 |         user = uapi.create_user('[email protected]', password='[email protected]', | ||
| 1112 | do_save=True, do_notify=False, | ||
| 1113 | groups=groups) # nopep8 | ||
| 1114 | transaction.commit() | ||
| 1115 | self.testapp.authorization = ( | ||
| 1116 | 'Basic', | ||
| 1117 | ( | ||
| 1118 | '[email protected]', | ||
| 1119 | '[email protected]' | ||
| 1120 | ) | ||
| 1121 | ) | ||
| 1122 |         res = self.testapp.get('/api/v2/workspaces', status=403) | ||
| 1123 | assert isinstance(res.json, dict) | ||
| 1124 | assert 'code' in res.json.keys() | ||
| 1125 | assert res.json_body['code'] == error.INSUFFICIENT_USER_PROFILE | ||
| 1126 | assert 'message' in res.json.keys() | ||
| 1127 | assert 'details' in res.json.keys() | ||
| 1128 | |||
| 1129 | def test_api__get_workspaces__err_401__unregistered_user(self): | ||
| 1130 | """ | ||
| 1131 | Check obtain all workspaces reachables for one user | ||
| 1132 | without correct user auth (user unregistered). | ||
| 1133 | """ | ||
| 1134 | self.testapp.authorization = ( | ||
| 1135 | 'Basic', | ||
| 1136 | ( | ||
| 1137 | '[email protected]', | ||
| 1138 | 'lapin' | ||
| 1139 | ) | ||
| 1140 | ) | ||
| 1141 |         res = self.testapp.get('/api/v2/workspaces', status=401) | ||
| 1142 | assert isinstance(res.json, dict) | ||
| 1143 | assert 'code' in res.json.keys() | ||
| 1144 | assert res.json_body['code'] is None | ||
| 1145 | assert 'message' in res.json.keys() | ||
| 1146 | assert 'details' in res.json.keys() | ||
| 1147 | |||
| 1148 | |||
| 1149 | class TestWorkspaceMembersEndpoint(FunctionalTest): | ||
| 1150 | """ | ||
| 1151 |     Tests for /api/v2/workspaces/{workspace_id}/members endpoint | ||
| 1152 | """ | ||
| 1153 | |||
| 1154 | fixtures = [BaseFixture, ContentFixtures] | ||
| 1155 | |||
| 1156 | View Code Duplication | def test_api__get_workspace_members__ok_200__nominal_case(self): | |
| 1157 | """ | ||
| 1158 | Check obtain workspace members list with a reachable workspace for user | ||
| 1159 | """ | ||
| 1160 | self.testapp.authorization = ( | ||
| 1161 | 'Basic', | ||
| 1162 | ( | ||
| 1163 | '[email protected]', | ||
| 1164 | '[email protected]' | ||
| 1165 | ) | ||
| 1166 | ) | ||
| 1167 |         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8 | ||
| 1168 | assert len(res) == 1 | ||
| 1169 | user_role = res[0] | ||
| 1170 | assert user_role['role'] == 'workspace-manager' | ||
| 1171 | assert user_role['user_id'] == 1 | ||
| 1172 | assert user_role['workspace_id'] == 1 | ||
| 1173 | assert user_role['workspace']['workspace_id'] == 1 | ||
| 1174 | assert user_role['workspace']['label'] == 'Business' | ||
| 1175 | assert user_role['workspace']['slug'] == 'business' | ||
| 1176 | assert user_role['user']['public_name'] == 'Global manager' | ||
| 1177 | assert user_role['user']['user_id'] == 1 | ||
| 1178 | assert user_role['is_active'] is True | ||
| 1179 | assert user_role['do_notify'] is True | ||
| 1180 | # TODO - G.M - 24-05-2018 - [Avatar] Replace | ||
| 1181 | # by correct value when avatar feature will be enabled | ||
| 1182 | assert user_role['user']['avatar_url'] is None | ||
| 1183 | |||
| 1184 | View Code Duplication | def test_api__get_workspace_members__ok_200__as_admin(self): | |
| 1185 | """ | ||
| 1186 | Check obtain workspace members list of a workspace where admin doesn't | ||
| 1187 | have any right | ||
| 1188 | """ | ||
| 1189 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1190 | admin = dbsession.query(models.User) \ | ||
| 1191 | .filter(models.User.email == '[email protected]') \ | ||
| 1192 | .one() | ||
| 1193 | uapi = UserApi( | ||
| 1194 | current_user=admin, | ||
| 1195 | session=dbsession, | ||
| 1196 | config=self.app_config, | ||
| 1197 | ) | ||
| 1198 | gapi = GroupApi( | ||
| 1199 | current_user=admin, | ||
| 1200 | session=dbsession, | ||
| 1201 | config=self.app_config, | ||
| 1202 | ) | ||
| 1203 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 1204 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 1205 | workspace_api = WorkspaceApi( | ||
| 1206 | current_user=admin, | ||
| 1207 | session=dbsession, | ||
| 1208 | config=self.app_config, | ||
| 1209 | ) | ||
| 1210 |         workspace = workspace_api.create_workspace('test_2', save_now=True)  # nopep8 | ||
| 1211 | rapi = RoleApi( | ||
| 1212 | current_user=None, | ||
| 1213 | session=dbsession, | ||
| 1214 | config=self.app_config, | ||
| 1215 | ) | ||
| 1216 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 1217 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 1218 | transaction.commit() | ||
| 1219 | user_id = user.user_id | ||
| 1220 | workspace_id = workspace.workspace_id | ||
| 1221 | admin_id = admin.user_id | ||
| 1222 | self.testapp.authorization = ( | ||
| 1223 | 'Basic', | ||
| 1224 | ( | ||
| 1225 | '[email protected]', | ||
| 1226 | '[email protected]' | ||
| 1227 | ) | ||
| 1228 | ) | ||
| 1229 |         res = self.testapp.get('/api/v2/workspaces/{}/members'.format( | ||
| 1230 | workspace_id, | ||
| 1231 | user_id | ||
| 1232 | ), status=200).json_body | ||
| 1233 | assert len(res) == 1 | ||
| 1234 | user_role = res[0] | ||
| 1235 | assert user_role['role'] == 'reader' | ||
| 1236 | assert user_role['user_id'] == user_id | ||
| 1237 | assert user_role['workspace_id'] == workspace_id | ||
| 1238 | assert user_role['is_active'] is True | ||
| 1239 | assert user_role['do_notify'] is False | ||
| 1240 | |||
| 1241 | def test_api__get_workspace_members__err_400__unallowed_user(self): | ||
| 1242 | """ | ||
| 1243 | Check obtain workspace members list with an unreachable workspace for | ||
| 1244 | user | ||
| 1245 | """ | ||
| 1246 | self.testapp.authorization = ( | ||
| 1247 | 'Basic', | ||
| 1248 | ( | ||
| 1249 | '[email protected]', | ||
| 1250 | 'foobarbaz' | ||
| 1251 | ) | ||
| 1252 | ) | ||
| 1253 |         res = self.testapp.get('/api/v2/workspaces/3/members', status=400) | ||
| 1254 | assert isinstance(res.json, dict) | ||
| 1255 | assert 'code' in res.json.keys() | ||
| 1256 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 1257 | assert 'message' in res.json.keys() | ||
| 1258 | assert 'details' in res.json.keys() | ||
| 1259 | |||
| 1260 | def test_api__get_workspace_members__err_401__unregistered_user(self): | ||
| 1261 | """ | ||
| 1262 | Check obtain workspace members list with an unregistered user | ||
| 1263 | """ | ||
| 1264 | self.testapp.authorization = ( | ||
| 1265 | 'Basic', | ||
| 1266 | ( | ||
| 1267 | '[email protected]', | ||
| 1268 | 'lapin' | ||
| 1269 | ) | ||
| 1270 | ) | ||
| 1271 |         res = self.testapp.get('/api/v2/workspaces/1/members', status=401) | ||
| 1272 | assert isinstance(res.json, dict) | ||
| 1273 | assert 'code' in res.json.keys() | ||
| 1274 | assert res.json_body['code'] is None | ||
| 1275 | assert 'message' in res.json.keys() | ||
| 1276 | assert 'details' in res.json.keys() | ||
| 1277 | |||
| 1278 | View Code Duplication | def test_api__get_workspace_member__ok_200__self(self): | |
| 1279 | """ | ||
| 1280 | Check obtain workspace members list with a reachable workspace for user | ||
| 1281 | """ | ||
| 1282 | self.testapp.authorization = ( | ||
| 1283 | 'Basic', | ||
| 1284 | ( | ||
| 1285 | '[email protected]', | ||
| 1286 | '[email protected]' | ||
| 1287 | ) | ||
| 1288 | ) | ||
| 1289 |         res = self.testapp.get('/api/v2/workspaces/1/members/1', status=200).json_body   # nopep8 | ||
| 1290 | user_role = res | ||
| 1291 | assert user_role['role'] == 'workspace-manager' | ||
| 1292 | assert user_role['user_id'] == 1 | ||
| 1293 | assert user_role['workspace_id'] == 1 | ||
| 1294 | assert user_role['workspace']['workspace_id'] == 1 | ||
| 1295 | assert user_role['workspace']['label'] == 'Business' | ||
| 1296 | assert user_role['workspace']['slug'] == 'business' | ||
| 1297 | assert user_role['user']['public_name'] == 'Global manager' | ||
| 1298 | assert user_role['user']['user_id'] == 1 | ||
| 1299 | assert user_role['is_active'] is True | ||
| 1300 | assert user_role['do_notify'] is True | ||
| 1301 | # TODO - G.M - 24-05-2018 - [Avatar] Replace | ||
| 1302 | # by correct value when avatar feature will be enabled | ||
| 1303 | assert user_role['user']['avatar_url'] is None | ||
| 1304 | |||
| 1305 | View Code Duplication | def test_api__get_workspace_member__ok_200__as_admin(self): | |
| 1306 | """ | ||
| 1307 | Check obtain workspace members list with a reachable workspace for user | ||
| 1308 | """ | ||
| 1309 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1310 | admin = dbsession.query(models.User) \ | ||
| 1311 | .filter(models.User.email == '[email protected]') \ | ||
| 1312 | .one() | ||
| 1313 | uapi = UserApi( | ||
| 1314 | current_user=admin, | ||
| 1315 | session=dbsession, | ||
| 1316 | config=self.app_config, | ||
| 1317 | ) | ||
| 1318 | gapi = GroupApi( | ||
| 1319 | current_user=admin, | ||
| 1320 | session=dbsession, | ||
| 1321 | config=self.app_config, | ||
| 1322 | ) | ||
| 1323 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 1324 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 1325 | workspace_api = WorkspaceApi( | ||
| 1326 | current_user=admin, | ||
| 1327 | session=dbsession, | ||
| 1328 | config=self.app_config, | ||
| 1329 | ) | ||
| 1330 |         workspace = workspace_api.create_workspace('test_2', save_now=True)  # nopep8 | ||
| 1331 | rapi = RoleApi( | ||
| 1332 | current_user=None, | ||
| 1333 | session=dbsession, | ||
| 1334 | config=self.app_config, | ||
| 1335 | ) | ||
| 1336 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 1337 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 1338 | transaction.commit() | ||
| 1339 | user_id = user.user_id | ||
| 1340 | workspace_id = workspace.workspace_id | ||
| 1341 | admin_id = admin.user_id | ||
| 1342 | self.testapp.authorization = ( | ||
| 1343 | 'Basic', | ||
| 1344 | ( | ||
| 1345 | '[email protected]', | ||
| 1346 | '[email protected]' | ||
| 1347 | ) | ||
| 1348 | ) | ||
| 1349 |         res = self.testapp.get('/api/v2/workspaces/{}/members/{}'.format( | ||
| 1350 | workspace_id, | ||
| 1351 | user_id | ||
| 1352 | ), status=200).json_body | ||
| 1353 | user_role = res | ||
| 1354 | assert user_role['role'] == 'reader' | ||
| 1355 | assert user_role['user_id'] == user_id | ||
| 1356 | assert user_role['workspace_id'] == workspace_id | ||
| 1357 | assert user_role['is_active'] is True | ||
| 1358 | assert user_role['do_notify'] is False | ||
| 1359 | |||
| 1360 | def test_api__get_workspace_member__ok_200__other_user(self): | ||
| 1361 | """ | ||
| 1362 | Check obtain workspace members list with a reachable workspace for user | ||
| 1363 | """ | ||
| 1364 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1365 | admin = dbsession.query(models.User) \ | ||
| 1366 | .filter(models.User.email == '[email protected]') \ | ||
| 1367 | .one() | ||
| 1368 | uapi = UserApi( | ||
| 1369 | current_user=admin, | ||
| 1370 | session=dbsession, | ||
| 1371 | config=self.app_config, | ||
| 1372 | ) | ||
| 1373 | gapi = GroupApi( | ||
| 1374 | current_user=admin, | ||
| 1375 | session=dbsession, | ||
| 1376 | config=self.app_config, | ||
| 1377 | ) | ||
| 1378 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 1379 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 1380 | workspace_api = WorkspaceApi( | ||
| 1381 | current_user=admin, | ||
| 1382 | session=dbsession, | ||
| 1383 | config=self.app_config, | ||
| 1384 | ) | ||
| 1385 |         workspace = workspace_api.create_workspace('test_2', save_now=True)  # nopep8 | ||
| 1386 | rapi = RoleApi( | ||
| 1387 | current_user=None, | ||
| 1388 | session=dbsession, | ||
| 1389 | config=self.app_config, | ||
| 1390 | ) | ||
| 1391 | rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 1392 | transaction.commit() | ||
| 1393 | user_id = user.user_id | ||
| 1394 | workspace_id = workspace.workspace_id | ||
| 1395 | admin_id = admin.user_id | ||
| 1396 | self.testapp.authorization = ( | ||
| 1397 | 'Basic', | ||
| 1398 | ( | ||
| 1399 | '[email protected]', | ||
| 1400 | '[email protected]' | ||
| 1401 | ) | ||
| 1402 | ) | ||
| 1403 |         res = self.testapp.get('/api/v2/workspaces/{}/members/{}'.format( | ||
| 1404 | workspace_id, | ||
| 1405 | user_id | ||
| 1406 | ), status=200).json_body | ||
| 1407 | user_role = res | ||
| 1408 | assert user_role['role'] == 'reader' | ||
| 1409 | assert user_role['user_id'] == user_id | ||
| 1410 | assert user_role['workspace_id'] == workspace_id | ||
| 1411 | assert user_role['is_active'] is True | ||
| 1412 | assert user_role['do_notify'] is False | ||
| 1413 | |||
| 1414 | self.testapp.authorization = ( | ||
| 1415 | 'Basic', | ||
| 1416 | ( | ||
| 1417 | '[email protected]', | ||
| 1418 | '[email protected]' | ||
| 1419 | ) | ||
| 1420 | ) | ||
| 1421 |         res = self.testapp.get('/api/v2/workspaces/{}/members/{}'.format( | ||
| 1422 | workspace_id, | ||
| 1423 | admin_id | ||
| 1424 | ), status=200).json_body | ||
| 1425 | user_role = res | ||
| 1426 | assert user_role['role'] == 'workspace-manager' | ||
| 1427 | assert user_role['user_id'] == admin_id | ||
| 1428 | assert user_role['workspace_id'] == workspace_id | ||
| 1429 | assert user_role['is_active'] is True | ||
| 1430 | assert user_role['do_notify'] is True | ||
| 1431 | |||
| 1432 | def test_api__get_workspace_member__err_400__unallowed_user(self): | ||
| 1433 | """ | ||
| 1434 | Check obtain workspace members info with an unreachable workspace for | ||
| 1435 | user | ||
| 1436 | """ | ||
| 1437 | self.testapp.authorization = ( | ||
| 1438 | 'Basic', | ||
| 1439 | ( | ||
| 1440 | '[email protected]', | ||
| 1441 | 'foobarbaz' | ||
| 1442 | ) | ||
| 1443 | ) | ||
| 1444 |         res = self.testapp.get('/api/v2/workspaces/3/members/1', status=400) | ||
| 1445 | assert isinstance(res.json, dict) | ||
| 1446 | assert 'code' in res.json.keys() | ||
| 1447 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 1448 | assert 'message' in res.json.keys() | ||
| 1449 | assert 'details' in res.json.keys() | ||
| 1450 | |||
| 1451 | def test_api__get_workspace_member__err_401__unregistered_user(self): | ||
| 1452 | """ | ||
| 1453 | Check obtain workspace member info with an unregistered user | ||
| 1454 | """ | ||
| 1455 | self.testapp.authorization = ( | ||
| 1456 | 'Basic', | ||
| 1457 | ( | ||
| 1458 | '[email protected]', | ||
| 1459 | 'lapin' | ||
| 1460 | ) | ||
| 1461 | ) | ||
| 1462 |         res = self.testapp.get('/api/v2/workspaces/1/members/1', status=401) | ||
| 1463 | assert isinstance(res.json, dict) | ||
| 1464 | assert 'code' in res.json.keys() | ||
| 1465 | assert res.json_body['code'] is None | ||
| 1466 | assert 'message' in res.json.keys() | ||
| 1467 | assert 'details' in res.json.keys() | ||
| 1468 | |||
| 1469 | def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8 | ||
| 1470 | """ | ||
| 1471 | Check obtain workspace members list with an existing user but | ||
| 1472 | an unexisting workspace | ||
| 1473 | """ | ||
| 1474 | self.testapp.authorization = ( | ||
| 1475 | 'Basic', | ||
| 1476 | ( | ||
| 1477 | '[email protected]', | ||
| 1478 | '[email protected]' | ||
| 1479 | ) | ||
| 1480 | ) | ||
| 1481 |         res = self.testapp.get('/api/v2/workspaces/5/members', status=400) | ||
| 1482 | assert isinstance(res.json, dict) | ||
| 1483 | assert 'code' in res.json.keys() | ||
| 1484 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 1485 | assert 'message' in res.json.keys() | ||
| 1486 | assert 'details' in res.json.keys() | ||
| 1487 | |||
| 1488 | View Code Duplication | def test_api__create_workspace_member_role__ok_200__user_id(self): | |
| 1489 | """ | ||
| 1490 | Create workspace member role | ||
| 1491 | :return: | ||
| 1492 | """ | ||
| 1493 | self.testapp.authorization = ( | ||
| 1494 | 'Basic', | ||
| 1495 | ( | ||
| 1496 | '[email protected]', | ||
| 1497 | '[email protected]' | ||
| 1498 | ) | ||
| 1499 | ) | ||
| 1500 | # create workspace role | ||
| 1501 |         params = { | ||
| 1502 | 'user_id': 2, | ||
| 1503 | 'user_email': None, | ||
| 1504 | 'user_public_name': None, | ||
| 1505 | 'role': 'content-manager', | ||
| 1506 | } | ||
| 1507 | res = self.testapp.post_json( | ||
| 1508 | '/api/v2/workspaces/1/members', | ||
| 1509 | status=200, | ||
| 1510 | params=params, | ||
| 1511 | ) | ||
| 1512 | user_role_found = res.json_body | ||
| 1513 | assert user_role_found['role'] == 'content-manager' | ||
| 1514 | assert user_role_found['user_id'] == 2 | ||
| 1515 | assert user_role_found['workspace_id'] == 1 | ||
| 1516 | assert user_role_found['newly_created'] is False | ||
| 1517 | assert user_role_found['email_sent'] is False | ||
| 1518 | assert user_role_found['do_notify'] is False | ||
| 1519 | |||
| 1520 |         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8 | ||
| 1521 | assert len(res) == 2 | ||
| 1522 | user_role = res[0] | ||
| 1523 | assert user_role['role'] == 'workspace-manager' | ||
| 1524 | assert user_role['user_id'] == 1 | ||
| 1525 | assert user_role['workspace_id'] == 1 | ||
| 1526 | user_role = res[1] | ||
| 1527 | assert user_role_found['role'] == user_role['role'] | ||
| 1528 | assert user_role_found['user_id'] == user_role['user_id'] | ||
| 1529 | assert user_role_found['workspace_id'] == user_role['workspace_id'] | ||
| 1530 | |||
| 1531 | def test_api__create_workspace_members_role_ok_200__user_email_as_admin(self): | ||
| 1532 | """ | ||
| 1533 | Check obtain workspace members list of a workspace where admin doesn't | ||
| 1534 | have any right | ||
| 1535 | """ | ||
| 1536 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1537 | admin = dbsession.query(models.User) \ | ||
| 1538 | .filter(models.User.email == '[email protected]') \ | ||
| 1539 | .one() | ||
| 1540 | uapi = UserApi( | ||
| 1541 | current_user=admin, | ||
| 1542 | session=dbsession, | ||
| 1543 | config=self.app_config, | ||
| 1544 | ) | ||
| 1545 | gapi = GroupApi( | ||
| 1546 | current_user=admin, | ||
| 1547 | session=dbsession, | ||
| 1548 | config=self.app_config, | ||
| 1549 | ) | ||
| 1550 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 1551 | workspace_api = WorkspaceApi( | ||
| 1552 | current_user=admin, | ||
| 1553 | session=dbsession, | ||
| 1554 | config=self.app_config, | ||
| 1555 | ) | ||
| 1556 |         workspace = workspace_api.create_workspace('test_2', save_now=True)  # nopep8 | ||
| 1557 | rapi = RoleApi( | ||
| 1558 | current_user=None, | ||
| 1559 | session=dbsession, | ||
| 1560 | config=self.app_config, | ||
| 1561 | ) | ||
| 1562 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 1563 | transaction.commit() | ||
| 1564 | workspace_id = workspace.workspace_id | ||
| 1565 | admin_id = admin.user_id | ||
| 1566 | self.testapp.authorization = ( | ||
| 1567 | 'Basic', | ||
| 1568 | ( | ||
| 1569 | '[email protected]', | ||
| 1570 | '[email protected]' | ||
| 1571 | ) | ||
| 1572 | ) | ||
| 1573 | # create workspace role | ||
| 1574 |         params = { | ||
| 1575 | 'user_id': None, | ||
| 1576 | 'user_email': '[email protected]', | ||
| 1577 | 'user_public_name': None, | ||
| 1578 | 'role': 'content-manager', | ||
| 1579 | } | ||
| 1580 | res = self.testapp.post_json( | ||
| 1581 |             '/api/v2/workspaces/{}/members'.format(workspace_id), | ||
| 1582 | status=200, | ||
| 1583 | params=params, | ||
| 1584 | ) | ||
| 1585 | user_role_found = res.json_body | ||
| 1586 | assert user_role_found['role'] == 'content-manager' | ||
| 1587 | assert user_role_found['user_id'] | ||
| 1588 | assert user_role_found['workspace_id'] == workspace_id | ||
| 1589 | assert user_role_found['newly_created'] is False | ||
| 1590 | assert user_role_found['email_sent'] is False | ||
| 1591 | assert user_role_found['do_notify'] is False | ||
| 1592 | |||
| 1593 |         res = self.testapp.get('/api/v2/workspaces/{}/members'.format(workspace_id), status=200).json_body   # nopep8 | ||
| 1594 | assert len(res) == 1 | ||
| 1595 | user_role = res[0] | ||
| 1596 | assert user_role_found['role'] == user_role['role'] | ||
| 1597 | assert user_role_found['user_id'] == user_role['user_id'] | ||
| 1598 | assert user_role_found['workspace_id'] == user_role['workspace_id'] | ||
| 1599 | |||
| 1600 | def test_api__create_workspace_members_role_ok_200__user_email_as_workspace_manager(self): # nopep8 | ||
| 1601 | """ | ||
| 1602 | Check obtain workspace members list of a workspace where admin doesn't | ||
| 1603 | have any right | ||
| 1604 | """ | ||
| 1605 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1606 | admin = dbsession.query(models.User) \ | ||
| 1607 | .filter(models.User.email == '[email protected]') \ | ||
| 1608 | .one() | ||
| 1609 | uapi = UserApi( | ||
| 1610 | current_user=admin, | ||
| 1611 | session=dbsession, | ||
| 1612 | config=self.app_config, | ||
| 1613 | ) | ||
| 1614 | gapi = GroupApi( | ||
| 1615 | current_user=admin, | ||
| 1616 | session=dbsession, | ||
| 1617 | config=self.app_config, | ||
| 1618 | ) | ||
| 1619 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 1620 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 1621 | workspace_api = WorkspaceApi( | ||
| 1622 | current_user=admin, | ||
| 1623 | session=dbsession, | ||
| 1624 | config=self.app_config, | ||
| 1625 | ) | ||
| 1626 |         workspace = workspace_api.create_workspace('test_2', save_now=True)  # nopep8 | ||
| 1627 | rapi = RoleApi( | ||
| 1628 | current_user=None, | ||
| 1629 | session=dbsession, | ||
| 1630 | config=self.app_config, | ||
| 1631 | ) | ||
| 1632 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 1633 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 1634 | transaction.commit() | ||
| 1635 | user_id = user.user_id | ||
| 1636 | workspace_id = workspace.workspace_id | ||
| 1637 | admin_id = admin.user_id | ||
| 1638 | self.testapp.authorization = ( | ||
| 1639 | 'Basic', | ||
| 1640 | ( | ||
| 1641 | '[email protected]', | ||
| 1642 | '[email protected]' | ||
| 1643 | ) | ||
| 1644 | ) | ||
| 1645 | # create workspace role | ||
| 1646 |         params = { | ||
| 1647 | 'user_id': None, | ||
| 1648 | 'user_email': '[email protected]', | ||
| 1649 | 'user_public_name': None, | ||
| 1650 | 'role': 'content-manager', | ||
| 1651 | } | ||
| 1652 | res = self.testapp.post_json( | ||
| 1653 |             '/api/v2/workspaces/{}/members'.format(workspace_id), | ||
| 1654 | status=200, | ||
| 1655 | params=params, | ||
| 1656 | ) | ||
| 1657 | user_role_found = res.json_body | ||
| 1658 | assert user_role_found['role'] == 'content-manager' | ||
| 1659 | assert user_role_found['user_id'] | ||
| 1660 | assert user_role_found['workspace_id'] == workspace_id | ||
| 1661 | assert user_role_found['newly_created'] is False | ||
| 1662 | assert user_role_found['email_sent'] is False | ||
| 1663 | assert user_role_found['do_notify'] is False | ||
| 1664 | |||
| 1665 |         res = self.testapp.get('/api/v2/workspaces/{}/members'.format(workspace_id), status=200).json_body   # nopep8 | ||
| 1666 | assert len(res) == 2 | ||
| 1667 | user_role = res[0] | ||
| 1668 | assert user_role_found['role'] == user_role['role'] | ||
| 1669 | assert user_role_found['user_id'] == user_role['user_id'] | ||
| 1670 | assert user_role_found['workspace_id'] == user_role['workspace_id'] | ||
| 1671 | user_role = res[1] | ||
| 1672 | assert user_role['role'] == 'workspace-manager' | ||
| 1673 | assert user_role['user_id'] == user_id | ||
| 1674 | assert user_role['workspace_id'] == workspace_id | ||
| 1675 | |||
| 1676 | View Code Duplication | def test_api__create_workspace_member_role__ok_200__user_email(self): | |
| 1677 | """ | ||
| 1678 | Create workspace member role | ||
| 1679 | :return: | ||
| 1680 | """ | ||
| 1681 | self.testapp.authorization = ( | ||
| 1682 | 'Basic', | ||
| 1683 | ( | ||
| 1684 | '[email protected]', | ||
| 1685 | '[email protected]' | ||
| 1686 | ) | ||
| 1687 | ) | ||
| 1688 | # create workspace role | ||
| 1689 |         params = { | ||
| 1690 | 'user_id': None, | ||
| 1691 | 'user_email': '[email protected]', | ||
| 1692 | 'user_public_name': None, | ||
| 1693 | 'role': 'content-manager', | ||
| 1694 | } | ||
| 1695 | res = self.testapp.post_json( | ||
| 1696 | '/api/v2/workspaces/1/members', | ||
| 1697 | status=200, | ||
| 1698 | params=params, | ||
| 1699 | ) | ||
| 1700 | user_role_found = res.json_body | ||
| 1701 | assert user_role_found['role'] == 'content-manager' | ||
| 1702 | assert user_role_found['user_id'] == 2 | ||
| 1703 | assert user_role_found['workspace_id'] == 1 | ||
| 1704 | assert user_role_found['newly_created'] is False | ||
| 1705 | assert user_role_found['email_sent'] is False | ||
| 1706 | assert user_role_found['do_notify'] is False | ||
| 1707 | |||
| 1708 |         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8 | ||
| 1709 | assert len(res) == 2 | ||
| 1710 | user_role = res[0] | ||
| 1711 | assert user_role['role'] == 'workspace-manager' | ||
| 1712 | assert user_role['user_id'] == 1 | ||
| 1713 | assert user_role['workspace_id'] == 1 | ||
| 1714 | user_role = res[1] | ||
| 1715 | assert user_role_found['role'] == user_role['role'] | ||
| 1716 | assert user_role_found['user_id'] == user_role['user_id'] | ||
| 1717 | assert user_role_found['workspace_id'] == user_role['workspace_id'] | ||
| 1718 | |||
| 1719 | View Code Duplication | def test_api__create_workspace_member_role__err_400__user_email__user_deactivated(self): # nopep8 | |
| 1720 | """ | ||
| 1721 | Create workspace member role | ||
| 1722 | :return: | ||
| 1723 | """ | ||
| 1724 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1725 | admin = dbsession.query(models.User) \ | ||
| 1726 | .filter(models.User.email == '[email protected]') \ | ||
| 1727 | .one() | ||
| 1728 | uapi = UserApi( | ||
| 1729 | current_user=admin, | ||
| 1730 | session=dbsession, | ||
| 1731 | config=self.app_config, | ||
| 1732 | ) | ||
| 1733 |         lawrence = uapi.get_one_by_email('[email protected]') | ||
| 1734 | lawrence.is_active = False | ||
| 1735 | uapi.save(lawrence) | ||
| 1736 | transaction.commit() | ||
| 1737 | self.testapp.authorization = ( | ||
| 1738 | 'Basic', | ||
| 1739 | ( | ||
| 1740 | '[email protected]', | ||
| 1741 | '[email protected]' | ||
| 1742 | ) | ||
| 1743 | ) | ||
| 1744 | |||
| 1745 | # create workspace role | ||
| 1746 |         params = { | ||
| 1747 | 'user_id': None, | ||
| 1748 | 'user_email': '[email protected]', | ||
| 1749 | 'user_public_name': None, | ||
| 1750 | 'role': 'content-manager', | ||
| 1751 | } | ||
| 1752 | res = self.testapp.post_json( | ||
| 1753 | '/api/v2/workspaces/1/members', | ||
| 1754 | status=400, | ||
| 1755 | params=params, | ||
| 1756 | ) | ||
| 1757 | assert isinstance(res.json, dict) | ||
| 1758 | assert 'code' in res.json.keys() | ||
| 1759 | assert res.json_body['code'] == error.USER_NOT_ACTIVE | ||
| 1760 | |||
| 1761 | View Code Duplication | def test_api__create_workspace_member_role__err_400__user_email__user_deleted(self): # nopep8 | |
| 1762 | """ | ||
| 1763 | Create workspace member role | ||
| 1764 | :return: | ||
| 1765 | """ | ||
| 1766 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1767 | admin = dbsession.query(models.User) \ | ||
| 1768 | .filter(models.User.email == '[email protected]') \ | ||
| 1769 | .one() | ||
| 1770 | uapi = UserApi( | ||
| 1771 | current_user=admin, | ||
| 1772 | session=dbsession, | ||
| 1773 | config=self.app_config, | ||
| 1774 | ) | ||
| 1775 |         lawrence = uapi.get_one_by_email('[email protected]') | ||
| 1776 | lawrence.is_deleted = True | ||
| 1777 | uapi.save(lawrence) | ||
| 1778 | transaction.commit() | ||
| 1779 | self.testapp.authorization = ( | ||
| 1780 | 'Basic', | ||
| 1781 | ( | ||
| 1782 | '[email protected]', | ||
| 1783 | '[email protected]' | ||
| 1784 | ) | ||
| 1785 | ) | ||
| 1786 | |||
| 1787 | # create workspace role | ||
| 1788 |         params = { | ||
| 1789 | 'user_id': None, | ||
| 1790 | 'user_email': '[email protected]', | ||
| 1791 | 'user_public_name': None, | ||
| 1792 | 'role': 'content-manager', | ||
| 1793 | } | ||
| 1794 | res = self.testapp.post_json( | ||
| 1795 | '/api/v2/workspaces/1/members', | ||
| 1796 | status=400, | ||
| 1797 | params=params, | ||
| 1798 | ) | ||
| 1799 | assert isinstance(res.json, dict) | ||
| 1800 | assert 'code' in res.json.keys() | ||
| 1801 | assert res.json_body['code'] == error.USER_DELETED | ||
| 1802 | |||
| 1803 | View Code Duplication | def test_api__create_workspace_member_role__ok_200__user_public_name(self): | |
| 1804 | """ | ||
| 1805 | Create workspace member role | ||
| 1806 | :return: | ||
| 1807 | """ | ||
| 1808 | self.testapp.authorization = ( | ||
| 1809 | 'Basic', | ||
| 1810 | ( | ||
| 1811 | '[email protected]', | ||
| 1812 | '[email protected]' | ||
| 1813 | ) | ||
| 1814 | ) | ||
| 1815 | # create workspace role | ||
| 1816 |         params = { | ||
| 1817 | 'user_id': None, | ||
| 1818 | 'user_email': None, | ||
| 1819 | 'user_public_name': 'Lawrence L.', | ||
| 1820 | 'role': 'content-manager', | ||
| 1821 | } | ||
| 1822 | res = self.testapp.post_json( | ||
| 1823 | '/api/v2/workspaces/1/members', | ||
| 1824 | status=200, | ||
| 1825 | params=params, | ||
| 1826 | ) | ||
| 1827 | user_role_found = res.json_body | ||
| 1828 | assert user_role_found['role'] == 'content-manager' | ||
| 1829 | assert user_role_found['user_id'] == 2 | ||
| 1830 | assert user_role_found['workspace_id'] == 1 | ||
| 1831 | assert user_role_found['newly_created'] is False | ||
| 1832 | assert user_role_found['email_sent'] is False | ||
| 1833 | assert user_role_found['do_notify'] is False | ||
| 1834 | |||
| 1835 |         res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body   # nopep8 | ||
| 1836 | assert len(res) == 2 | ||
| 1837 | user_role = res[0] | ||
| 1838 | assert user_role['role'] == 'workspace-manager' | ||
| 1839 | assert user_role['user_id'] == 1 | ||
| 1840 | assert user_role['workspace_id'] == 1 | ||
| 1841 | user_role = res[1] | ||
| 1842 | assert user_role_found['role'] == user_role['role'] | ||
| 1843 | assert user_role_found['user_id'] == user_role['user_id'] | ||
| 1844 | assert user_role_found['workspace_id'] == user_role['workspace_id'] | ||
| 1845 | |||
| 1846 | def test_api__create_workspace_member_role__ok_400__user_public_name_user_already_in_workspace(self): | ||
| 1847 | """ | ||
| 1848 | Create workspace member role | ||
| 1849 | :return: | ||
| 1850 | """ | ||
| 1851 | self.testapp.authorization = ( | ||
| 1852 | 'Basic', | ||
| 1853 | ( | ||
| 1854 | '[email protected]', | ||
| 1855 | '[email protected]' | ||
| 1856 | ) | ||
| 1857 | ) | ||
| 1858 | # create workspace role | ||
| 1859 |         params = { | ||
| 1860 | 'user_id': None, | ||
| 1861 | 'user_email': None, | ||
| 1862 | 'user_public_name': 'Lawrence L.', | ||
| 1863 | 'role': 'content-manager', | ||
| 1864 | } | ||
| 1865 | res = self.testapp.post_json( | ||
| 1866 | '/api/v2/workspaces/1/members', | ||
| 1867 | status=200, | ||
| 1868 | params=params, | ||
| 1869 | ) | ||
| 1870 | res = self.testapp.post_json( | ||
| 1871 | '/api/v2/workspaces/1/members', | ||
| 1872 | status=400, | ||
| 1873 | params=params, | ||
| 1874 | ) | ||
| 1875 | assert isinstance(res.json, dict) | ||
| 1876 | assert 'code' in res.json.keys() | ||
| 1877 | assert res.json_body['code'] == error.USER_ROLE_ALREADY_EXIST | ||
| 1878 | |||
| 1879 | def test_api__create_workspace_member_role__err_400__nothing_and_no_notification(self): # nopep8 | ||
| 1880 | """ | ||
| 1881 | Create workspace member role | ||
| 1882 | :return: | ||
| 1883 | """ | ||
| 1884 | self.testapp.authorization = ( | ||
| 1885 | 'Basic', | ||
| 1886 | ( | ||
| 1887 | '[email protected]', | ||
| 1888 | '[email protected]' | ||
| 1889 | ) | ||
| 1890 | ) | ||
| 1891 | # create workspace role | ||
| 1892 |         params = { | ||
| 1893 | 'user_id': None, | ||
| 1894 | 'user_email': None, | ||
| 1895 | 'user_public_name': None, | ||
| 1896 | 'role': 'content-manager', | ||
| 1897 | } | ||
| 1898 | res = self.testapp.post_json( | ||
| 1899 | '/api/v2/workspaces/1/members', | ||
| 1900 | status=400, | ||
| 1901 | params=params, | ||
| 1902 | ) | ||
| 1903 | assert isinstance(res.json, dict) | ||
| 1904 | assert 'code' in res.json.keys() | ||
| 1905 | assert res.json_body['code'] == error.USER_NOT_FOUND | ||
| 1906 | |||
| 1907 | def test_api__create_workspace_member_role__err_400__wrong_user_id_and_not_notification(self): # nopep8 | ||
| 1908 | """ | ||
| 1909 | Create workspace member role | ||
| 1910 | :return: | ||
| 1911 | """ | ||
| 1912 | self.testapp.authorization = ( | ||
| 1913 | 'Basic', | ||
| 1914 | ( | ||
| 1915 | '[email protected]', | ||
| 1916 | '[email protected]' | ||
| 1917 | ) | ||
| 1918 | ) | ||
| 1919 | # create workspace role | ||
| 1920 |         params = { | ||
| 1921 | 'user_id': 47, | ||
| 1922 | 'user_email': None, | ||
| 1923 | 'user_public_name': None, | ||
| 1924 | 'role': 'content-manager', | ||
| 1925 | } | ||
| 1926 | res = self.testapp.post_json( | ||
| 1927 | '/api/v2/workspaces/1/members', | ||
| 1928 | status=400, | ||
| 1929 | params=params, | ||
| 1930 | ) | ||
| 1931 | assert isinstance(res.json, dict) | ||
| 1932 | assert 'code' in res.json.keys() | ||
| 1933 | assert res.json_body['code'] == error.USER_NOT_FOUND | ||
| 1934 | |||
| 1935 | def test_api__create_workspace_member_role__err_400__notification_disabled_user_not_found(self): # nopep8 | ||
| 1936 | """ | ||
| 1937 | Create workspace member role | ||
| 1938 | :return: | ||
| 1939 | """ | ||
| 1940 | self.testapp.authorization = ( | ||
| 1941 | 'Basic', | ||
| 1942 | ( | ||
| 1943 | '[email protected]', | ||
| 1944 | '[email protected]' | ||
| 1945 | ) | ||
| 1946 | ) | ||
| 1947 | # create workspace role | ||
| 1948 |         params = { | ||
| 1949 | 'user_id': None, | ||
| 1950 | 'user_email': '[email protected]', | ||
| 1951 | 'user_public_name': None, | ||
| 1952 | 'role': 'content-manager', | ||
| 1953 | } | ||
| 1954 | res = self.testapp.post_json( | ||
| 1955 | '/api/v2/workspaces/1/members', | ||
| 1956 | status=400, | ||
| 1957 | params=params, | ||
| 1958 | ) | ||
| 1959 | assert isinstance(res.json, dict) | ||
| 1960 | assert 'code' in res.json.keys() | ||
| 1961 | assert res.json_body['code'] == error.USER_NOT_FOUND | ||
| 1962 | |||
| 1963 | View Code Duplication | def test_api__update_workspace_member_role__ok_200__nominal_case(self): | |
| 1964 | """ | ||
| 1965 | Update worskpace member role | ||
| 1966 | """ | ||
| 1967 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 1968 | admin = dbsession.query(models.User) \ | ||
| 1969 | .filter(models.User.email == '[email protected]') \ | ||
| 1970 | .one() | ||
| 1971 | uapi = UserApi( | ||
| 1972 | current_user=admin, | ||
| 1973 | session=dbsession, | ||
| 1974 | config=self.app_config, | ||
| 1975 | ) | ||
| 1976 | gapi = GroupApi( | ||
| 1977 | current_user=admin, | ||
| 1978 | session=dbsession, | ||
| 1979 | config=self.app_config, | ||
| 1980 | ) | ||
| 1981 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 1982 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 1983 |         user2 = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 1984 | workspace_api = WorkspaceApi( | ||
| 1985 | current_user=admin, | ||
| 1986 | session=dbsession, | ||
| 1987 | config=self.app_config, | ||
| 1988 | show_deleted=True, | ||
| 1989 | ) | ||
| 1990 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 1991 | rapi = RoleApi( | ||
| 1992 | current_user=None, | ||
| 1993 | session=dbsession, | ||
| 1994 | config=self.app_config, | ||
| 1995 | ) | ||
| 1996 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 1997 | rapi.create_one(user2, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 1998 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 1999 | transaction.commit() | ||
| 2000 | # before | ||
| 2001 | self.testapp.authorization = ( | ||
| 2002 | 'Basic', | ||
| 2003 | ( | ||
| 2004 | '[email protected]', | ||
| 2005 | '[email protected]' | ||
| 2006 | ) | ||
| 2007 | ) | ||
| 2008 | self.testapp.get( | ||
| 2009 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2010 | workspace_id=workspace.workspace_id, | ||
| 2011 | user_id=user2.user_id | ||
| 2012 | ), | ||
| 2013 | status=200, | ||
| 2014 | ) | ||
| 2015 | # update workspace role | ||
| 2016 |         params = { | ||
| 2017 | 'role': 'content-manager', | ||
| 2018 | } | ||
| 2019 | res = self.testapp.put_json( | ||
| 2020 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2021 | workspace_id=workspace.workspace_id, | ||
| 2022 | user_id=user2.user_id | ||
| 2023 | ), | ||
| 2024 | status=200, | ||
| 2025 | params=params, | ||
| 2026 | ) | ||
| 2027 | user_role = res.json_body | ||
| 2028 | assert user_role['role'] == 'content-manager' | ||
| 2029 | assert user_role['user_id'] == user2.user_id | ||
| 2030 | assert user_role['workspace_id'] == workspace.workspace_id | ||
| 2031 | # after | ||
| 2032 | res = self.testapp.get( | ||
| 2033 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2034 | workspace_id=workspace.workspace_id, | ||
| 2035 | user_id=user2.user_id, | ||
| 2036 | ), | ||
| 2037 | status=200 | ||
| 2038 | ).json_body # nopep8 | ||
| 2039 | user_role = res | ||
| 2040 | assert user_role['role'] == 'content-manager' | ||
| 2041 | assert user_role['do_notify'] is False | ||
| 2042 | assert user_role['user_id'] == user2.user_id | ||
| 2043 | assert user_role['workspace_id'] == workspace.workspace_id | ||
| 2044 | |||
| 2045 | View Code Duplication | def test_api__update_workspace_member_role__err_400__role_not_exist(self): | |
| 2046 | """ | ||
| 2047 | Update worskpace member role | ||
| 2048 | """ | ||
| 2049 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2050 | admin = dbsession.query(models.User) \ | ||
| 2051 | .filter(models.User.email == '[email protected]') \ | ||
| 2052 | .one() | ||
| 2053 | uapi = UserApi( | ||
| 2054 | current_user=admin, | ||
| 2055 | session=dbsession, | ||
| 2056 | config=self.app_config, | ||
| 2057 | ) | ||
| 2058 | gapi = GroupApi( | ||
| 2059 | current_user=admin, | ||
| 2060 | session=dbsession, | ||
| 2061 | config=self.app_config, | ||
| 2062 | ) | ||
| 2063 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2064 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2065 |         user2 = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2066 | workspace_api = WorkspaceApi( | ||
| 2067 | current_user=admin, | ||
| 2068 | session=dbsession, | ||
| 2069 | config=self.app_config, | ||
| 2070 | show_deleted=True, | ||
| 2071 | ) | ||
| 2072 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2073 | rapi = RoleApi( | ||
| 2074 | current_user=None, | ||
| 2075 | session=dbsession, | ||
| 2076 | config=self.app_config, | ||
| 2077 | ) | ||
| 2078 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 2079 | transaction.commit() | ||
| 2080 | # update workspace role | ||
| 2081 | self.testapp.authorization = ( | ||
| 2082 | 'Basic', | ||
| 2083 | ( | ||
| 2084 | '[email protected]', | ||
| 2085 | '[email protected]' | ||
| 2086 | ) | ||
| 2087 | ) | ||
| 2088 |         params = { | ||
| 2089 | 'role': 'content-manager', | ||
| 2090 | } | ||
| 2091 | res = self.testapp.put_json( | ||
| 2092 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2093 | workspace_id=workspace.workspace_id, | ||
| 2094 | user_id=user2.user_id | ||
| 2095 | ), | ||
| 2096 | status=400, | ||
| 2097 | params=params, | ||
| 2098 | ) | ||
| 2099 | assert isinstance(res.json, dict) | ||
| 2100 | assert 'code' in res.json.keys() | ||
| 2101 | assert res.json_body['code'] == error.USER_ROLE_NOT_FOUND | ||
| 2102 | |||
| 2103 | View Code Duplication | def test_api__update_workspace_member_role__ok_200__as_admin(self): | |
| 2104 | """ | ||
| 2105 | Update worskpace member role | ||
| 2106 | """ | ||
| 2107 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2108 | admin = dbsession.query(models.User) \ | ||
| 2109 | .filter(models.User.email == '[email protected]') \ | ||
| 2110 | .one() | ||
| 2111 | uapi = UserApi( | ||
| 2112 | current_user=admin, | ||
| 2113 | session=dbsession, | ||
| 2114 | config=self.app_config, | ||
| 2115 | ) | ||
| 2116 | gapi = GroupApi( | ||
| 2117 | current_user=admin, | ||
| 2118 | session=dbsession, | ||
| 2119 | config=self.app_config, | ||
| 2120 | ) | ||
| 2121 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2122 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2123 |         user2 = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2124 | workspace_api = WorkspaceApi( | ||
| 2125 | current_user=admin, | ||
| 2126 | session=dbsession, | ||
| 2127 | config=self.app_config, | ||
| 2128 | show_deleted=True, | ||
| 2129 | ) | ||
| 2130 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2131 | rapi = RoleApi( | ||
| 2132 | current_user=None, | ||
| 2133 | session=dbsession, | ||
| 2134 | config=self.app_config, | ||
| 2135 | ) | ||
| 2136 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2137 | rapi.create_one(user2, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 2138 | rapi.delete_one(admin.user_id, workspace.workspace_id) | ||
| 2139 | transaction.commit() | ||
| 2140 | # before | ||
| 2141 | self.testapp.authorization = ( | ||
| 2142 | 'Basic', | ||
| 2143 | ( | ||
| 2144 | '[email protected]', | ||
| 2145 | '[email protected]' | ||
| 2146 | ) | ||
| 2147 | ) | ||
| 2148 | self.testapp.get( | ||
| 2149 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2150 | workspace_id=workspace.workspace_id, | ||
| 2151 | user_id=user2.user_id | ||
| 2152 | ), | ||
| 2153 | status=200, | ||
| 2154 | ) | ||
| 2155 | # update workspace role | ||
| 2156 |         params = { | ||
| 2157 | 'role': 'content-manager', | ||
| 2158 | } | ||
| 2159 | res = self.testapp.put_json( | ||
| 2160 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2161 | workspace_id=workspace.workspace_id, | ||
| 2162 | user_id=user2.user_id | ||
| 2163 | ), | ||
| 2164 | status=200, | ||
| 2165 | params=params, | ||
| 2166 | ) | ||
| 2167 | user_role = res.json_body | ||
| 2168 | assert user_role['role'] == 'content-manager' | ||
| 2169 | assert user_role['user_id'] == user2.user_id | ||
| 2170 | assert user_role['workspace_id'] == workspace.workspace_id | ||
| 2171 | # after | ||
| 2172 | res = self.testapp.get( | ||
| 2173 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2174 | workspace_id=workspace.workspace_id, | ||
| 2175 | user_id=user2.user_id, | ||
| 2176 | ), | ||
| 2177 | status=200 | ||
| 2178 | ).json_body # nopep8 | ||
| 2179 | user_role = res | ||
| 2180 | assert user_role['role'] == 'content-manager' | ||
| 2181 | assert user_role['do_notify'] is False | ||
| 2182 | assert user_role['user_id'] == user2.user_id | ||
| 2183 | assert user_role['workspace_id'] == workspace.workspace_id | ||
| 2184 | |||
| 2185 | def test_api__delete_workspace_member_role__ok_200__as_admin(self): | ||
| 2186 | """ | ||
| 2187 | Delete worskpace member role | ||
| 2188 | """ | ||
| 2189 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2190 | admin = dbsession.query(models.User) \ | ||
| 2191 | .filter(models.User.email == '[email protected]') \ | ||
| 2192 | .one() | ||
| 2193 | uapi = UserApi( | ||
| 2194 | current_user=admin, | ||
| 2195 | session=dbsession, | ||
| 2196 | config=self.app_config, | ||
| 2197 | ) | ||
| 2198 | gapi = GroupApi( | ||
| 2199 | current_user=admin, | ||
| 2200 | session=dbsession, | ||
| 2201 | config=self.app_config, | ||
| 2202 | ) | ||
| 2203 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2204 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2205 | workspace_api = WorkspaceApi( | ||
| 2206 | current_user=admin, | ||
| 2207 | session=dbsession, | ||
| 2208 | config=self.app_config, | ||
| 2209 | show_deleted=True, | ||
| 2210 | ) | ||
| 2211 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2212 | rapi = RoleApi( | ||
| 2213 | current_user=admin, | ||
| 2214 | session=dbsession, | ||
| 2215 | config=self.app_config, | ||
| 2216 | ) | ||
| 2217 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2218 | transaction.commit() | ||
| 2219 | |||
| 2220 | self.testapp.authorization = ( | ||
| 2221 | 'Basic', | ||
| 2222 | ( | ||
| 2223 | '[email protected]', | ||
| 2224 | '[email protected]' | ||
| 2225 | ) | ||
| 2226 | ) | ||
| 2227 | res = self.testapp.delete( | ||
| 2228 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2229 | workspace_id=workspace.workspace_id, | ||
| 2230 | user_id=user.user_id, | ||
| 2231 | ), | ||
| 2232 | status=204, | ||
| 2233 | ) | ||
| 2234 | # after | ||
| 2235 |         roles = self.testapp.get('/api/v2/workspaces/{}/members'.format(workspace.workspace_id), status=200).json_body   # nopep8 | ||
| 2236 | for role in roles: | ||
| 2237 | assert role['user_id'] != user.user_id | ||
| 2238 | |||
| 2239 | View Code Duplication | def test_api__delete_workspace_member_role__ok_200__nominal_case(self): | |
| 2240 | """ | ||
| 2241 | Delete worskpace member role | ||
| 2242 | """ | ||
| 2243 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2244 | admin = dbsession.query(models.User) \ | ||
| 2245 | .filter(models.User.email == '[email protected]') \ | ||
| 2246 | .one() | ||
| 2247 | uapi = UserApi( | ||
| 2248 | current_user=admin, | ||
| 2249 | session=dbsession, | ||
| 2250 | config=self.app_config, | ||
| 2251 | ) | ||
| 2252 | gapi = GroupApi( | ||
| 2253 | current_user=admin, | ||
| 2254 | session=dbsession, | ||
| 2255 | config=self.app_config, | ||
| 2256 | ) | ||
| 2257 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2258 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2259 |         user2 = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2260 | workspace_api = WorkspaceApi( | ||
| 2261 | current_user=admin, | ||
| 2262 | session=dbsession, | ||
| 2263 | config=self.app_config, | ||
| 2264 | show_deleted=True, | ||
| 2265 | ) | ||
| 2266 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2267 | rapi = RoleApi( | ||
| 2268 | current_user=admin, | ||
| 2269 | session=dbsession, | ||
| 2270 | config=self.app_config, | ||
| 2271 | ) | ||
| 2272 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2273 | rapi.create_one(user2, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 2274 | transaction.commit() | ||
| 2275 | |||
| 2276 | self.testapp.authorization = ( | ||
| 2277 | 'Basic', | ||
| 2278 | ( | ||
| 2279 | '[email protected]', | ||
| 2280 | '[email protected]' | ||
| 2281 | ) | ||
| 2282 | ) | ||
| 2283 | res = self.testapp.delete( | ||
| 2284 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2285 | workspace_id=workspace.workspace_id, | ||
| 2286 | user_id=user2.user_id, | ||
| 2287 | ), | ||
| 2288 | status=204, | ||
| 2289 | ) | ||
| 2290 | # after | ||
| 2291 |         roles = self.testapp.get('/api/v2/workspaces/{}/members'.format(workspace.workspace_id), status=200).json_body   # nopep8 | ||
| 2292 | for role in roles: | ||
| 2293 | assert role['user_id'] != user2.user_id | ||
| 2294 | |||
| 2295 | View Code Duplication | def test_api__delete_workspace_member_role__err_400__role_not_exist(self): | |
| 2296 | """ | ||
| 2297 | Delete worskpace member role | ||
| 2298 | """ | ||
| 2299 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2300 | admin = dbsession.query(models.User) \ | ||
| 2301 | .filter(models.User.email == '[email protected]') \ | ||
| 2302 | .one() | ||
| 2303 | uapi = UserApi( | ||
| 2304 | current_user=admin, | ||
| 2305 | session=dbsession, | ||
| 2306 | config=self.app_config, | ||
| 2307 | ) | ||
| 2308 | gapi = GroupApi( | ||
| 2309 | current_user=admin, | ||
| 2310 | session=dbsession, | ||
| 2311 | config=self.app_config, | ||
| 2312 | ) | ||
| 2313 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2314 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2315 |         user2 = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2316 | workspace_api = WorkspaceApi( | ||
| 2317 | current_user=admin, | ||
| 2318 | session=dbsession, | ||
| 2319 | config=self.app_config, | ||
| 2320 | show_deleted=True, | ||
| 2321 | ) | ||
| 2322 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2323 | rapi = RoleApi( | ||
| 2324 | current_user=admin, | ||
| 2325 | session=dbsession, | ||
| 2326 | config=self.app_config, | ||
| 2327 | ) | ||
| 2328 | transaction.commit() | ||
| 2329 | |||
| 2330 | self.testapp.authorization = ( | ||
| 2331 | 'Basic', | ||
| 2332 | ( | ||
| 2333 | '[email protected]', | ||
| 2334 | '[email protected]' | ||
| 2335 | ) | ||
| 2336 | ) | ||
| 2337 | res = self.testapp.delete( | ||
| 2338 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2339 | workspace_id=workspace.workspace_id, | ||
| 2340 | user_id=user2.user_id, | ||
| 2341 | ), | ||
| 2342 | status=400, | ||
| 2343 | ) | ||
| 2344 | assert isinstance(res.json, dict) | ||
| 2345 | assert 'code' in res.json.keys() | ||
| 2346 | assert res.json_body['code'] == error.USER_ROLE_NOT_FOUND | ||
| 2347 | |||
| 2348 | View Code Duplication | def test_api__delete_workspace_member_role__err_400__workspace_manager_itself(self): # nopep8 | |
| 2349 | """ | ||
| 2350 | Delete worskpace member role. | ||
| 2351 | Unallow to delete himself as workspace_manager | ||
| 2352 | """ | ||
| 2353 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2354 | admin = dbsession.query(models.User) \ | ||
| 2355 | .filter(models.User.email == '[email protected]') \ | ||
| 2356 | .one() | ||
| 2357 | uapi = UserApi( | ||
| 2358 | current_user=admin, | ||
| 2359 | session=dbsession, | ||
| 2360 | config=self.app_config, | ||
| 2361 | ) | ||
| 2362 | gapi = GroupApi( | ||
| 2363 | current_user=admin, | ||
| 2364 | session=dbsession, | ||
| 2365 | config=self.app_config, | ||
| 2366 | ) | ||
| 2367 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2368 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2369 |         user2 = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2370 | workspace_api = WorkspaceApi( | ||
| 2371 | current_user=admin, | ||
| 2372 | session=dbsession, | ||
| 2373 | config=self.app_config, | ||
| 2374 | show_deleted=True, | ||
| 2375 | ) | ||
| 2376 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2377 | rapi = RoleApi( | ||
| 2378 | current_user=admin, | ||
| 2379 | session=dbsession, | ||
| 2380 | config=self.app_config, | ||
| 2381 | ) | ||
| 2382 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2383 | rapi.create_one(user2, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2384 | transaction.commit() | ||
| 2385 | |||
| 2386 | self.testapp.authorization = ( | ||
| 2387 | 'Basic', | ||
| 2388 | ( | ||
| 2389 | '[email protected]', | ||
| 2390 | '[email protected]' | ||
| 2391 | ) | ||
| 2392 | ) | ||
| 2393 | res = self.testapp.delete( | ||
| 2394 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2395 | workspace_id=workspace.workspace_id, | ||
| 2396 | user_id=user2.user_id, | ||
| 2397 | ), | ||
| 2398 | status=400, | ||
| 2399 | ) | ||
| 2400 | assert res.json_body['code'] == error.USER_CANT_REMOVE_IS_OWN_ROLE_IN_WORKSPACE # nopep8 | ||
| 2401 | # after | ||
| 2402 |         roles = self.testapp.get('/api/v2/workspaces/{}/members'.format(workspace.workspace_id), status=200).json_body   # nopep8 | ||
| 2403 | assert user2.user_id in [role['user_id'] for role in roles] | ||
| 2404 | |||
| 2405 | def test_api__delete_workspace_member_role__err_400__simple_user(self): | ||
| 2406 | """ | ||
| 2407 | Delete worskpace member role | ||
| 2408 | """ | ||
| 2409 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2410 | admin = dbsession.query(models.User) \ | ||
| 2411 | .filter(models.User.email == '[email protected]') \ | ||
| 2412 | .one() | ||
| 2413 | uapi = UserApi( | ||
| 2414 | current_user=admin, | ||
| 2415 | session=dbsession, | ||
| 2416 | config=self.app_config, | ||
| 2417 | ) | ||
| 2418 | gapi = GroupApi( | ||
| 2419 | current_user=admin, | ||
| 2420 | session=dbsession, | ||
| 2421 | config=self.app_config, | ||
| 2422 | ) | ||
| 2423 |         groups = [gapi.get_one_with_name('users')] | ||
| 2424 |         user2 = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2425 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2426 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2427 | workspace_api = WorkspaceApi( | ||
| 2428 | current_user=admin, | ||
| 2429 | session=dbsession, | ||
| 2430 | config=self.app_config, | ||
| 2431 | show_deleted=True, | ||
| 2432 | ) | ||
| 2433 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2434 | rapi = RoleApi( | ||
| 2435 | current_user=admin, | ||
| 2436 | session=dbsession, | ||
| 2437 | config=self.app_config, | ||
| 2438 | ) | ||
| 2439 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2440 | rapi.create_one(user2, workspace, UserRoleInWorkspace.READER, False) # nopep8 | ||
| 2441 | transaction.commit() | ||
| 2442 | |||
| 2443 | self.testapp.authorization = ( | ||
| 2444 | 'Basic', | ||
| 2445 | ( | ||
| 2446 | '[email protected]', | ||
| 2447 | '[email protected]' | ||
| 2448 | ) | ||
| 2449 | ) | ||
| 2450 | res = self.testapp.delete( | ||
| 2451 |             '/api/v2/workspaces/{workspace_id}/members/{user_id}'.format( | ||
| 2452 | workspace_id=workspace.workspace_id, | ||
| 2453 | user_id=user.user_id, | ||
| 2454 | ), | ||
| 2455 | status=403, | ||
| 2456 | ) | ||
| 2457 | assert isinstance(res.json, dict) | ||
| 2458 | assert 'code' in res.json.keys() | ||
| 2459 | assert res.json_body['code'] == error.INSUFFICIENT_USER_ROLE_IN_WORKSPACE | ||
| 2460 | # after | ||
| 2461 | roles = self.testapp.get( | ||
| 2462 |             '/api/v2/workspaces/{workspace_id}/members'.format( | ||
| 2463 | workspace_id=workspace.workspace_id | ||
| 2464 | ), | ||
| 2465 | status=200 | ||
| 2466 | ).json_body | ||
| 2467 | assert len([role for role in roles if role['user_id'] == user.user_id]) == 1 # nopep8 | ||
| 2468 | |||
| 2469 | |||
| 2470 | class TestUserInvitationWithMailActivatedSync(FunctionalTest): | ||
| 2471 | |||
| 2472 | fixtures = [BaseFixture, ContentFixtures] | ||
| 2473 | config_section = 'functional_test_with_mail_test_sync' | ||
| 2474 | |||
| 2475 | def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8 | ||
| 2476 | """ | ||
| 2477 | Create workspace member role | ||
| 2478 | :return: | ||
| 2479 | """ | ||
| 2480 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2481 | admin = dbsession.query(models.User) \ | ||
| 2482 | .filter(models.User.email == '[email protected]') \ | ||
| 2483 | .one() | ||
| 2484 | uapi = UserApi( | ||
| 2485 | current_user=admin, | ||
| 2486 | session=dbsession, | ||
| 2487 | config=self.app_config, | ||
| 2488 | ) | ||
| 2489 | gapi = GroupApi( | ||
| 2490 | current_user=admin, | ||
| 2491 | session=dbsession, | ||
| 2492 | config=self.app_config, | ||
| 2493 | ) | ||
| 2494 |         groups = [gapi.get_one_with_name('trusted-users')] | ||
| 2495 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2496 | workspace_api = WorkspaceApi( | ||
| 2497 | current_user=admin, | ||
| 2498 | session=dbsession, | ||
| 2499 | config=self.app_config, | ||
| 2500 | show_deleted=True, | ||
| 2501 | ) | ||
| 2502 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2503 | rapi = RoleApi( | ||
| 2504 | current_user=admin, | ||
| 2505 | session=dbsession, | ||
| 2506 | config=self.app_config, | ||
| 2507 | ) | ||
| 2508 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2509 | transaction.commit() | ||
| 2510 | |||
| 2511 |         requests.delete('http://127.0.0.1:8025/api/v1/messages') | ||
| 2512 | self.testapp.authorization = ( | ||
| 2513 | 'Basic', | ||
| 2514 | ( | ||
| 2515 | '[email protected]', | ||
| 2516 | '[email protected]' | ||
| 2517 | ) | ||
| 2518 | ) | ||
| 2519 | # create workspace role | ||
| 2520 |         params = { | ||
| 2521 | 'user_id': None, | ||
| 2522 | 'user_public_name': None, | ||
| 2523 | 'user_email': '[email protected]', | ||
| 2524 | 'role': 'content-manager', | ||
| 2525 | } | ||
| 2526 | res = self.testapp.post_json( | ||
| 2527 |             '/api/v2/workspaces/{}/members'.format(workspace.workspace_id), | ||
| 2528 | status=200, | ||
| 2529 | params=params, | ||
| 2530 | ) | ||
| 2531 | user_role_found = res.json_body | ||
| 2532 | assert user_role_found['role'] == 'content-manager' | ||
| 2533 | assert user_role_found['user_id'] | ||
| 2534 | user_id = user_role_found['user_id'] | ||
| 2535 | assert user_role_found['workspace_id'] == workspace.workspace_id | ||
| 2536 | assert user_role_found['newly_created'] is True | ||
| 2537 | assert user_role_found['email_sent'] is True | ||
| 2538 | assert user_role_found['do_notify'] is False | ||
| 2539 | |||
| 2540 | self.testapp.authorization = ( | ||
| 2541 | 'Basic', | ||
| 2542 | ( | ||
| 2543 | '[email protected]', | ||
| 2544 | '[email protected]' | ||
| 2545 | ) | ||
| 2546 | ) | ||
| 2547 | res = self.testapp.get( | ||
| 2548 |             '/api/v2/users/{}'.format(user_id), | ||
| 2549 | status=200, | ||
| 2550 | ) | ||
| 2551 | res = res.json_body | ||
| 2552 | assert res['profile'] == 'users' | ||
| 2553 | |||
| 2554 | # check mail received | ||
| 2555 |         response = requests.get('http://127.0.0.1:8025/api/v1/messages') | ||
| 2556 | response = response.json() | ||
| 2557 | assert len(response) == 1 | ||
| 2558 | headers = response[0]['Content']['Headers'] | ||
| 2559 | assert headers['From'][0] == 'Tracim Notifications <test_user_from+0@localhost>' # nopep8 | ||
| 2560 | assert headers['To'][0] == 'bob <[email protected]>' | ||
| 2561 | assert headers['Subject'][0] == '[TRACIM] Created account' | ||
| 2562 | |||
| 2563 | # TODO - G.M - 2018-08-02 - Place cleanup outside of the test | ||
| 2564 |         requests.delete('http://127.0.0.1:8025/api/v1/messages') | ||
| 2565 | |||
| 2566 | def test_api__create_workspace_member_role__err_400__user_not_found_as_simple_user(self): # nopep8 | ||
| 2567 | """ | ||
| 2568 | Create workspace member role | ||
| 2569 | :return: | ||
| 2570 | """ | ||
| 2571 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 2572 | admin = dbsession.query(models.User) \ | ||
| 2573 | .filter(models.User.email == '[email protected]') \ | ||
| 2574 | .one() | ||
| 2575 | uapi = UserApi( | ||
| 2576 | current_user=admin, | ||
| 2577 | session=dbsession, | ||
| 2578 | config=self.app_config, | ||
| 2579 | ) | ||
| 2580 | gapi = GroupApi( | ||
| 2581 | current_user=admin, | ||
| 2582 | session=dbsession, | ||
| 2583 | config=self.app_config, | ||
| 2584 | ) | ||
| 2585 |         groups = [gapi.get_one_with_name('users')] | ||
| 2586 |         user = uapi.create_user('[email protected]', password='[email protected]', do_save=True, do_notify=False, groups=groups)  # nopep8 | ||
| 2587 | workspace_api = WorkspaceApi( | ||
| 2588 | current_user=admin, | ||
| 2589 | session=dbsession, | ||
| 2590 | config=self.app_config, | ||
| 2591 | show_deleted=True, | ||
| 2592 | ) | ||
| 2593 |         workspace = workspace_api.create_workspace('test', save_now=True)  # nopep8 | ||
| 2594 | rapi = RoleApi( | ||
| 2595 | current_user=admin, | ||
| 2596 | session=dbsession, | ||
| 2597 | config=self.app_config, | ||
| 2598 | ) | ||
| 2599 | rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) # nopep8 | ||
| 2600 | transaction.commit() | ||
| 2601 | |||
| 2602 |         requests.delete('http://127.0.0.1:8025/api/v1/messages') | ||
| 2603 | self.testapp.authorization = ( | ||
| 2604 | 'Basic', | ||
| 2605 | ( | ||
| 2606 | '[email protected]', | ||
| 2607 | '[email protected]' | ||
| 2608 | ) | ||
| 2609 | ) | ||
| 2610 | # create workspace role | ||
| 2611 |         params = { | ||
| 2612 | 'user_id': None, | ||
| 2613 | 'user_public_name': None, | ||
| 2614 | 'user_email': '[email protected]', | ||
| 2615 | 'role': 'content-manager', | ||
| 2616 | } | ||
| 2617 | res = self.testapp.post_json( | ||
| 2618 |             '/api/v2/workspaces/{}/members'.format(workspace.workspace_id), | ||
| 2619 | status=400, | ||
| 2620 | params=params, | ||
| 2621 | ) | ||
| 2622 | assert isinstance(res.json, dict) | ||
| 2623 | assert 'code' in res.json.keys() | ||
| 2624 | assert res.json_body['code'] == error.USER_NOT_FOUND | ||
| 2625 | |||
| 2626 | |||
| 2627 | class TestUserInvitationWithMailActivatedASync(FunctionalTest): | ||
| 2628 | |||
| 2629 | fixtures = [BaseFixture, ContentFixtures] | ||
| 2630 | config_section = 'functional_test_with_mail_test_async' | ||
| 2631 | |||
| 2632 | def test_api__create_workspace_member_role__ok_200__new_user(self): # nopep8 | ||
| 2633 | """ | ||
| 2634 | Create workspace member role | ||
| 2635 | :return: | ||
| 2636 | """ | ||
| 2637 | self.testapp.authorization = ( | ||
| 2638 | 'Basic', | ||
| 2639 | ( | ||
| 2640 | '[email protected]', | ||
| 2641 | '[email protected]' | ||
| 2642 | ) | ||
| 2643 | ) | ||
| 2644 | # create workspace role | ||
| 2645 |         params = { | ||
| 2646 | 'user_id': None, | ||
| 2647 | 'user_public_name': None, | ||
| 2648 | 'user_email': '[email protected]', | ||
| 2649 | 'role': 'content-manager', | ||
| 2650 | } | ||
| 2651 | res = self.testapp.post_json( | ||
| 2652 | '/api/v2/workspaces/1/members', | ||
| 2653 | status=200, | ||
| 2654 | params=params, | ||
| 2655 | ) | ||
| 2656 | user_role_found = res.json_body | ||
| 2657 | assert user_role_found['newly_created'] is True | ||
| 2658 | assert user_role_found['email_sent'] is False | ||
| 2659 | |||
| 2660 | |||
| 2661 | class TestWorkspaceContents(FunctionalTest): | ||
| 2662 | """ | ||
| 2663 |     Tests for /api/v2/workspaces/{workspace_id}/contents endpoint | ||
| 2664 | """ | ||
| 2665 | |||
| 2666 | fixtures = [BaseFixture, ContentFixtures] | ||
| 2667 | |||
| 2668 | def test_api__get_workspace_content__ok_200__get_default(self): | ||
| 2669 | """ | ||
| 2670 | Check obtain workspace contents with defaults filters | ||
| 2671 | """ | ||
| 2672 | self.testapp.authorization = ( | ||
| 2673 | 'Basic', | ||
| 2674 | ( | ||
| 2675 | '[email protected]', | ||
| 2676 | '[email protected]' | ||
| 2677 | ) | ||
| 2678 | ) | ||
| 2679 |         res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body   # nopep8 | ||
| 2680 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 2681 | assert len(res) == 3 | ||
| 2682 | content = res[0] | ||
| 2683 | assert content['content_id'] == 11 | ||
| 2684 | assert content['content_type'] == 'html-document' | ||
| 2685 | assert content['is_archived'] is False | ||
| 2686 | assert content['is_deleted'] is False | ||
| 2687 | assert content['label'] == 'Current Menu' | ||
| 2688 | assert content['parent_id'] == 2 | ||
| 2689 | assert content['show_in_ui'] is True | ||
| 2690 | assert content['slug'] == 'current-menu' | ||
| 2691 | assert content['status'] == 'open' | ||
| 2692 | assert content['modified'] | ||
| 2693 | assert content['created'] | ||
| 2694 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2695 | assert content['workspace_id'] == 1 | ||
| 2696 | content = res[1] | ||
| 2697 | assert content['content_id'] == 2 | ||
| 2698 | assert content['content_type'] == 'folder' | ||
| 2699 | assert content['is_archived'] is False | ||
| 2700 | assert content['is_deleted'] is False | ||
| 2701 | assert content['label'] == 'Menus' | ||
| 2702 | assert content['parent_id'] is None | ||
| 2703 | assert content['show_in_ui'] is True | ||
| 2704 | assert content['slug'] == 'menus' | ||
| 2705 | assert content['status'] == 'open' | ||
| 2706 | assert len(content['sub_content_types']) > 1 | ||
| 2707 | assert 'comment' in content['sub_content_types'] | ||
| 2708 | assert 'folder' in content['sub_content_types'] | ||
| 2709 | assert content['workspace_id'] == 1 | ||
| 2710 | assert content['modified'] | ||
| 2711 | assert content['created'] | ||
| 2712 | content = res[2] | ||
| 2713 | assert content['content_id'] == 1 | ||
| 2714 | assert content['content_type'] == 'folder' | ||
| 2715 | assert content['is_archived'] is False | ||
| 2716 | assert content['is_deleted'] is False | ||
| 2717 | assert content['label'] == 'Tools' | ||
| 2718 | assert content['parent_id'] is None | ||
| 2719 | assert content['show_in_ui'] is True | ||
| 2720 | assert content['slug'] == 'tools' | ||
| 2721 | assert content['status'] == 'open' | ||
| 2722 | assert len(content['sub_content_types']) > 1 | ||
| 2723 | assert 'comment' in content['sub_content_types'] | ||
| 2724 | assert 'folder' in content['sub_content_types'] | ||
| 2725 | assert content['workspace_id'] == 1 | ||
| 2726 | assert content['modified'] | ||
| 2727 | assert content['created'] | ||
| 2728 | |||
| 2729 | def test_api__get_workspace_content__ok_200__get_default_html_documents(self): | ||
| 2730 | """ | ||
| 2731 | Check obtain workspace contents with defaults filters + content_filter | ||
| 2732 | """ | ||
| 2733 | self.testapp.authorization = ( | ||
| 2734 | 'Basic', | ||
| 2735 | ( | ||
| 2736 | '[email protected]', | ||
| 2737 | '[email protected]' | ||
| 2738 | ) | ||
| 2739 | ) | ||
| 2740 |         params = { | ||
| 2741 | 'content_type': 'html-document', | ||
| 2742 | } | ||
| 2743 |         res = self.testapp.get('/api/v2/workspaces/1/contents', status=200, params=params).json_body   # nopep8 | ||
| 2744 | assert len(res) == 1 | ||
| 2745 | content = res[0] | ||
| 2746 | assert content | ||
| 2747 | assert content['content_id'] == 11 | ||
| 2748 | assert content['content_type'] == 'html-document' | ||
| 2749 | assert content['is_archived'] is False | ||
| 2750 | assert content['is_deleted'] is False | ||
| 2751 | assert content['label'] == 'Current Menu' | ||
| 2752 | assert content['parent_id'] == 2 | ||
| 2753 | assert content['show_in_ui'] is True | ||
| 2754 | assert content['slug'] == 'current-menu' | ||
| 2755 | assert content['status'] == 'open' | ||
| 2756 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2757 | assert content['workspace_id'] == 1 | ||
| 2758 | assert content['modified'] | ||
| 2759 | assert content['created'] | ||
| 2760 | |||
| 2761 | def test_api__get_workspace_content__ok_200__get_all_root_content__legacy_html_slug(self): # nopep8 | ||
| 2762 | """ | ||
| 2763 | Check obtain workspace all root contents | ||
| 2764 | """ | ||
| 2765 | set_html_document_slug_to_legacy(self.session_factory) | ||
| 2766 |         params = { | ||
| 2767 | 'parent_id': 0, | ||
| 2768 | 'show_archived': 1, | ||
| 2769 | 'show_deleted': 1, | ||
| 2770 | 'show_active': 1, | ||
| 2771 | } | ||
| 2772 | self.testapp.authorization = ( | ||
| 2773 | 'Basic', | ||
| 2774 | ( | ||
| 2775 | '[email protected]', | ||
| 2776 | 'foobarbaz' | ||
| 2777 | ) | ||
| 2778 | ) | ||
| 2779 | res = self.testapp.get( | ||
| 2780 | '/api/v2/workspaces/3/contents', | ||
| 2781 | status=200, | ||
| 2782 | params=params, | ||
| 2783 | ).json_body # nopep8 | ||
| 2784 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 2785 | assert len(res) == 4 | ||
| 2786 | content = res[0] | ||
| 2787 | assert content['content_type'] == 'html-document' | ||
| 2788 | assert content['content_id'] == 17 | ||
| 2789 | assert content['is_archived'] is False | ||
| 2790 | assert content['is_deleted'] is True | ||
| 2791 |         assert content['label'].startswith('Bad Fruit Salad') | ||
| 2792 | assert content['parent_id'] is None | ||
| 2793 | assert content['show_in_ui'] is True | ||
| 2794 |         assert content['slug'].startswith('bad-fruit-salad') | ||
| 2795 | assert content['status'] == 'open' | ||
| 2796 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2797 | assert content['workspace_id'] == 3 | ||
| 2798 | assert content['modified'] | ||
| 2799 | assert content['created'] | ||
| 2800 | content = res[1] | ||
| 2801 | assert content['content_type'] == 'html-document' | ||
| 2802 | assert content['content_id'] == 16 | ||
| 2803 | assert content['is_archived'] is True | ||
| 2804 | assert content['is_deleted'] is False | ||
| 2805 |         assert content['label'].startswith('Fruit Salad') | ||
| 2806 | assert content['parent_id'] is None | ||
| 2807 | assert content['show_in_ui'] is True | ||
| 2808 |         assert content['slug'].startswith('fruit-salad') | ||
| 2809 | assert content['status'] == 'open' | ||
| 2810 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2811 | assert content['workspace_id'] == 3 | ||
| 2812 | assert content['modified'] | ||
| 2813 | assert content['created'] | ||
| 2814 | content = res[3] | ||
| 2815 | assert content['content_type'] == 'html-document' | ||
| 2816 | assert content['content_id'] == 15 | ||
| 2817 | assert content['is_archived'] is False | ||
| 2818 | assert content['is_deleted'] is False | ||
| 2819 | assert content['label'] == 'New Fruit Salad' | ||
| 2820 | assert content['parent_id'] is None | ||
| 2821 | assert content['show_in_ui'] is True | ||
| 2822 | assert content['slug'] == 'new-fruit-salad' | ||
| 2823 | assert content['status'] == 'open' | ||
| 2824 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2825 | assert content['workspace_id'] == 3 | ||
| 2826 | assert content['modified'] | ||
| 2827 | assert content['created'] | ||
| 2828 | |||
| 2829 | View Code Duplication | def test_api__get_workspace_content__ok_200__get_all_root_content(self): | |
| 2830 | """ | ||
| 2831 | Check obtain workspace all root contents | ||
| 2832 | """ | ||
| 2833 |         params = { | ||
| 2834 | 'parent_id': 0, | ||
| 2835 | 'show_archived': 1, | ||
| 2836 | 'show_deleted': 1, | ||
| 2837 | 'show_active': 1, | ||
| 2838 | } | ||
| 2839 | self.testapp.authorization = ( | ||
| 2840 | 'Basic', | ||
| 2841 | ( | ||
| 2842 | '[email protected]', | ||
| 2843 | 'foobarbaz' | ||
| 2844 | ) | ||
| 2845 | ) | ||
| 2846 | res = self.testapp.get( | ||
| 2847 | '/api/v2/workspaces/3/contents', | ||
| 2848 | status=200, | ||
| 2849 | params=params, | ||
| 2850 | ).json_body # nopep8 | ||
| 2851 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 2852 | assert len(res) == 4 | ||
| 2853 | content = res[0] | ||
| 2854 | assert content['content_type'] == 'html-document' | ||
| 2855 | assert content['content_id'] == 17 | ||
| 2856 | assert content['is_archived'] is False | ||
| 2857 | assert content['is_deleted'] is True | ||
| 2858 |         assert content['label'].startswith('Bad Fruit Salad') | ||
| 2859 | assert content['parent_id'] is None | ||
| 2860 | assert content['show_in_ui'] is True | ||
| 2861 |         assert content['slug'].startswith('bad-fruit-salad') | ||
| 2862 | assert content['status'] == 'open' | ||
| 2863 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2864 | assert content['workspace_id'] == 3 | ||
| 2865 | assert content['modified'] | ||
| 2866 | assert content['created'] | ||
| 2867 | content = res[1] | ||
| 2868 | assert content['content_type'] == 'html-document' | ||
| 2869 | assert content['content_id'] == 16 | ||
| 2870 | assert content['is_archived'] is True | ||
| 2871 | assert content['is_deleted'] is False | ||
| 2872 |         assert content['label'].startswith('Fruit Salad') | ||
| 2873 | assert content['parent_id'] is None | ||
| 2874 | assert content['show_in_ui'] is True | ||
| 2875 |         assert content['slug'].startswith('fruit-salad') | ||
| 2876 | assert content['status'] == 'open' | ||
| 2877 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2878 | assert content['workspace_id'] == 3 | ||
| 2879 | assert content['modified'] | ||
| 2880 | assert content['created'] | ||
| 2881 | content = res[3] | ||
| 2882 | assert content['content_type'] == 'html-document' | ||
| 2883 | assert content['content_id'] == 15 | ||
| 2884 | assert content['is_archived'] is False | ||
| 2885 | assert content['is_deleted'] is False | ||
| 2886 | assert content['label'] == 'New Fruit Salad' | ||
| 2887 | assert content['parent_id'] is None | ||
| 2888 | assert content['show_in_ui'] is True | ||
| 2889 | assert content['slug'] == 'new-fruit-salad' | ||
| 2890 | assert content['status'] == 'open' | ||
| 2891 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2892 | assert content['workspace_id'] == 3 | ||
| 2893 | assert content['modified'] | ||
| 2894 | assert content['created'] | ||
| 2895 | |||
| 2896 | def test_api__get_workspace_content__ok_200__get_all_root_content_filter_by_label(self): # nopep8 | ||
| 2897 | """ | ||
| 2898 | Check obtain workspace all root contents | ||
| 2899 | """ | ||
| 2900 |         params = { | ||
| 2901 | 'parent_id': 0, | ||
| 2902 | 'show_archived': 1, | ||
| 2903 | 'show_deleted': 1, | ||
| 2904 | 'show_active': 1, | ||
| 2905 | 'label': 'ew' | ||
| 2906 | } | ||
| 2907 | self.testapp.authorization = ( | ||
| 2908 | 'Basic', | ||
| 2909 | ( | ||
| 2910 | '[email protected]', | ||
| 2911 | 'foobarbaz' | ||
| 2912 | ) | ||
| 2913 | ) | ||
| 2914 | res = self.testapp.get( | ||
| 2915 | '/api/v2/workspaces/3/contents', | ||
| 2916 | status=200, | ||
| 2917 | params=params, | ||
| 2918 | ).json_body # nopep8 | ||
| 2919 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 2920 | assert len(res) == 1 | ||
| 2921 | content = res[0] | ||
| 2922 | assert content['content_type'] == 'html-document' | ||
| 2923 | assert content['content_id'] == 15 | ||
| 2924 | assert content['is_archived'] is False | ||
| 2925 | assert content['is_deleted'] is False | ||
| 2926 | assert content['label'] == 'New Fruit Salad' | ||
| 2927 | assert content['parent_id'] is None | ||
| 2928 | assert content['show_in_ui'] is True | ||
| 2929 | assert content['slug'] == 'new-fruit-salad' | ||
| 2930 | assert content['status'] == 'open' | ||
| 2931 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2932 | assert content['workspace_id'] == 3 | ||
| 2933 | assert content['modified'] | ||
| 2934 | assert content['created'] | ||
| 2935 | |||
| 2936 | def test_api__get_workspace_content__ok_200__get_only_active_root_content(self): # nopep8 | ||
| 2937 | """ | ||
| 2938 | Check obtain workspace root active contents | ||
| 2939 | """ | ||
| 2940 |         params = { | ||
| 2941 | 'parent_id': 0, | ||
| 2942 | 'show_archived': 0, | ||
| 2943 | 'show_deleted': 0, | ||
| 2944 | 'show_active': 1, | ||
| 2945 | } | ||
| 2946 | self.testapp.authorization = ( | ||
| 2947 | 'Basic', | ||
| 2948 | ( | ||
| 2949 | '[email protected]', | ||
| 2950 | 'foobarbaz' | ||
| 2951 | ) | ||
| 2952 | ) | ||
| 2953 | res = self.testapp.get( | ||
| 2954 | '/api/v2/workspaces/3/contents', | ||
| 2955 | status=200, | ||
| 2956 | params=params, | ||
| 2957 | ).json_body # nopep8 | ||
| 2958 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 2959 | assert len(res) == 2 | ||
| 2960 | content = res[1] | ||
| 2961 | assert content['content_type'] == 'html-document' | ||
| 2962 | assert content['content_id'] == 15 | ||
| 2963 | assert content['is_archived'] is False | ||
| 2964 | assert content['is_deleted'] is False | ||
| 2965 | assert content['label'] == 'New Fruit Salad' | ||
| 2966 | assert content['parent_id'] is None | ||
| 2967 | assert content['show_in_ui'] is True | ||
| 2968 | assert content['slug'] == 'new-fruit-salad' | ||
| 2969 | assert content['status'] == 'open' | ||
| 2970 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 2971 | assert content['workspace_id'] == 3 | ||
| 2972 | assert content['modified'] | ||
| 2973 | assert content['created'] | ||
| 2974 | |||
| 2975 | View Code Duplication | def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self): # nopep8 | |
| 2976 | """ | ||
| 2977 | Check obtain workspace root archived contents | ||
| 2978 | """ | ||
| 2979 |         params = { | ||
| 2980 | 'parent_id': 0, | ||
| 2981 | 'show_archived': 1, | ||
| 2982 | 'show_deleted': 0, | ||
| 2983 | 'show_active': 0, | ||
| 2984 | } | ||
| 2985 | self.testapp.authorization = ( | ||
| 2986 | 'Basic', | ||
| 2987 | ( | ||
| 2988 | '[email protected]', | ||
| 2989 | 'foobarbaz' | ||
| 2990 | ) | ||
| 2991 | ) | ||
| 2992 | res = self.testapp.get( | ||
| 2993 | '/api/v2/workspaces/3/contents', | ||
| 2994 | status=200, | ||
| 2995 | params=params, | ||
| 2996 | ).json_body # nopep8 | ||
| 2997 | assert len(res) == 1 | ||
| 2998 | content = res[0] | ||
| 2999 | assert content['content_type'] == 'html-document' | ||
| 3000 | assert content['content_id'] == 16 | ||
| 3001 | assert content['is_archived'] is True | ||
| 3002 | assert content['is_deleted'] is False | ||
| 3003 |         assert content['label'].startswith('Fruit Salad') | ||
| 3004 | assert content['parent_id'] is None | ||
| 3005 | assert content['show_in_ui'] is True | ||
| 3006 |         assert content['slug'].startswith('fruit-salad') | ||
| 3007 | assert content['status'] == 'open' | ||
| 3008 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 3009 | assert content['workspace_id'] == 3 | ||
| 3010 | assert content['modified'] | ||
| 3011 | assert content['created'] | ||
| 3012 | |||
| 3013 | View Code Duplication | def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self): # nopep8 | |
| 3014 | """ | ||
| 3015 | Check obtain workspace root deleted contents | ||
| 3016 | """ | ||
| 3017 |         params = { | ||
| 3018 | 'parent_id': 0, | ||
| 3019 | 'show_archived': 0, | ||
| 3020 | 'show_deleted': 1, | ||
| 3021 | 'show_active': 0, | ||
| 3022 | } | ||
| 3023 | self.testapp.authorization = ( | ||
| 3024 | 'Basic', | ||
| 3025 | ( | ||
| 3026 | '[email protected]', | ||
| 3027 | 'foobarbaz' | ||
| 3028 | ) | ||
| 3029 | ) | ||
| 3030 | res = self.testapp.get( | ||
| 3031 | '/api/v2/workspaces/3/contents', | ||
| 3032 | status=200, | ||
| 3033 | params=params, | ||
| 3034 | ).json_body # nopep8 | ||
| 3035 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 3036 | |||
| 3037 | assert len(res) == 1 | ||
| 3038 | content = res[0] | ||
| 3039 | assert content['content_type'] == 'html-document' | ||
| 3040 | assert content['content_id'] == 17 | ||
| 3041 | assert content['is_archived'] is False | ||
| 3042 | assert content['is_deleted'] is True | ||
| 3043 |         assert content['label'].startswith('Bad Fruit Salad') | ||
| 3044 | assert content['parent_id'] is None | ||
| 3045 | assert content['show_in_ui'] is True | ||
| 3046 |         assert content['slug'].startswith('bad-fruit-salad') | ||
| 3047 | assert content['status'] == 'open' | ||
| 3048 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 3049 | assert content['workspace_id'] == 3 | ||
| 3050 | assert content['modified'] | ||
| 3051 | assert content['created'] | ||
| 3052 | |||
| 3053 | def test_api__get_workspace_content__ok_200__get_nothing_root_content(self): | ||
| 3054 | """ | ||
| 3055 | Check obtain workspace root content who does not match any type | ||
| 3056 | (archived, deleted, active) result should be empty list. | ||
| 3057 | """ | ||
| 3058 |         params = { | ||
| 3059 | 'parent_id': 0, | ||
| 3060 | 'show_archived': 0, | ||
| 3061 | 'show_deleted': 0, | ||
| 3062 | 'show_active': 0, | ||
| 3063 | } | ||
| 3064 | self.testapp.authorization = ( | ||
| 3065 | 'Basic', | ||
| 3066 | ( | ||
| 3067 | '[email protected]', | ||
| 3068 | 'foobarbaz' | ||
| 3069 | ) | ||
| 3070 | ) | ||
| 3071 | res = self.testapp.get( | ||
| 3072 | '/api/v2/workspaces/3/contents', | ||
| 3073 | status=200, | ||
| 3074 | params=params, | ||
| 3075 | ).json_body # nopep8 | ||
| 3076 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 3077 | assert res == [] | ||
| 3078 | |||
| 3079 | # Folder related | ||
| 3080 | def test_api__get_workspace_content__ok_200__get_all_filter_content_thread(self): | ||
| 3081 | # prepare data | ||
| 3082 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 3083 | admin = dbsession.query(models.User) \ | ||
| 3084 | .filter(models.User.email == '[email protected]') \ | ||
| 3085 | .one() | ||
| 3086 | workspace_api = WorkspaceApi( | ||
| 3087 | current_user=admin, | ||
| 3088 | session=dbsession, | ||
| 3089 | config=self.app_config | ||
| 3090 | ) | ||
| 3091 | business_workspace = workspace_api.get_one(1) | ||
| 3092 | content_api = ContentApi( | ||
| 3093 | current_user=admin, | ||
| 3094 | session=dbsession, | ||
| 3095 | config=self.app_config | ||
| 3096 | ) | ||
| 3097 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) | ||
| 3098 | test_thread = content_api.create( | ||
| 3099 | content_type_slug=content_type_list.Thread.slug, | ||
| 3100 | workspace=business_workspace, | ||
| 3101 | parent=tool_folder, | ||
| 3102 | label='Test Thread', | ||
| 3103 | do_save=False, | ||
| 3104 | do_notify=False, | ||
| 3105 | ) | ||
| 3106 | test_thread.description = 'Thread description' | ||
| 3107 | dbsession.add(test_thread) | ||
| 3108 | test_file = content_api.create( | ||
| 3109 | content_type_slug=content_type_list.File.slug, | ||
| 3110 | workspace=business_workspace, | ||
| 3111 | parent=tool_folder, | ||
| 3112 | label='Test file', | ||
| 3113 | do_save=False, | ||
| 3114 | do_notify=False, | ||
| 3115 | ) | ||
| 3116 | test_file.file_extension = '.txt' | ||
| 3117 | test_file.depot_file = FileIntent( | ||
| 3118 | b'Test file', | ||
| 3119 | 'Test_file.txt', | ||
| 3120 | 'text/plain', | ||
| 3121 | ) | ||
| 3122 | test_page_legacy = content_api.create( | ||
| 3123 | content_type_slug=content_type_list.Page.slug, | ||
| 3124 | workspace=business_workspace, | ||
| 3125 | label='test_page', | ||
| 3126 | do_save=False, | ||
| 3127 | do_notify=False, | ||
| 3128 | ) | ||
| 3129 | test_page_legacy.type = 'page' | ||
| 3130 | with new_revision( | ||
| 3131 | session=dbsession, | ||
| 3132 | tm=transaction.manager, | ||
| 3133 | content=test_page_legacy, | ||
| 3134 | ): | ||
| 3135 | content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>') | ||
| 3136 | test_html_document = content_api.create( | ||
| 3137 | content_type_slug=content_type_list.Page.slug, | ||
| 3138 | workspace=business_workspace, | ||
| 3139 | label='test_html_page', | ||
| 3140 | do_save=False, | ||
| 3141 | do_notify=False, | ||
| 3142 | ) | ||
| 3143 | with new_revision( | ||
| 3144 | session=dbsession, | ||
| 3145 | tm=transaction.manager, | ||
| 3146 | content=test_html_document, | ||
| 3147 | ): | ||
| 3148 | content_api.update_content(test_html_document, 'test_page', '<p>HTML_DOCUMENT</p>') # nopep8 | ||
| 3149 | dbsession.flush() | ||
| 3150 | transaction.commit() | ||
| 3151 | # test-itself | ||
| 3152 |         params = { | ||
| 3153 | 'parent_id': 1, | ||
| 3154 | 'show_archived': 1, | ||
| 3155 | 'show_deleted': 1, | ||
| 3156 | 'show_active': 1, | ||
| 3157 | 'content_type': 'thread', | ||
| 3158 | } | ||
| 3159 | self.testapp.authorization = ( | ||
| 3160 | 'Basic', | ||
| 3161 | ( | ||
| 3162 | '[email protected]', | ||
| 3163 | '[email protected]' | ||
| 3164 | ) | ||
| 3165 | ) | ||
| 3166 | res = self.testapp.get( | ||
| 3167 | '/api/v2/workspaces/1/contents', | ||
| 3168 | status=200, | ||
| 3169 | params=params, | ||
| 3170 | ).json_body | ||
| 3171 | assert len(res) == 1 | ||
| 3172 | content = res[0] | ||
| 3173 | assert content['content_type'] == 'thread' | ||
| 3174 | assert content['content_id'] | ||
| 3175 | assert content['is_archived'] is False | ||
| 3176 | assert content['is_deleted'] is False | ||
| 3177 | assert content['label'] == 'Test Thread' | ||
| 3178 | assert content['parent_id'] == 1 | ||
| 3179 | assert content['show_in_ui'] is True | ||
| 3180 | assert content['slug'] == 'test-thread' | ||
| 3181 | assert content['status'] == 'open' | ||
| 3182 |         assert set(content['sub_content_types']) == {'comment'} | ||
| 3183 | assert content['workspace_id'] == 1 | ||
| 3184 | assert content['modified'] | ||
| 3185 | assert content['created'] | ||
| 3186 | |||
| 3187 | def test_api__get_workspace_content__ok_200__get_all_filter_content_html_and_legacy_page(self): # nopep8 | ||
| 3188 | # prepare data | ||
| 3189 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 3190 | admin = dbsession.query(models.User) \ | ||
| 3191 | .filter(models.User.email == '[email protected]') \ | ||
| 3192 | .one() | ||
| 3193 | workspace_api = WorkspaceApi( | ||
| 3194 | current_user=admin, | ||
| 3195 | session=dbsession, | ||
| 3196 | config=self.app_config | ||
| 3197 | ) | ||
| 3198 | business_workspace = workspace_api.get_one(1) | ||
| 3199 | content_api = ContentApi( | ||
| 3200 | current_user=admin, | ||
| 3201 | session=dbsession, | ||
| 3202 | config=self.app_config | ||
| 3203 | ) | ||
| 3204 | tool_folder = content_api.get_one(1, content_type=content_type_list.Any_SLUG) | ||
| 3205 | test_thread = content_api.create( | ||
| 3206 | content_type_slug=content_type_list.Thread.slug, | ||
| 3207 | workspace=business_workspace, | ||
| 3208 | parent=tool_folder, | ||
| 3209 | label='Test Thread', | ||
| 3210 | do_save=False, | ||
| 3211 | do_notify=False, | ||
| 3212 | ) | ||
| 3213 | test_thread.description = 'Thread description' | ||
| 3214 | dbsession.add(test_thread) | ||
| 3215 | test_file = content_api.create( | ||
| 3216 | content_type_slug=content_type_list.File.slug, | ||
| 3217 | workspace=business_workspace, | ||
| 3218 | parent=tool_folder, | ||
| 3219 | label='Test file', | ||
| 3220 | do_save=False, | ||
| 3221 | do_notify=False, | ||
| 3222 | ) | ||
| 3223 | test_file.file_extension = '.txt' | ||
| 3224 | test_file.depot_file = FileIntent( | ||
| 3225 | b'Test file', | ||
| 3226 | 'Test_file.txt', | ||
| 3227 | 'text/plain', | ||
| 3228 | ) | ||
| 3229 | test_page_legacy = content_api.create( | ||
| 3230 | content_type_slug=content_type_list.Page.slug, | ||
| 3231 | workspace=business_workspace, | ||
| 3232 | parent=tool_folder, | ||
| 3233 | label='test_page', | ||
| 3234 | do_save=False, | ||
| 3235 | do_notify=False, | ||
| 3236 | ) | ||
| 3237 | test_page_legacy.type = 'page' | ||
| 3238 | with new_revision( | ||
| 3239 | session=dbsession, | ||
| 3240 | tm=transaction.manager, | ||
| 3241 | content=test_page_legacy, | ||
| 3242 | ): | ||
| 3243 | content_api.update_content(test_page_legacy, 'test_page', '<p>PAGE</p>') | ||
| 3244 | test_html_document = content_api.create( | ||
| 3245 | content_type_slug=content_type_list.Page.slug, | ||
| 3246 | workspace=business_workspace, | ||
| 3247 | parent=tool_folder, | ||
| 3248 | label='test_html_page', | ||
| 3249 | do_save=False, | ||
| 3250 | do_notify=False, | ||
| 3251 | ) | ||
| 3252 | with new_revision( | ||
| 3253 | session=dbsession, | ||
| 3254 | tm=transaction.manager, | ||
| 3255 | content=test_html_document, | ||
| 3256 | ): | ||
| 3257 | content_api.update_content(test_html_document, 'test_html_page', '<p>HTML_DOCUMENT</p>') # nopep8 | ||
| 3258 | dbsession.flush() | ||
| 3259 | transaction.commit() | ||
| 3260 | # test-itself | ||
| 3261 |         params = { | ||
| 3262 | 'parent_id': 1, | ||
| 3263 | 'show_archived': 1, | ||
| 3264 | 'show_deleted': 1, | ||
| 3265 | 'show_active': 1, | ||
| 3266 | 'content_type': 'html-document', | ||
| 3267 | } | ||
| 3268 | self.testapp.authorization = ( | ||
| 3269 | 'Basic', | ||
| 3270 | ( | ||
| 3271 | '[email protected]', | ||
| 3272 | '[email protected]' | ||
| 3273 | ) | ||
| 3274 | ) | ||
| 3275 | res = self.testapp.get( | ||
| 3276 | '/api/v2/workspaces/1/contents', | ||
| 3277 | status=200, | ||
| 3278 | params=params, | ||
| 3279 | ).json_body | ||
| 3280 | assert len(res) == 2 | ||
| 3281 | content = res[0] | ||
| 3282 | assert content['content_type'] == 'html-document' | ||
| 3283 | assert content['content_id'] | ||
| 3284 | assert content['is_archived'] is False | ||
| 3285 | assert content['is_deleted'] is False | ||
| 3286 | assert content['label'] == 'test_html_page' | ||
| 3287 | assert content['parent_id'] == 1 | ||
| 3288 | assert content['show_in_ui'] is True | ||
| 3289 | assert content['slug'] == 'test-html-page' | ||
| 3290 | assert content['status'] == 'open' | ||
| 3291 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3292 | assert content['workspace_id'] == 1 | ||
| 3293 | assert res[0]['content_id'] != res[1]['content_id'] | ||
| 3294 | assert content['modified'] | ||
| 3295 | assert content['created'] | ||
| 3296 | content = res[1] | ||
| 3297 | assert content['content_type'] == 'html-document' | ||
| 3298 | assert content['content_id'] | ||
| 3299 | assert content['is_archived'] is False | ||
| 3300 | assert content['is_deleted'] is False | ||
| 3301 | assert content['label'] == 'test_page' | ||
| 3302 | assert content['parent_id'] == 1 | ||
| 3303 | assert content['show_in_ui'] is True | ||
| 3304 | assert content['slug'] == 'test-page' | ||
| 3305 | assert content['status'] == 'open' | ||
| 3306 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3307 | assert content['workspace_id'] == 1 | ||
| 3308 | assert content['modified'] | ||
| 3309 | assert content['created'] | ||
| 3310 | |||
| 3311 | View Code Duplication | def test_api__get_workspace_content__ok_200__get_all_folder_content(self): | |
| 3312 | """ | ||
| 3313 | Check obtain workspace folder all contents | ||
| 3314 | """ | ||
| 3315 |         params = { | ||
| 3316 | 'parent_id': 10, # TODO - G.M - 30-05-2018 - Find a real id | ||
| 3317 | 'show_archived': 1, | ||
| 3318 | 'show_deleted': 1, | ||
| 3319 | 'show_active': 1, | ||
| 3320 | # 'content_type': 'any' | ||
| 3321 | } | ||
| 3322 | self.testapp.authorization = ( | ||
| 3323 | 'Basic', | ||
| 3324 | ( | ||
| 3325 | '[email protected]', | ||
| 3326 | '[email protected]' | ||
| 3327 | ) | ||
| 3328 | ) | ||
| 3329 | res = self.testapp.get( | ||
| 3330 | '/api/v2/workspaces/2/contents', | ||
| 3331 | status=200, | ||
| 3332 | params=params, | ||
| 3333 | ).json_body # nopep8 | ||
| 3334 | assert len(res) == 3 | ||
| 3335 | content = res[0] | ||
| 3336 | assert content['content_type'] == 'html-document' | ||
| 3337 | assert content['content_id'] == 14 | ||
| 3338 | assert content['is_archived'] is False | ||
| 3339 | assert content['is_deleted'] is True | ||
| 3340 |         assert content['label'].startswith('Bad Fruit Salad') | ||
| 3341 | assert content['parent_id'] == 10 | ||
| 3342 | assert content['show_in_ui'] is True | ||
| 3343 |         assert content['slug'].startswith('bad-fruit-salad') | ||
| 3344 | assert content['status'] == 'open' | ||
| 3345 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3346 | assert content['workspace_id'] == 2 | ||
| 3347 | assert content['modified'] | ||
| 3348 | assert content['created'] | ||
| 3349 | content = res[1] | ||
| 3350 | assert content['content_type'] == 'html-document' | ||
| 3351 | assert content['content_id'] == 13 | ||
| 3352 | assert content['is_archived'] is True | ||
| 3353 | assert content['is_deleted'] is False | ||
| 3354 |         assert content['label'].startswith('Fruit Salad') | ||
| 3355 | assert content['parent_id'] == 10 | ||
| 3356 | assert content['show_in_ui'] is True | ||
| 3357 |         assert content['slug'].startswith('fruit-salad') | ||
| 3358 | assert content['status'] == 'open' | ||
| 3359 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3360 | assert content['workspace_id'] == 2 | ||
| 3361 | assert content['modified'] | ||
| 3362 | assert content['created'] | ||
| 3363 | content = res[2] | ||
| 3364 | assert content['content_type'] == 'html-document' | ||
| 3365 | assert content['content_id'] == 12 | ||
| 3366 | assert content['is_archived'] is False | ||
| 3367 | assert content['is_deleted'] is False | ||
| 3368 | assert content['label'] == 'New Fruit Salad' | ||
| 3369 | assert content['parent_id'] == 10 | ||
| 3370 | assert content['show_in_ui'] is True | ||
| 3371 | assert content['slug'] == 'new-fruit-salad' | ||
| 3372 | assert content['status'] == 'open' | ||
| 3373 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3374 | assert content['workspace_id'] == 2 | ||
| 3375 | assert content['modified'] | ||
| 3376 | assert content['created'] | ||
| 3377 | |||
| 3378 | View Code Duplication | def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self): # nopep8 | |
| 3379 | """ | ||
| 3380 | Check obtain workspace folder active contents | ||
| 3381 | """ | ||
| 3382 |         params = { | ||
| 3383 | 'parent_id': 10, | ||
| 3384 | 'show_archived': 0, | ||
| 3385 | 'show_deleted': 0, | ||
| 3386 | 'show_active': 1, | ||
| 3387 | } | ||
| 3388 | self.testapp.authorization = ( | ||
| 3389 | 'Basic', | ||
| 3390 | ( | ||
| 3391 | '[email protected]', | ||
| 3392 | '[email protected]' | ||
| 3393 | ) | ||
| 3394 | ) | ||
| 3395 | res = self.testapp.get( | ||
| 3396 | '/api/v2/workspaces/2/contents', | ||
| 3397 | status=200, | ||
| 3398 | params=params, | ||
| 3399 | ).json_body # nopep8 | ||
| 3400 | assert len(res) == 1 | ||
| 3401 | content = res[0] | ||
| 3402 | assert content['content_type'] | ||
| 3403 | assert content['content_id'] == 12 | ||
| 3404 | assert content['is_archived'] is False | ||
| 3405 | assert content['is_deleted'] is False | ||
| 3406 | assert content['label'] == 'New Fruit Salad' | ||
| 3407 | assert content['parent_id'] == 10 | ||
| 3408 | assert content['show_in_ui'] is True | ||
| 3409 | assert content['slug'] == 'new-fruit-salad' | ||
| 3410 | assert content['status'] == 'open' | ||
| 3411 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3412 | assert content['workspace_id'] == 2 | ||
| 3413 | assert content['modified'] | ||
| 3414 | assert content['created'] | ||
| 3415 | |||
| 3416 | View Code Duplication | def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self): # nopep8 | |
| 3417 | """ | ||
| 3418 | Check obtain workspace folder archived contents | ||
| 3419 | """ | ||
| 3420 |         params = { | ||
| 3421 | 'parent_id': 10, | ||
| 3422 | 'show_archived': 1, | ||
| 3423 | 'show_deleted': 0, | ||
| 3424 | 'show_active': 0, | ||
| 3425 | } | ||
| 3426 | self.testapp.authorization = ( | ||
| 3427 | 'Basic', | ||
| 3428 | ( | ||
| 3429 | '[email protected]', | ||
| 3430 | '[email protected]' | ||
| 3431 | ) | ||
| 3432 | ) | ||
| 3433 | res = self.testapp.get( | ||
| 3434 | '/api/v2/workspaces/2/contents', | ||
| 3435 | status=200, | ||
| 3436 | params=params, | ||
| 3437 | ).json_body # nopep8 | ||
| 3438 | assert len(res) == 1 | ||
| 3439 | content = res[0] | ||
| 3440 | assert content['content_type'] == 'html-document' | ||
| 3441 | assert content['content_id'] == 13 | ||
| 3442 | assert content['is_archived'] is True | ||
| 3443 | assert content['is_deleted'] is False | ||
| 3444 |         assert content['label'].startswith('Fruit Salad') | ||
| 3445 | assert content['parent_id'] == 10 | ||
| 3446 | assert content['show_in_ui'] is True | ||
| 3447 |         assert content['slug'].startswith('fruit-salad') | ||
| 3448 | assert content['status'] == 'open' | ||
| 3449 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3450 | assert content['workspace_id'] == 2 | ||
| 3451 | assert content['modified'] | ||
| 3452 | assert content['created'] | ||
| 3453 | |||
| 3454 | View Code Duplication | def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self): # nopep8 | |
| 3455 | """ | ||
| 3456 | Check obtain workspace folder deleted contents | ||
| 3457 | """ | ||
| 3458 |         params = { | ||
| 3459 | 'parent_id': 10, | ||
| 3460 | 'show_archived': 0, | ||
| 3461 | 'show_deleted': 1, | ||
| 3462 | 'show_active': 0, | ||
| 3463 | } | ||
| 3464 | self.testapp.authorization = ( | ||
| 3465 | 'Basic', | ||
| 3466 | ( | ||
| 3467 | '[email protected]', | ||
| 3468 | '[email protected]' | ||
| 3469 | ) | ||
| 3470 | ) | ||
| 3471 | res = self.testapp.get( | ||
| 3472 | '/api/v2/workspaces/2/contents', | ||
| 3473 | status=200, | ||
| 3474 | params=params, | ||
| 3475 | ).json_body # nopep8 | ||
| 3476 | |||
| 3477 | assert len(res) == 1 | ||
| 3478 | content = res[0] | ||
| 3479 | assert content['content_type'] == 'html-document' | ||
| 3480 | assert content['content_id'] == 14 | ||
| 3481 | assert content['is_archived'] is False | ||
| 3482 | assert content['is_deleted'] is True | ||
| 3483 |         assert content['label'].startswith('Bad Fruit Salad') | ||
| 3484 | assert content['parent_id'] == 10 | ||
| 3485 | assert content['show_in_ui'] is True | ||
| 3486 |         assert content['slug'].startswith('bad-fruit-salad') | ||
| 3487 | assert content['status'] == 'open' | ||
| 3488 |         assert set(content['sub_content_types']) == {'comment'}  # nopep8 | ||
| 3489 | assert content['workspace_id'] == 2 | ||
| 3490 | assert content['modified'] | ||
| 3491 | assert content['created'] | ||
| 3492 | |||
| 3493 | def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self): # nopep8 | ||
| 3494 | """ | ||
| 3495 | Check obtain workspace folder content who does not match any type | ||
| 3496 | (archived, deleted, active) result should be empty list. | ||
| 3497 | """ | ||
| 3498 |         params = { | ||
| 3499 | 'parent_id': 10, | ||
| 3500 | 'show_archived': 0, | ||
| 3501 | 'show_deleted': 0, | ||
| 3502 | 'show_active': 0, | ||
| 3503 | } | ||
| 3504 | self.testapp.authorization = ( | ||
| 3505 | 'Basic', | ||
| 3506 | ( | ||
| 3507 | '[email protected]', | ||
| 3508 | '[email protected]' | ||
| 3509 | ) | ||
| 3510 | ) | ||
| 3511 | res = self.testapp.get( | ||
| 3512 | '/api/v2/workspaces/2/contents', | ||
| 3513 | status=200, | ||
| 3514 | params=params, | ||
| 3515 | ).json_body # nopep8 | ||
| 3516 | # TODO - G.M - 30-05-2018 - Check this test | ||
| 3517 | assert res == [] | ||
| 3518 | |||
| 3519 | # Error case | ||
| 3520 | |||
| 3521 | def test_api__get_workspace_content__err_400__unallowed_user(self): | ||
| 3522 | """ | ||
| 3523 | Check obtain workspace content list with an unreachable workspace for | ||
| 3524 | user | ||
| 3525 | """ | ||
| 3526 | self.testapp.authorization = ( | ||
| 3527 | 'Basic', | ||
| 3528 | ( | ||
| 3529 | '[email protected]', | ||
| 3530 | 'foobarbaz' | ||
| 3531 | ) | ||
| 3532 | ) | ||
| 3533 |         res = self.testapp.get('/api/v2/workspaces/3/contents', status=400) | ||
| 3534 | assert isinstance(res.json, dict) | ||
| 3535 | assert 'code' in res.json.keys() | ||
| 3536 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 3537 | assert 'message' in res.json.keys() | ||
| 3538 | assert 'details' in res.json.keys() | ||
| 3539 | |||
| 3540 | def test_api__get_workspace_content__err_401__unregistered_user(self): | ||
| 3541 | """ | ||
| 3542 | Check obtain workspace content list with an unregistered user | ||
| 3543 | """ | ||
| 3544 | self.testapp.authorization = ( | ||
| 3545 | 'Basic', | ||
| 3546 | ( | ||
| 3547 | '[email protected]', | ||
| 3548 | 'lapin' | ||
| 3549 | ) | ||
| 3550 | ) | ||
| 3551 |         res = self.testapp.get('/api/v2/workspaces/1/contents', status=401) | ||
| 3552 | assert isinstance(res.json, dict) | ||
| 3553 | assert 'code' in res.json.keys() | ||
| 3554 | assert res.json_body['code'] is None | ||
| 3555 | assert 'message' in res.json.keys() | ||
| 3556 | assert 'details' in res.json.keys() | ||
| 3557 | |||
| 3558 | def test_api__get_workspace_content__err_400__workspace_does_not_exist(self): # nopep8 | ||
| 3559 | """ | ||
| 3560 | Check obtain workspace contents list with an existing user but | ||
| 3561 | an unexisting workspace | ||
| 3562 | """ | ||
| 3563 | self.testapp.authorization = ( | ||
| 3564 | 'Basic', | ||
| 3565 | ( | ||
| 3566 | '[email protected]', | ||
| 3567 | '[email protected]' | ||
| 3568 | ) | ||
| 3569 | ) | ||
| 3570 |         res = self.testapp.get('/api/v2/workspaces/5/contents', status=400) | ||
| 3571 | assert isinstance(res.json, dict) | ||
| 3572 | assert 'code' in res.json.keys() | ||
| 3573 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND | ||
| 3574 | assert 'message' in res.json.keys() | ||
| 3575 | assert 'details' in res.json.keys() | ||
| 3576 | |||
| 3577 | View Code Duplication | def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None: # nopep8 | |
| 3578 | """ | ||
| 3579 | Create generic content as workspace root | ||
| 3580 | """ | ||
| 3581 | self.testapp.authorization = ( | ||
| 3582 | 'Basic', | ||
| 3583 | ( | ||
| 3584 | '[email protected]', | ||
| 3585 | '[email protected]' | ||
| 3586 | ) | ||
| 3587 | ) | ||
| 3588 |         params = { | ||
| 3589 | 'parent_id': None, | ||
| 3590 | 'label': 'GenericCreatedContent', | ||
| 3591 | 'content_type': 'html-document', | ||
| 3592 | } | ||
| 3593 | res = self.testapp.post_json( | ||
| 3594 | '/api/v2/workspaces/1/contents', | ||
| 3595 | params=params, | ||
| 3596 | status=200 | ||
| 3597 | ) | ||
| 3598 | assert res | ||
| 3599 | assert res.json_body | ||
| 3600 | assert res.json_body['status'] == 'open' | ||
| 3601 | assert res.json_body['content_id'] | ||
| 3602 | assert res.json_body['content_type'] == 'html-document' | ||
| 3603 | assert res.json_body['is_archived'] is False | ||
| 3604 | assert res.json_body['is_deleted'] is False | ||
| 3605 | assert res.json_body['workspace_id'] == 1 | ||
| 3606 | assert res.json_body['slug'] == 'genericcreatedcontent' | ||
| 3607 | assert res.json_body['parent_id'] is None | ||
| 3608 | assert res.json_body['show_in_ui'] is True | ||
| 3609 | assert res.json_body['sub_content_types'] | ||
| 3610 | assert res.json_body['modified'] | ||
| 3611 | assert res.json_body['created'] | ||
| 3612 | assert res.json_body['file_extension'] == '.document.html' | ||
| 3613 | assert res.json_body['filename'] == 'GenericCreatedContent.document.html' # nopep8 | ||
| 3614 |         params_active = { | ||
| 3615 | 'parent_id': 0, | ||
| 3616 | 'show_archived': 0, | ||
| 3617 | 'show_deleted': 0, | ||
| 3618 | 'show_active': 1, | ||
| 3619 | } | ||
| 3620 | # INFO - G.M - 2018-06-165 - Verify if new content is correctly created | ||
| 3621 |         active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 3622 | content_ids = [content['content_id'] for content in active_contents] | ||
| 3623 | assert res.json_body['content_id'] in content_ids | ||
| 3624 | |||
| 3625 | def test_api__post_content_create_generic_content__err_400__filename_already_used(self) -> None: # nopep8 | ||
| 3626 | """ | ||
| 3627 | Create generic content but filename is already used here | ||
| 3628 | """ | ||
| 3629 | self.testapp.authorization = ( | ||
| 3630 | 'Basic', | ||
| 3631 | ( | ||
| 3632 | '[email protected]', | ||
| 3633 | '[email protected]' | ||
| 3634 | ) | ||
| 3635 | ) | ||
| 3636 |         params = { | ||
| 3637 | 'parent_id': None, | ||
| 3638 | 'label': 'GenericCreatedContent', | ||
| 3639 | 'content_type': 'html-document', | ||
| 3640 | } | ||
| 3641 | res = self.testapp.post_json( | ||
| 3642 | '/api/v2/workspaces/1/contents', | ||
| 3643 | params=params, | ||
| 3644 | status=200 | ||
| 3645 | ) | ||
| 3646 | assert res | ||
| 3647 | assert res.json_body | ||
| 3648 | assert res.json_body['status'] == 'open' | ||
| 3649 | assert res.json_body['content_id'] | ||
| 3650 | assert res.json_body['content_type'] == 'html-document' | ||
| 3651 | assert res.json_body['is_archived'] is False | ||
| 3652 | assert res.json_body['is_deleted'] is False | ||
| 3653 | assert res.json_body['workspace_id'] == 1 | ||
| 3654 | assert res.json_body['slug'] == 'genericcreatedcontent' | ||
| 3655 | assert res.json_body['parent_id'] is None | ||
| 3656 | assert res.json_body['show_in_ui'] is True | ||
| 3657 | assert res.json_body['sub_content_types'] | ||
| 3658 | assert res.json_body['file_extension'] == '.document.html' | ||
| 3659 | assert res.json_body['filename'] == 'GenericCreatedContent.document.html' # nopep8 | ||
| 3660 | assert res.json_body['modified'] | ||
| 3661 | assert res.json_body['created'] | ||
| 3662 |         params_active = { | ||
| 3663 | 'parent_id': 0, | ||
| 3664 | 'show_archived': 0, | ||
| 3665 | 'show_deleted': 0, | ||
| 3666 | 'show_active': 1, | ||
| 3667 | } | ||
| 3668 | # INFO - G.M - 2018-06-165 - Verify if new content is correctly created | ||
| 3669 |         active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 3670 | content_ids = [content['content_id'] for content in active_contents] | ||
| 3671 | assert res.json_body['content_id'] in content_ids | ||
| 3672 | |||
| 3673 | # recreate same content | ||
| 3674 | res = self.testapp.post_json( | ||
| 3675 | '/api/v2/workspaces/1/contents', | ||
| 3676 | params=params, | ||
| 3677 | status=400 | ||
| 3678 | ) | ||
| 3679 | assert isinstance(res.json, dict) | ||
| 3680 | assert 'code' in res.json.keys() | ||
| 3681 | assert res.json_body['code'] == error.CONTENT_FILENAME_ALREADY_USED_IN_FOLDER | ||
| 3682 | |||
| 3683 | View Code Duplication | def test_api__post_content_create_generic_content__ok_200__no_parent_id_param(self) -> None: # nopep8 | |
| 3684 | """ | ||
| 3685 | Create generic content without provided parent_id param | ||
| 3686 | """ | ||
| 3687 | self.testapp.authorization = ( | ||
| 3688 | 'Basic', | ||
| 3689 | ( | ||
| 3690 | '[email protected]', | ||
| 3691 | '[email protected]' | ||
| 3692 | ) | ||
| 3693 | ) | ||
| 3694 |         params = { | ||
| 3695 | 'label': 'GenericCreatedContent', | ||
| 3696 | 'content_type': 'html-document', | ||
| 3697 | } | ||
| 3698 | res = self.testapp.post_json( | ||
| 3699 | '/api/v2/workspaces/1/contents', | ||
| 3700 | params=params, | ||
| 3701 | status=200 | ||
| 3702 | ) | ||
| 3703 | assert res | ||
| 3704 | assert res.json_body | ||
| 3705 | assert res.json_body['status'] == 'open' | ||
| 3706 | assert res.json_body['content_id'] | ||
| 3707 | assert res.json_body['content_type'] == 'html-document' | ||
| 3708 | assert res.json_body['is_archived'] is False | ||
| 3709 | assert res.json_body['is_deleted'] is False | ||
| 3710 | assert res.json_body['workspace_id'] == 1 | ||
| 3711 | assert res.json_body['slug'] == 'genericcreatedcontent' | ||
| 3712 | assert res.json_body['parent_id'] is None | ||
| 3713 | assert res.json_body['show_in_ui'] is True | ||
| 3714 | assert res.json_body['sub_content_types'] | ||
| 3715 | assert res.json_body['file_extension'] == '.document.html' | ||
| 3716 | assert res.json_body['filename'] == 'GenericCreatedContent.document.html' # nopep8 | ||
| 3717 | assert res.json_body['modified'] | ||
| 3718 | assert res.json_body['created'] | ||
| 3719 |         params_active = { | ||
| 3720 | 'parent_id': 0, | ||
| 3721 | 'show_archived': 0, | ||
| 3722 | 'show_deleted': 0, | ||
| 3723 | 'show_active': 1, | ||
| 3724 | } | ||
| 3725 | # INFO - G.M - 2018-06-165 - Verify if new content is correctly created | ||
| 3726 |         active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 3727 | content_ids = [content['content_id'] for content in active_contents] | ||
| 3728 | assert res.json_body['content_id'] in content_ids | ||
| 3729 | |||
| 3730 | def test_api__post_content_create_generic_content__err_400__parent_id_0(self) -> None: # nopep8 | ||
| 3731 | """ | ||
| 3732 | Create generic content but parent_id=0 | ||
| 3733 | """ | ||
| 3734 | self.testapp.authorization = ( | ||
| 3735 | 'Basic', | ||
| 3736 | ( | ||
| 3737 | '[email protected]', | ||
| 3738 | '[email protected]' | ||
| 3739 | ) | ||
| 3740 | ) | ||
| 3741 |         params = { | ||
| 3742 | 'parent_id': 0, | ||
| 3743 | 'label': 'GenericCreatedContent', | ||
| 3744 | 'content_type': content_type_list.Page.slug | ||
| 3745 | } | ||
| 3746 | res = self.testapp.post_json( | ||
| 3747 | '/api/v2/workspaces/1/contents', | ||
| 3748 | params=params, | ||
| 3749 | status=400 | ||
| 3750 | ) | ||
| 3751 | assert isinstance(res.json, dict) | ||
| 3752 | assert 'code' in res.json.keys() | ||
| 3753 | # INFO - G.M - 2018-09-10 - handled by marshmallow schema | ||
| 3754 | assert res.json_body['code'] == error.GENERIC_SCHEMA_VALIDATION_ERROR # nopep8 | ||
| 3755 | |||
| 3756 | def test_api__post_content_create_generic_content__err_400__parent_not_found(self) -> None: # nopep8 | ||
| 3757 | """ | ||
| 3758 | Create generic content but parent id is not valable | ||
| 3759 | """ | ||
| 3760 | self.testapp.authorization = ( | ||
| 3761 | 'Basic', | ||
| 3762 | ( | ||
| 3763 | '[email protected]', | ||
| 3764 | '[email protected]' | ||
| 3765 | ) | ||
| 3766 | ) | ||
| 3767 |         params = { | ||
| 3768 | 'parent_id': 1000, | ||
| 3769 | 'label': 'GenericCreatedContent', | ||
| 3770 | 'content_type': content_type_list.Page.slug, | ||
| 3771 | } | ||
| 3772 | res = self.testapp.post_json( | ||
| 3773 | '/api/v2/workspaces/1/contents', | ||
| 3774 | params=params, | ||
| 3775 | status=400 | ||
| 3776 | ) | ||
| 3777 | assert isinstance(res.json, dict) | ||
| 3778 | assert 'code' in res.json.keys() | ||
| 3779 | assert res.json_body['code'] == error.PARENT_NOT_FOUND # nopep8 | ||
| 3780 | |||
| 3781 | View Code Duplication | def test_api__post_content_create_generic_content__ok_200__in_folder(self) -> None: # nopep8 | |
| 3782 | """ | ||
| 3783 | Create generic content in folder | ||
| 3784 | """ | ||
| 3785 | self.testapp.authorization = ( | ||
| 3786 | 'Basic', | ||
| 3787 | ( | ||
| 3788 | '[email protected]', | ||
| 3789 | '[email protected]' | ||
| 3790 | ) | ||
| 3791 | ) | ||
| 3792 |         params = { | ||
| 3793 | 'label': 'GenericCreatedContent', | ||
| 3794 | 'content_type': 'html-document', | ||
| 3795 | 'parent_id': 10, | ||
| 3796 | } | ||
| 3797 | res = self.testapp.post_json( | ||
| 3798 | '/api/v2/workspaces/1/contents', | ||
| 3799 | params=params, | ||
| 3800 | status=200 | ||
| 3801 | ) | ||
| 3802 | assert res | ||
| 3803 | assert res.json_body | ||
| 3804 | assert res.json_body['status'] == 'open' | ||
| 3805 | assert res.json_body['content_id'] | ||
| 3806 | assert res.json_body['content_type'] == 'html-document' | ||
| 3807 | assert res.json_body['is_archived'] is False | ||
| 3808 | assert res.json_body['is_deleted'] is False | ||
| 3809 | assert res.json_body['workspace_id'] == 1 | ||
| 3810 | assert res.json_body['slug'] == 'genericcreatedcontent' | ||
| 3811 | assert res.json_body['parent_id'] == 10 | ||
| 3812 | assert res.json_body['show_in_ui'] is True | ||
| 3813 | assert res.json_body['sub_content_types'] | ||
| 3814 | assert res.json_body['file_extension'] == '.document.html' | ||
| 3815 | assert res.json_body['filename'] == 'GenericCreatedContent.document.html' # nopep8 | ||
| 3816 | assert res.json_body['modified'] | ||
| 3817 | assert res.json_body['created'] | ||
| 3818 |         params_active = { | ||
| 3819 | 'parent_id': 10, | ||
| 3820 | 'show_archived': 0, | ||
| 3821 | 'show_deleted': 0, | ||
| 3822 | 'show_active': 1, | ||
| 3823 | } | ||
| 3824 | # INFO - G.M - 2018-06-165 - Verify if new content is correctly created | ||
| 3825 |         active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 3826 | content_ids = [content['content_id'] for content in active_contents] | ||
| 3827 | assert res.json_body['content_id'] in content_ids | ||
| 3828 | |||
| 3829 | def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8 | ||
| 3830 | """ | ||
| 3831 | Create generic content but label provided is empty | ||
| 3832 | """ | ||
| 3833 | self.testapp.authorization = ( | ||
| 3834 | 'Basic', | ||
| 3835 | ( | ||
| 3836 | '[email protected]', | ||
| 3837 | '[email protected]' | ||
| 3838 | ) | ||
| 3839 | ) | ||
| 3840 |         params = { | ||
| 3841 | 'label': '', | ||
| 3842 | 'content_type': content_type_list.Page.slug, | ||
| 3843 | } | ||
| 3844 | res = self.testapp.post_json( | ||
| 3845 | '/api/v2/workspaces/1/contents', | ||
| 3846 | params=params, | ||
| 3847 | status=400 | ||
| 3848 | ) | ||
| 3849 | # INFO - G.M - 2018-09-10 - handled by marshmallow schema | ||
| 3850 | assert res.json_body['code'] == error.GENERIC_SCHEMA_VALIDATION_ERROR # nopep8' | ||
| 3851 | |||
| 3852 | def test_api__post_content_create_generic_content__err_400__wrong_content_type(self) -> None: # nopep8 | ||
| 3853 | """ | ||
| 3854 | Create generic content but content type is uncorrect | ||
| 3855 | """ | ||
| 3856 | self.testapp.authorization = ( | ||
| 3857 | 'Basic', | ||
| 3858 | ( | ||
| 3859 | '[email protected]', | ||
| 3860 | '[email protected]' | ||
| 3861 | ) | ||
| 3862 | ) | ||
| 3863 |         params = { | ||
| 3864 | 'label': 'GenericCreatedContent', | ||
| 3865 | 'content_type': 'unexistent-content-type', | ||
| 3866 | } | ||
| 3867 | res = self.testapp.post_json( | ||
| 3868 | '/api/v2/workspaces/1/contents', | ||
| 3869 | params=params, | ||
| 3870 | status=400, | ||
| 3871 | ) | ||
| 3872 | # INFO - G.M - 2018-09-10 - handled by marshmallow schema | ||
| 3873 | assert res.json_body['code'] == error.GENERIC_SCHEMA_VALIDATION_ERROR # nopep8 | ||
| 3874 | |||
| 3875 | def test_api__post_content_create_generic_content__err_400__unallowed_content_type(self) -> None: # nopep8 | ||
| 3876 | """ | ||
| 3877 | Create generic content but content_type is not allowed in this folder | ||
| 3878 | """ | ||
| 3879 | dbsession = get_tm_session(self.session_factory, transaction.manager) | ||
| 3880 | admin = dbsession.query(models.User) \ | ||
| 3881 | .filter(models.User.email == '[email protected]') \ | ||
| 3882 | .one() | ||
| 3883 | workspace_api = WorkspaceApi( | ||
| 3884 | current_user=admin, | ||
| 3885 | session=dbsession, | ||
| 3886 | config=self.app_config | ||
| 3887 | ) | ||
| 3888 | content_api = ContentApi( | ||
| 3889 | current_user=admin, | ||
| 3890 | session=dbsession, | ||
| 3891 | config=self.app_config | ||
| 3892 | ) | ||
| 3893 | test_workspace = workspace_api.create_workspace( | ||
| 3894 | label='test', | ||
| 3895 | save_now=True, | ||
| 3896 | ) | ||
| 3897 | folder = content_api.create( | ||
| 3898 | label='test-folder', | ||
| 3899 | content_type_slug=content_type_list.Folder.slug, | ||
| 3900 | workspace=test_workspace, | ||
| 3901 | do_save=False, | ||
| 3902 | do_notify=False | ||
| 3903 | ) | ||
| 3904 | content_api.set_allowed_content(folder, [content_type_list.Folder.slug]) | ||
| 3905 | content_api.save(folder) | ||
| 3906 | transaction.commit() | ||
| 3907 | self.testapp.authorization = ( | ||
| 3908 | 'Basic', | ||
| 3909 | ( | ||
| 3910 | '[email protected]', | ||
| 3911 | '[email protected]' | ||
| 3912 | ) | ||
| 3913 | ) | ||
| 3914 | # unallowed_content_type | ||
| 3915 |         params = { | ||
| 3916 | 'label': 'GenericCreatedContent', | ||
| 3917 | 'content_type': content_type_list.Page.slug, | ||
| 3918 | 'parent_id': folder.content_id | ||
| 3919 | } | ||
| 3920 | res = self.testapp.post_json( | ||
| 3921 |             '/api/v2/workspaces/{workspace_id}/contents'.format(workspace_id=test_workspace.workspace_id), | ||
| 3922 | params=params, | ||
| 3923 | status=400, | ||
| 3924 | ) | ||
| 3925 | assert isinstance(res.json, dict) | ||
| 3926 | assert 'code' in res.json.keys() | ||
| 3927 | assert res.json_body['code'] == error.UNALLOWED_SUBCONTENT # nopep8 | ||
| 3928 | # allowed_content_type | ||
| 3929 |         params = { | ||
| 3930 | 'label': 'GenericCreatedContent', | ||
| 3931 | 'content_type': 'folder', | ||
| 3932 | 'parent_id': folder.content_id | ||
| 3933 | } | ||
| 3934 | res = self.testapp.post_json( | ||
| 3935 |             '/api/v2/workspaces/{workspace_id}/contents'.format(workspace_id=test_workspace.workspace_id), | ||
| 3936 | params=params, | ||
| 3937 | status=200, | ||
| 3938 | ) | ||
| 3939 | |||
| 3940 | View Code Duplication | def test_api_put_move_content__ok_200__nominal_case(self): | |
| 3941 | """ | ||
| 3942 | Move content | ||
| 3943 | move Apple_Pie (content_id: 8) | ||
| 3944 | from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4) | ||
| 3945 | of workspace Recipes. | ||
| 3946 | """ | ||
| 3947 | self.testapp.authorization = ( | ||
| 3948 | 'Basic', | ||
| 3949 | ( | ||
| 3950 | '[email protected]', | ||
| 3951 | '[email protected]' | ||
| 3952 | ) | ||
| 3953 | ) | ||
| 3954 |         params = { | ||
| 3955 | 'new_parent_id': '4', # Salads | ||
| 3956 | 'new_workspace_id': '2', | ||
| 3957 | } | ||
| 3958 |         params_folder1 = { | ||
| 3959 | 'parent_id': 3, | ||
| 3960 | 'show_archived': 0, | ||
| 3961 | 'show_deleted': 0, | ||
| 3962 | 'show_active': 1, | ||
| 3963 | } | ||
| 3964 |         params_folder2 = { | ||
| 3965 | 'parent_id': 4, | ||
| 3966 | 'show_archived': 0, | ||
| 3967 | 'show_deleted': 0, | ||
| 3968 | 'show_active': 1, | ||
| 3969 | } | ||
| 3970 |         folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 3971 |         folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 3972 | assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 3973 | assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 3974 | # TODO - G.M - 2018-06-163 - Check content | ||
| 3975 | res = self.testapp.put_json( | ||
| 3976 | '/api/v2/workspaces/2/contents/8/move', | ||
| 3977 | params=params, | ||
| 3978 | status=200 | ||
| 3979 | ) | ||
| 3980 |         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 3981 |         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 3982 | assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 3983 | assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 3984 | assert res.json_body | ||
| 3985 | assert res.json_body['parent_id'] == 4 | ||
| 3986 | assert res.json_body['content_id'] == 8 | ||
| 3987 | assert res.json_body['workspace_id'] == 2 | ||
| 3988 | |||
| 3989 | View Code Duplication | def test_api_put_move_content__ok_200__to_root(self): | |
| 3990 | """ | ||
| 3991 | Move content | ||
| 3992 | move Apple_Pie (content_id: 8) | ||
| 3993 | from Desserts folder(content_id: 3) to root (content_id: 0) | ||
| 3994 | of workspace Recipes. | ||
| 3995 | """ | ||
| 3996 | self.testapp.authorization = ( | ||
| 3997 | 'Basic', | ||
| 3998 | ( | ||
| 3999 | '[email protected]', | ||
| 4000 | '[email protected]' | ||
| 4001 | ) | ||
| 4002 | ) | ||
| 4003 |         params = { | ||
| 4004 | 'new_parent_id': None, # root | ||
| 4005 | 'new_workspace_id': 2, | ||
| 4006 | } | ||
| 4007 |         params_folder1 = { | ||
| 4008 | 'parent_id': 3, | ||
| 4009 | 'show_archived': 0, | ||
| 4010 | 'show_deleted': 0, | ||
| 4011 | 'show_active': 1, | ||
| 4012 | } | ||
| 4013 |         params_folder2 = { | ||
| 4014 | 'parent_id': 0, | ||
| 4015 | 'show_archived': 0, | ||
| 4016 | 'show_deleted': 0, | ||
| 4017 | 'show_active': 1, | ||
| 4018 | } | ||
| 4019 |         folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4020 |         folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4021 | assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4022 | assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4023 | # TODO - G.M - 2018-06-163 - Check content | ||
| 4024 | res = self.testapp.put_json( | ||
| 4025 | '/api/v2/workspaces/2/contents/8/move', | ||
| 4026 | params=params, | ||
| 4027 | status=200 | ||
| 4028 | ) | ||
| 4029 |         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4030 |         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4031 | assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4032 | assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4033 | assert res.json_body | ||
| 4034 | assert res.json_body['parent_id'] is None | ||
| 4035 | assert res.json_body['content_id'] == 8 | ||
| 4036 | assert res.json_body['workspace_id'] == 2 | ||
| 4037 | |||
| 4038 | View Code Duplication | def test_api_put_move_content__ok_200__with_workspace_id(self): | |
| 4039 | """ | ||
| 4040 | Move content | ||
| 4041 | move Apple_Pie (content_id: 8) | ||
| 4042 | from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4) | ||
| 4043 | of workspace Recipes. | ||
| 4044 | """ | ||
| 4045 | self.testapp.authorization = ( | ||
| 4046 | 'Basic', | ||
| 4047 | ( | ||
| 4048 | '[email protected]', | ||
| 4049 | '[email protected]' | ||
| 4050 | ) | ||
| 4051 | ) | ||
| 4052 |         params = { | ||
| 4053 | 'new_parent_id': '4', # Salads | ||
| 4054 | 'new_workspace_id': '2', | ||
| 4055 | } | ||
| 4056 |         params_folder1 = { | ||
| 4057 | 'parent_id': 3, | ||
| 4058 | 'show_archived': 0, | ||
| 4059 | 'show_deleted': 0, | ||
| 4060 | 'show_active': 1, | ||
| 4061 | } | ||
| 4062 |         params_folder2 = { | ||
| 4063 | 'parent_id': 4, | ||
| 4064 | 'show_archived': 0, | ||
| 4065 | 'show_deleted': 0, | ||
| 4066 | 'show_active': 1, | ||
| 4067 | } | ||
| 4068 |         folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4069 |         folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4070 | assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4071 | assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4072 | # TODO - G.M - 2018-06-163 - Check content | ||
| 4073 | res = self.testapp.put_json( | ||
| 4074 | '/api/v2/workspaces/2/contents/8/move', | ||
| 4075 | params=params, | ||
| 4076 | status=200 | ||
| 4077 | ) | ||
| 4078 |         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4079 |         new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4080 | assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4081 | assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4082 | assert res.json_body | ||
| 4083 | assert res.json_body['parent_id'] == 4 | ||
| 4084 | assert res.json_body['content_id'] == 8 | ||
| 4085 | assert res.json_body['workspace_id'] == 2 | ||
| 4086 | |||
| 4087 | View Code Duplication | def test_api_put_move_content__ok_200__to_another_workspace(self): | |
| 4088 | """ | ||
| 4089 | Move content | ||
| 4090 | move Apple_Pie (content_id: 8) | ||
| 4091 | from Desserts folder(content_id: 3) to Menus subfolder (content_id: 2) | ||
| 4092 | of workspace Business. | ||
| 4093 | """ | ||
| 4094 | self.testapp.authorization = ( | ||
| 4095 | 'Basic', | ||
| 4096 | ( | ||
| 4097 | '[email protected]', | ||
| 4098 | '[email protected]' | ||
| 4099 | ) | ||
| 4100 | ) | ||
| 4101 |         params = { | ||
| 4102 | 'new_parent_id': '2', # Menus | ||
| 4103 | 'new_workspace_id': '1', | ||
| 4104 | } | ||
| 4105 |         params_folder1 = { | ||
| 4106 | 'parent_id': 3, | ||
| 4107 | 'show_archived': 0, | ||
| 4108 | 'show_deleted': 0, | ||
| 4109 | 'show_active': 1, | ||
| 4110 | } | ||
| 4111 |         params_folder2 = { | ||
| 4112 | 'parent_id': 2, | ||
| 4113 | 'show_archived': 0, | ||
| 4114 | 'show_deleted': 0, | ||
| 4115 | 'show_active': 1, | ||
| 4116 | } | ||
| 4117 |         folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4118 |         folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4119 | assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4120 | assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4121 | # TODO - G.M - 2018-06-163 - Check content | ||
| 4122 | res = self.testapp.put_json( | ||
| 4123 | '/api/v2/workspaces/2/contents/8/move', | ||
| 4124 | params=params, | ||
| 4125 | status=200 | ||
| 4126 | ) | ||
| 4127 |         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4128 |         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4129 | assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4130 | assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4131 | assert res.json_body | ||
| 4132 | assert res.json_body['parent_id'] == 2 | ||
| 4133 | assert res.json_body['content_id'] == 8 | ||
| 4134 | assert res.json_body['workspace_id'] == 1 | ||
| 4135 | |||
| 4136 | View Code Duplication | def test_api_put_move_content__ok_200__to_another_workspace_root(self): | |
| 4137 | """ | ||
| 4138 | Move content | ||
| 4139 | move Apple_Pie (content_id: 8) | ||
| 4140 | from Desserts folder(content_id: 3) to root (content_id: 0) | ||
| 4141 | of workspace Business. | ||
| 4142 | """ | ||
| 4143 | self.testapp.authorization = ( | ||
| 4144 | 'Basic', | ||
| 4145 | ( | ||
| 4146 | '[email protected]', | ||
| 4147 | '[email protected]' | ||
| 4148 | ) | ||
| 4149 | ) | ||
| 4150 |         params = { | ||
| 4151 | 'new_parent_id': None, # root | ||
| 4152 | 'new_workspace_id': '1', | ||
| 4153 | } | ||
| 4154 |         params_folder1 = { | ||
| 4155 | 'parent_id': 3, | ||
| 4156 | 'show_archived': 0, | ||
| 4157 | 'show_deleted': 0, | ||
| 4158 | 'show_active': 1, | ||
| 4159 | } | ||
| 4160 |         params_folder2 = { | ||
| 4161 | 'parent_id': 0, | ||
| 4162 | 'show_archived': 0, | ||
| 4163 | 'show_deleted': 0, | ||
| 4164 | 'show_active': 1, | ||
| 4165 | } | ||
| 4166 |         folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4167 |         folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4168 | assert [content for content in folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4169 | assert not [content for content in folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4170 | # TODO - G.M - 2018-06-163 - Check content | ||
| 4171 | res = self.testapp.put_json( | ||
| 4172 | '/api/v2/workspaces/2/contents/8/move', | ||
| 4173 | params=params, | ||
| 4174 | status=200 | ||
| 4175 | ) | ||
| 4176 |         new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8 | ||
| 4177 |         new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8 | ||
| 4178 | assert not [content for content in new_folder1_contents if content['content_id'] == 8] # nopep8 | ||
| 4179 | assert [content for content in new_folder2_contents if content['content_id'] == 8] # nopep8 | ||
| 4180 | assert res.json_body | ||
| 4181 | assert res.json_body['parent_id'] is None | ||
| 4182 | assert res.json_body['content_id'] == 8 | ||
| 4183 | assert res.json_body['workspace_id'] == 1 | ||
| 4184 | |||
| 4185 | def test_api_put_move_content__err_400__wrong_workspace_id(self): | ||
| 4186 | """ | ||
| 4187 | Move content | ||
| 4188 | move Apple_Pie (content_id: 8) | ||
| 4189 | from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4) | ||
| 4190 | of workspace Recipes. | ||
| 4191 | Workspace_id of parent_id don't match with workspace_id of workspace | ||
| 4192 | """ | ||
| 4193 | self.testapp.authorization = ( | ||
| 4194 | 'Basic', | ||
| 4195 | ( | ||
| 4196 | '[email protected]', | ||
| 4197 | '[email protected]' | ||
| 4198 | ) | ||
| 4199 | ) | ||
| 4200 |         params = { | ||
| 4201 | 'new_parent_id': '4', # Salads | ||
| 4202 | 'new_workspace_id': '1', | ||
| 4203 | } | ||
| 4204 |         params_folder1 = { | ||
| 4205 | 'parent_id': 3, | ||
| 4206 | 'show_archived': 0, | ||
| 4207 | 'show_deleted': 0, | ||
| 4208 | 'show_active': 1, | ||
| 4209 | } | ||
| 4210 |         params_folder2 = { | ||
| 4211 | 'parent_id': 4, | ||
| 4212 | 'show_archived': 0, | ||
| 4213 | 'show_deleted': 0, | ||
| 4214 | 'show_active': 1, | ||
| 4215 | } | ||
| 4216 | res = self.testapp.put_json( | ||
| 4217 | '/api/v2/workspaces/2/contents/8/move', | ||
| 4218 | params=params, | ||
| 4219 | status=400, | ||
| 4220 | ) | ||
| 4221 | assert res.json_body['code'] == error.WORKSPACE_DO_NOT_MATCH | ||
| 4222 | |||
| 4223 | View Code Duplication | def test_api_put_delete_content__ok_200__nominal_case(self): | |
| 4224 | """ | ||
| 4225 | delete content | ||
| 4226 | delete Apple_pie ( content_id: 8, parent_id: 3) | ||
| 4227 | """ | ||
| 4228 | self.testapp.authorization = ( | ||
| 4229 | 'Basic', | ||
| 4230 | ( | ||
| 4231 | '[email protected]', | ||
| 4232 | '[email protected]' | ||
| 4233 | ) | ||
| 4234 | ) | ||
| 4235 |         params_active = { | ||
| 4236 | 'parent_id': 3, | ||
| 4237 | 'show_archived': 0, | ||
| 4238 | 'show_deleted': 0, | ||
| 4239 | 'show_active': 1, | ||
| 4240 | } | ||
| 4241 |         params_deleted = { | ||
| 4242 | 'parent_id': 3, | ||
| 4243 | 'show_archived': 0, | ||
| 4244 | 'show_deleted': 1, | ||
| 4245 | 'show_active': 0, | ||
| 4246 | } | ||
| 4247 |         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4248 |         deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8 | ||
| 4249 | assert [content for content in active_contents if content['content_id'] == 8] # nopep8 | ||
| 4250 | assert not [content for content in deleted_contents if content['content_id'] == 8] # nopep8 | ||
| 4251 | # TODO - G.M - 2018-06-163 - Check content | ||
| 4252 | res = self.testapp.put_json( | ||
| 4253 | # INFO - G.M - 2018-06-163 - delete Apple_Pie | ||
| 4254 | '/api/v2/workspaces/2/contents/8/trashed', | ||
| 4255 | status=204 | ||
| 4256 | ) | ||
| 4257 |         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4258 |         new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8 | ||
| 4259 | assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8 | ||
| 4260 | assert [content for content in new_deleted_contents if content['content_id'] == 8] # nopep8 | ||
| 4261 | |||
| 4262 | View Code Duplication | def test_api_put_archive_content__ok_200__nominal_case(self): | |
| 4263 | """ | ||
| 4264 | archive content | ||
| 4265 | archive Apple_pie ( content_id: 8, parent_id: 3) | ||
| 4266 | """ | ||
| 4267 | self.testapp.authorization = ( | ||
| 4268 | 'Basic', | ||
| 4269 | ( | ||
| 4270 | '[email protected]', | ||
| 4271 | '[email protected]' | ||
| 4272 | ) | ||
| 4273 | ) | ||
| 4274 |         params_active = { | ||
| 4275 | 'parent_id': 3, | ||
| 4276 | 'show_archived': 0, | ||
| 4277 | 'show_deleted': 0, | ||
| 4278 | 'show_active': 1, | ||
| 4279 | } | ||
| 4280 |         params_archived = { | ||
| 4281 | 'parent_id': 3, | ||
| 4282 | 'show_archived': 1, | ||
| 4283 | 'show_deleted': 0, | ||
| 4284 | 'show_active': 0, | ||
| 4285 | } | ||
| 4286 |         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4287 |         archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8 | ||
| 4288 | assert [content for content in active_contents if content['content_id'] == 8] # nopep8 | ||
| 4289 | assert not [content for content in archived_contents if content['content_id'] == 8] # nopep8 | ||
| 4290 | res = self.testapp.put_json( | ||
| 4291 | '/api/v2/workspaces/2/contents/8/archived', | ||
| 4292 | status=204 | ||
| 4293 | ) | ||
| 4294 |         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4295 |         new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8 | ||
| 4296 | assert not [content for content in new_active_contents if content['content_id'] == 8] # nopep8 | ||
| 4297 | assert [content for content in new_archived_contents if content['content_id'] == 8] # nopep8 | ||
| 4298 | |||
| 4299 | View Code Duplication | def test_api_put_undelete_content__ok_200__nominal_case(self): | |
| 4300 | """ | ||
| 4301 | Undelete content | ||
| 4302 | undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10) | ||
| 4303 | """ | ||
| 4304 | self.testapp.authorization = ( | ||
| 4305 | 'Basic', | ||
| 4306 | ( | ||
| 4307 | '[email protected]', | ||
| 4308 | 'foobarbaz' | ||
| 4309 | ) | ||
| 4310 | ) | ||
| 4311 |         params_active = { | ||
| 4312 | 'parent_id': 10, | ||
| 4313 | 'show_archived': 0, | ||
| 4314 | 'show_deleted': 0, | ||
| 4315 | 'show_active': 1, | ||
| 4316 | } | ||
| 4317 |         params_deleted = { | ||
| 4318 | 'parent_id': 10, | ||
| 4319 | 'show_archived': 0, | ||
| 4320 | 'show_deleted': 1, | ||
| 4321 | 'show_active': 0, | ||
| 4322 | } | ||
| 4323 |         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4324 |         deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8 | ||
| 4325 | assert not [content for content in active_contents if content['content_id'] == 14] # nopep8 | ||
| 4326 | assert [content for content in deleted_contents if content['content_id'] == 14] # nopep8 | ||
| 4327 | res = self.testapp.put_json( | ||
| 4328 | '/api/v2/workspaces/2/contents/14/trashed/restore', | ||
| 4329 | status=204 | ||
| 4330 | ) | ||
| 4331 |         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4332 |         new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8 | ||
| 4333 | assert [content for content in new_active_contents if content['content_id'] == 14] # nopep8 | ||
| 4334 | assert not [content for content in new_deleted_contents if content['content_id'] == 14] # nopep8 | ||
| 4335 | |||
| 4336 | View Code Duplication | def test_api_put_unarchive_content__ok_200__nominal_case(self): | |
| 4337 | """ | ||
| 4338 | unarchive content, | ||
| 4339 | unarchive Fruit_salads ( content_id: 13, parent_id: 10) | ||
| 4340 | """ | ||
| 4341 | self.testapp.authorization = ( | ||
| 4342 | 'Basic', | ||
| 4343 | ( | ||
| 4344 | '[email protected]', | ||
| 4345 | 'foobarbaz' | ||
| 4346 | ) | ||
| 4347 | ) | ||
| 4348 |         params_active = { | ||
| 4349 | 'parent_id': 10, | ||
| 4350 | 'show_archived': 0, | ||
| 4351 | 'show_deleted': 0, | ||
| 4352 | 'show_active': 1, | ||
| 4353 | } | ||
| 4354 |         params_archived = { | ||
| 4355 | 'parent_id': 10, | ||
| 4356 | 'show_archived': 1, | ||
| 4357 | 'show_deleted': 0, | ||
| 4358 | 'show_active': 0, | ||
| 4359 | } | ||
| 4360 |         active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4361 |         archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8 | ||
| 4362 | assert not [content for content in active_contents if content['content_id'] == 13] # nopep8 | ||
| 4363 | assert [content for content in archived_contents if content['content_id'] == 13] # nopep8 | ||
| 4364 | res = self.testapp.put_json( | ||
| 4365 | '/api/v2/workspaces/2/contents/13/archived/restore', | ||
| 4366 | status=204 | ||
| 4367 | ) | ||
| 4368 |         new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8 | ||
| 4369 |         new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8 | ||
| 4370 | assert [content for content in new_active_contents if content['content_id'] == 13] # nopep8 | ||
| 4371 | assert not [content for content in new_archived_contents if content['content_id'] == 13] # nopep8 | ||
| 4372 |