Browse Source

Fix all test cases for get_workspace_content

Guénaël Muller 6 years ago
parent
commit
9b2827e6b1
2 changed files with 213 additions and 71 deletions
  1. 36 0
      tracim/fixtures/content.py
  2. 177 71
      tracim/tests/functional/test_workspaces.py

+ 36 - 0
tracim/fixtures/content.py View File

@@ -200,4 +200,40 @@ class Content(Fixture):
200 200
             content_api.delete(bad_fruit_salad)
201 201
         content_api.save(bad_fruit_salad)
202 202
 
203
+        # File at the root for test
204
+        new_fruit_salad = content_api.create(
205
+            content_type=ContentType.Page,
206
+            workspace=other_workspace,
207
+            label='New Fruit Salad',
208
+            do_save=True,
209
+        )
210
+        old_fruit_salad = content_api.create(
211
+            content_type=ContentType.Page,
212
+            workspace=other_workspace,
213
+            label='Fruit Salad',
214
+            do_save=True,
215
+        )
216
+        with new_revision(
217
+                session=self._session,
218
+                tm=transaction.manager,
219
+                content=old_fruit_salad,
220
+        ):
221
+            content_api.archive(old_fruit_salad)
222
+        content_api.save(old_fruit_salad)
223
+
224
+        bad_fruit_salad = content_api.create(
225
+            content_type=ContentType.Page,
226
+            workspace=other_workspace,
227
+            label='Bad Fruit Salad',
228
+            do_save=True,
229
+        )
230
+        with new_revision(
231
+                session=self._session,
232
+                tm=transaction.manager,
233
+                content=bad_fruit_salad,
234
+        ):
235
+            content_api.delete(bad_fruit_salad)
236
+        content_api.save(bad_fruit_salad)
237
+
238
+
203 239
         self._session.flush()

+ 177 - 71
tracim/tests/functional/test_workspaces.py View File

@@ -2,8 +2,6 @@
2 2
 """
3 3
 Tests for /api/v2/workspaces subpath endpoints.
4 4
 """
5
-import pytest
6
-
7 5
 from tracim.tests import FunctionalTest
8 6
 from tracim.fixtures.content import Content as ContentFixtures
9 7
 from tracim.fixtures.users_and_groups import Base as BaseFixture
@@ -246,10 +244,10 @@ class TestWorkspaceContents(FunctionalTest):
246 244
         assert content['is_deleted'] is False
247 245
         assert content['label'] == 'Tools'
248 246
         assert content['parent_id'] is None
249
-        assert content['show_in_ui'] == True
247
+        assert content['show_in_ui'] is True
250 248
         assert content['slug'] == 'tools'
251 249
         assert content['status_slug'] == 'open'
252
-        assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
250
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
253 251
         assert content['workspace_id'] == 1
254 252
         content = res[1]
255 253
         assert content['id'] == 2
@@ -257,10 +255,10 @@ class TestWorkspaceContents(FunctionalTest):
257 255
         assert content['is_deleted'] is False
258 256
         assert content['label'] == 'Menus'
259 257
         assert content['parent_id'] is None
260
-        assert content['show_in_ui'] == True
258
+        assert content['show_in_ui'] is True
261 259
         assert content['slug'] == 'menus'
262 260
         assert content['status_slug'] == 'open'
263
-        assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
261
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
264 262
         assert content['workspace_id'] == 1
265 263
         content = res[2]
266 264
         assert content['id'] == 11
@@ -268,10 +266,10 @@ class TestWorkspaceContents(FunctionalTest):
268 266
         assert content['is_deleted'] is False
269 267
         assert content['label'] == 'Current Menu'
270 268
         assert content['parent_id'] == 2
271
-        assert content['show_in_ui'] == True
269
+        assert content['show_in_ui'] is True
272 270
         assert content['slug'] == 'current-menu'
273 271
         assert content['status_slug'] == 'open'
274
-        assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
272
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
275 273
         assert content['workspace_id'] == 1
276 274
 
277 275
     # Root related
@@ -289,42 +287,57 @@ class TestWorkspaceContents(FunctionalTest):
289 287
         self.testapp.authorization = (
290 288
             'Basic',
291 289
             (
292
-                'admin@admin.admin',
293
-                'admin@admin.admin'
290
+                'bob@fsf.local',
291
+                'foobarbaz'
294 292
             )
295 293
         )
296 294
         res = self.testapp.get(
297
-            '/api/v2/workspaces/1/contents',
295
+            '/api/v2/workspaces/3/contents',
298 296
             status=200,
299 297
             params=params,
300 298
         ).json_body  # nopep8
301 299
         # TODO - G.M - 30-05-2018 - Check this test
302
-        assert len(res) == 2
303
-        content = res[0]
304
-        assert content['id'] == 1
300
+        assert len(res) == 4
301
+        content = res[1]
302
+        assert content['content_type_slug'] == 'page'
303
+        assert content['id'] == 15
305 304
         assert content['is_archived'] is False
306 305
         assert content['is_deleted'] is False
307
-        assert content['label'] == 'Tools'
306
+        assert content['label'] == 'New Fruit Salad'
308 307
         assert content['parent_id'] is None
309
-        assert content['show_in_ui'] == True
310
-        assert content['slug'] == 'tools'
308
+        assert content['show_in_ui'] is True
309
+        assert content['slug'] == 'new-fruit-salad'
311 310
         assert content['status_slug'] == 'open'
312
-        assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
313
-        assert content['workspace_id'] == 1
314
-        content = res[1]
315
-        assert content['id'] == 2
316
-        assert content['is_archived'] is False
311
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
312
+        assert content['workspace_id'] == 3
313
+
314
+        content = res[2]
315
+        assert content['content_type_slug'] == 'page'
316
+        assert content['id'] == 16
317
+        assert content['is_archived'] is True
317 318
         assert content['is_deleted'] is False
318
-        assert content['label'] == 'Menus'
319
+        assert content['label'].startswith('Fruit Salad')
319 320
         assert content['parent_id'] is None
320
-        assert content['show_in_ui'] == True
321
-        assert content['slug'] == 'menus'
321
+        assert content['show_in_ui'] is True
322
+        assert content['slug'].startswith('fruit-salad')
322 323
         assert content['status_slug'] == 'open'
323
-        assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
324
-        assert content['workspace_id'] == 1
324
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
325
+        assert content['workspace_id'] == 3
326
+
327
+        content = res[3]
328
+        assert content['content_type_slug'] == 'page'
329
+        assert content['id'] == 17
330
+        assert content['is_archived'] is False
331
+        assert content['is_deleted'] is True
332
+        assert content['label'].startswith('Bad Fruit Salad')
333
+        assert content['parent_id'] is None
334
+        assert content['show_in_ui'] is True
335
+        assert content['slug'].startswith('bad-fruit-salad')
336
+        assert content['status_slug'] == 'open'
337
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
338
+        assert content['workspace_id'] == 3
325 339
 
326
-    @pytest.mark.xfail()
327
-    def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):
340
+    def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):  # nopep8
328 341
         """
329 342
         Check obtain workspace root active contents
330 343
         """
@@ -337,20 +350,31 @@ class TestWorkspaceContents(FunctionalTest):
337 350
         self.testapp.authorization = (
338 351
             'Basic',
339 352
             (
340
-                'admin@admin.admin',
341
-                'admin@admin.admin'
353
+                'bob@fsf.local',
354
+                'foobarbaz'
342 355
             )
343 356
         )
344 357
         res = self.testapp.get(
345
-            '/api/v2/workspaces/1/contents',
358
+            '/api/v2/workspaces/3/contents',
346 359
             status=200,
347 360
             params=params,
348 361
         ).json_body   # nopep8
349 362
         # TODO - G.M - 30-05-2018 - Check this test
350
-        raise NotImplementedError()
363
+        assert len(res) == 2
364
+        content = res[1]
365
+        assert content['content_type_slug'] == 'page'
366
+        assert content['id'] == 15
367
+        assert content['is_archived'] is False
368
+        assert content['is_deleted'] is False
369
+        assert content['label'] == 'New Fruit Salad'
370
+        assert content['parent_id'] is None
371
+        assert content['show_in_ui'] is True
372
+        assert content['slug'] == 'new-fruit-salad'
373
+        assert content['status_slug'] == 'open'
374
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
375
+        assert content['workspace_id'] == 3
351 376
 
352
-    @pytest.mark.xfail()
353
-    def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):
377
+    def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):  # nopep8
354 378
         """
355 379
         Check obtain workspace root archived contents
356 380
         """
@@ -363,20 +387,30 @@ class TestWorkspaceContents(FunctionalTest):
363 387
         self.testapp.authorization = (
364 388
             'Basic',
365 389
             (
366
-                'admin@admin.admin',
367
-                'admin@admin.admin'
390
+                'bob@fsf.local',
391
+                'foobarbaz'
368 392
             )
369 393
         )
370 394
         res = self.testapp.get(
371
-            '/api/v2/workspaces/1/contents',
395
+            '/api/v2/workspaces/3/contents',
372 396
             status=200,
373 397
             params=params,
374 398
         ).json_body   # nopep8
375
-        # TODO - G.M - 30-05-2018 - Check this test
376
-        raise NotImplementedError()
399
+        assert len(res) == 1
400
+        content = res[0]
401
+        assert content['content_type_slug'] == 'page'
402
+        assert content['id'] == 16
403
+        assert content['is_archived'] is True
404
+        assert content['is_deleted'] is False
405
+        assert content['label'].startswith('Fruit Salad')
406
+        assert content['parent_id'] is None
407
+        assert content['show_in_ui'] is True
408
+        assert content['slug'].startswith('fruit-salad')
409
+        assert content['status_slug'] == 'open'
410
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
411
+        assert content['workspace_id'] == 3
377 412
 
378
-    @pytest.mark.xfail()
379
-    def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):
413
+    def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):  # nopep8
380 414
         """
381 415
          Check obtain workspace root deleted contents
382 416
          """
@@ -389,17 +423,30 @@ class TestWorkspaceContents(FunctionalTest):
389 423
         self.testapp.authorization = (
390 424
             'Basic',
391 425
             (
392
-                'admin@admin.admin',
393
-                'admin@admin.admin'
426
+                'bob@fsf.local',
427
+                'foobarbaz'
394 428
             )
395 429
         )
396 430
         res = self.testapp.get(
397
-            '/api/v2/workspaces/1/contents',
431
+            '/api/v2/workspaces/3/contents',
398 432
             status=200,
399 433
             params=params,
400 434
         ).json_body   # nopep8
401 435
         # TODO - G.M - 30-05-2018 - Check this test
402
-        raise NotImplementedError()
436
+
437
+        assert len(res) == 1
438
+        content = res[0]
439
+        assert content['content_type_slug'] == 'page'
440
+        assert content['id'] == 17
441
+        assert content['is_archived'] is False
442
+        assert content['is_deleted'] is True
443
+        assert content['label'].startswith('Bad Fruit Salad')
444
+        assert content['parent_id'] is None
445
+        assert content['show_in_ui'] is True
446
+        assert content['slug'].startswith('bad-fruit-salad')
447
+        assert content['status_slug'] == 'open'
448
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
449
+        assert content['workspace_id'] == 3
403 450
 
404 451
     def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
405 452
         """
@@ -407,7 +454,7 @@ class TestWorkspaceContents(FunctionalTest):
407 454
         (archived, deleted, active) result should be empty list.
408 455
         """
409 456
         params = {
410
-            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
457
+            'parent_id': 0,
411 458
             'show_archived': 0,
412 459
             'show_deleted': 0,
413 460
             'show_active': 0,
@@ -415,12 +462,12 @@ class TestWorkspaceContents(FunctionalTest):
415 462
         self.testapp.authorization = (
416 463
             'Basic',
417 464
             (
418
-                'admin@admin.admin',
419
-                'admin@admin.admin'
465
+                'bob@fsf.local',
466
+                'foobarbaz'
420 467
             )
421 468
         )
422 469
         res = self.testapp.get(
423
-            '/api/v2/workspaces/1/contents',
470
+            '/api/v2/workspaces/3/contents',
424 471
             status=200,
425 472
             params=params,
426 473
         ).json_body  # nopep8
@@ -434,7 +481,7 @@ class TestWorkspaceContents(FunctionalTest):
434 481
          Check obtain workspace folder all contents
435 482
          """
436 483
         params = {
437
-            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
484
+            'parent_id': 10,  # TODO - G.M - 30-05-2018 - Find a real id
438 485
             'show_archived': 1,
439 486
             'show_deleted': 1,
440 487
             'show_active': 1,
@@ -447,26 +494,51 @@ class TestWorkspaceContents(FunctionalTest):
447 494
             )
448 495
         )
449 496
         res = self.testapp.get(
450
-            '/api/v2/workspaces/1/contents',
497
+            '/api/v2/workspaces/2/contents',
451 498
             status=200,
452 499
             params=params,
453 500
         ).json_body   # nopep8
454
-        # TODO - G.M - 30-05-2018 - Check this test
455
-        assert len(res) == 1
501
+        assert len(res) == 3
456 502
         content = res[0]
457
-        assert content['id'] == 11
503
+        assert content['content_type_slug'] == 'page'
504
+        assert content['id'] == 12
458 505
         assert content['is_archived'] is False
459 506
         assert content['is_deleted'] is False
460
-        assert content['label'] == 'Current Menu'
461
-        assert content['parent_id'] == 2
462
-        assert content['show_in_ui'] == True
463
-        assert content['slug'] == 'current-menu'
507
+        assert content['label'] == 'New Fruit Salad'
508
+        assert content['parent_id'] == 10
509
+        assert content['show_in_ui'] is True
510
+        assert content['slug'] == 'new-fruit-salad'
464 511
         assert content['status_slug'] == 'open'
465
-        assert set(content['sub_content_type_slug']) == set(['thread', 'page', 'folder', 'file'])
466
-        assert content['workspace_id'] == 1
512
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
513
+        assert content['workspace_id'] == 2
467 514
 
515
+        content = res[1]
516
+        assert content['content_type_slug'] == 'page'
517
+        assert content['id'] == 13
518
+        assert content['is_archived'] is True
519
+        assert content['is_deleted'] is False
520
+        assert content['label'].startswith('Fruit Salad')
521
+        assert content['parent_id'] == 10
522
+        assert content['show_in_ui'] is True
523
+        assert content['slug'].startswith('fruit-salad')
524
+        assert content['status_slug'] == 'open'
525
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
526
+        assert content['workspace_id'] == 2
468 527
 
469
-    def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):
528
+        content = res[2]
529
+        assert content['content_type_slug'] == 'page'
530
+        assert content['id'] == 14
531
+        assert content['is_archived'] is False
532
+        assert content['is_deleted'] is True
533
+        assert content['label'].startswith('Bad Fruit Salad')
534
+        assert content['parent_id'] == 10
535
+        assert content['show_in_ui'] is True
536
+        assert content['slug'].startswith('bad-fruit-salad')
537
+        assert content['status_slug'] == 'open'
538
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
539
+        assert content['workspace_id'] == 2
540
+
541
+    def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):  # nopep8
470 542
         """
471 543
          Check obtain workspace folder active contents
472 544
          """
@@ -488,10 +560,21 @@ class TestWorkspaceContents(FunctionalTest):
488 560
             status=200,
489 561
             params=params,
490 562
         ).json_body   # nopep8
491
-        # TODO - G.M - 30-05-2018 - Check this test
492
-        raise NotImplementedError()
563
+        assert len(res) == 1
564
+        content = res[0]
565
+        assert content['content_type_slug']
566
+        assert content['id'] == 12
567
+        assert content['is_archived'] is False
568
+        assert content['is_deleted'] is False
569
+        assert content['label'] == 'New Fruit Salad'
570
+        assert content['parent_id'] == 10
571
+        assert content['show_in_ui'] is True
572
+        assert content['slug'] == 'new-fruit-salad'
573
+        assert content['status_slug'] == 'open'
574
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
575
+        assert content['workspace_id'] == 2
493 576
 
494
-    def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):
577
+    def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):  # nopep8
495 578
         """
496 579
          Check obtain workspace folder archived contents
497 580
          """
@@ -513,10 +596,21 @@ class TestWorkspaceContents(FunctionalTest):
513 596
             status=200,
514 597
             params=params,
515 598
         ).json_body   # nopep8
516
-        # TODO - G.M - 30-05-2018 - Check this test
517
-        raise NotImplementedError()
599
+        assert len(res) == 1
600
+        content = res[0]
601
+        assert content['content_type_slug'] == 'page'
602
+        assert content['id'] == 13
603
+        assert content['is_archived'] is True
604
+        assert content['is_deleted'] is False
605
+        assert content['label'].startswith('Fruit Salad')
606
+        assert content['parent_id'] == 10
607
+        assert content['show_in_ui'] is True
608
+        assert content['slug'].startswith('fruit-salad')
609
+        assert content['status_slug'] == 'open'
610
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
611
+        assert content['workspace_id'] == 2
518 612
 
519
-    def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):
613
+    def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):  # nopep8
520 614
         """
521 615
          Check obtain workspace folder deleted contents
522 616
          """
@@ -538,10 +632,22 @@ class TestWorkspaceContents(FunctionalTest):
538 632
             status=200,
539 633
             params=params,
540 634
         ).json_body   # nopep8
541
-        # TODO - G.M - 30-05-2018 - Check this test
542
-        raise NotImplementedError()
543 635
 
544
-    def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):
636
+        assert len(res) == 1
637
+        content = res[0]
638
+        assert content['content_type_slug'] == 'page'
639
+        assert content['id'] == 14
640
+        assert content['is_archived'] is False
641
+        assert content['is_deleted'] is True
642
+        assert content['label'].startswith('Bad Fruit Salad')
643
+        assert content['parent_id'] == 10
644
+        assert content['show_in_ui'] is True
645
+        assert content['slug'].startswith('bad-fruit-salad')
646
+        assert content['status_slug'] == 'open'
647
+        assert set(content['sub_content_type_slug']) == {'thread', 'page', 'folder', 'file'}  # nopep8
648
+        assert content['workspace_id'] == 2
649
+
650
+    def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):  # nopep8
545 651
         """
546 652
         Check obtain workspace folder content who does not match any type
547 653
         (archived, deleted, active) result should be empty list.