Quellcode durchsuchen

Fix all test cases for get_workspace_content

Guénaël Muller vor 6 Jahren
Ursprung
Commit
9b2827e6b1
2 geänderte Dateien mit 213 neuen und 71 gelöschten Zeilen
  1. 36 0
      tracim/fixtures/content.py
  2. 177 71
      tracim/tests/functional/test_workspaces.py

+ 36 - 0
tracim/fixtures/content.py Datei anzeigen

200
             content_api.delete(bad_fruit_salad)
200
             content_api.delete(bad_fruit_salad)
201
         content_api.save(bad_fruit_salad)
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
         self._session.flush()
239
         self._session.flush()

+ 177 - 71
tracim/tests/functional/test_workspaces.py Datei anzeigen

2
 """
2
 """
3
 Tests for /api/v2/workspaces subpath endpoints.
3
 Tests for /api/v2/workspaces subpath endpoints.
4
 """
4
 """
5
-import pytest
6
-
7
 from tracim.tests import FunctionalTest
5
 from tracim.tests import FunctionalTest
8
 from tracim.fixtures.content import Content as ContentFixtures
6
 from tracim.fixtures.content import Content as ContentFixtures
9
 from tracim.fixtures.users_and_groups import Base as BaseFixture
7
 from tracim.fixtures.users_and_groups import Base as BaseFixture
246
         assert content['is_deleted'] is False
244
         assert content['is_deleted'] is False
247
         assert content['label'] == 'Tools'
245
         assert content['label'] == 'Tools'
248
         assert content['parent_id'] is None
246
         assert content['parent_id'] is None
249
-        assert content['show_in_ui'] == True
247
+        assert content['show_in_ui'] is True
250
         assert content['slug'] == 'tools'
248
         assert content['slug'] == 'tools'
251
         assert content['status_slug'] == 'open'
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
         assert content['workspace_id'] == 1
251
         assert content['workspace_id'] == 1
254
         content = res[1]
252
         content = res[1]
255
         assert content['id'] == 2
253
         assert content['id'] == 2
257
         assert content['is_deleted'] is False
255
         assert content['is_deleted'] is False
258
         assert content['label'] == 'Menus'
256
         assert content['label'] == 'Menus'
259
         assert content['parent_id'] is None
257
         assert content['parent_id'] is None
260
-        assert content['show_in_ui'] == True
258
+        assert content['show_in_ui'] is True
261
         assert content['slug'] == 'menus'
259
         assert content['slug'] == 'menus'
262
         assert content['status_slug'] == 'open'
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
         assert content['workspace_id'] == 1
262
         assert content['workspace_id'] == 1
265
         content = res[2]
263
         content = res[2]
266
         assert content['id'] == 11
264
         assert content['id'] == 11
268
         assert content['is_deleted'] is False
266
         assert content['is_deleted'] is False
269
         assert content['label'] == 'Current Menu'
267
         assert content['label'] == 'Current Menu'
270
         assert content['parent_id'] == 2
268
         assert content['parent_id'] == 2
271
-        assert content['show_in_ui'] == True
269
+        assert content['show_in_ui'] is True
272
         assert content['slug'] == 'current-menu'
270
         assert content['slug'] == 'current-menu'
273
         assert content['status_slug'] == 'open'
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
         assert content['workspace_id'] == 1
273
         assert content['workspace_id'] == 1
276
 
274
 
277
     # Root related
275
     # Root related
289
         self.testapp.authorization = (
287
         self.testapp.authorization = (
290
             'Basic',
288
             'Basic',
291
             (
289
             (
292
-                'admin@admin.admin',
293
-                'admin@admin.admin'
290
+                'bob@fsf.local',
291
+                'foobarbaz'
294
             )
292
             )
295
         )
293
         )
296
         res = self.testapp.get(
294
         res = self.testapp.get(
297
-            '/api/v2/workspaces/1/contents',
295
+            '/api/v2/workspaces/3/contents',
298
             status=200,
296
             status=200,
299
             params=params,
297
             params=params,
300
         ).json_body  # nopep8
298
         ).json_body  # nopep8
301
         # TODO - G.M - 30-05-2018 - Check this test
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
         assert content['is_archived'] is False
304
         assert content['is_archived'] is False
306
         assert content['is_deleted'] is False
305
         assert content['is_deleted'] is False
307
-        assert content['label'] == 'Tools'
306
+        assert content['label'] == 'New Fruit Salad'
308
         assert content['parent_id'] is None
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
         assert content['status_slug'] == 'open'
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
         assert content['is_deleted'] is False
318
         assert content['is_deleted'] is False
318
-        assert content['label'] == 'Menus'
319
+        assert content['label'].startswith('Fruit Salad')
319
         assert content['parent_id'] is None
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
         assert content['status_slug'] == 'open'
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
         Check obtain workspace root active contents
342
         Check obtain workspace root active contents
330
         """
343
         """
337
         self.testapp.authorization = (
350
         self.testapp.authorization = (
338
             'Basic',
351
             'Basic',
339
             (
352
             (
340
-                'admin@admin.admin',
341
-                'admin@admin.admin'
353
+                'bob@fsf.local',
354
+                'foobarbaz'
342
             )
355
             )
343
         )
356
         )
344
         res = self.testapp.get(
357
         res = self.testapp.get(
345
-            '/api/v2/workspaces/1/contents',
358
+            '/api/v2/workspaces/3/contents',
346
             status=200,
359
             status=200,
347
             params=params,
360
             params=params,
348
         ).json_body   # nopep8
361
         ).json_body   # nopep8
349
         # TODO - G.M - 30-05-2018 - Check this test
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
         Check obtain workspace root archived contents
379
         Check obtain workspace root archived contents
356
         """
380
         """
363
         self.testapp.authorization = (
387
         self.testapp.authorization = (
364
             'Basic',
388
             'Basic',
365
             (
389
             (
366
-                'admin@admin.admin',
367
-                'admin@admin.admin'
390
+                'bob@fsf.local',
391
+                'foobarbaz'
368
             )
392
             )
369
         )
393
         )
370
         res = self.testapp.get(
394
         res = self.testapp.get(
371
-            '/api/v2/workspaces/1/contents',
395
+            '/api/v2/workspaces/3/contents',
372
             status=200,
396
             status=200,
373
             params=params,
397
             params=params,
374
         ).json_body   # nopep8
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
          Check obtain workspace root deleted contents
415
          Check obtain workspace root deleted contents
382
          """
416
          """
389
         self.testapp.authorization = (
423
         self.testapp.authorization = (
390
             'Basic',
424
             'Basic',
391
             (
425
             (
392
-                'admin@admin.admin',
393
-                'admin@admin.admin'
426
+                'bob@fsf.local',
427
+                'foobarbaz'
394
             )
428
             )
395
         )
429
         )
396
         res = self.testapp.get(
430
         res = self.testapp.get(
397
-            '/api/v2/workspaces/1/contents',
431
+            '/api/v2/workspaces/3/contents',
398
             status=200,
432
             status=200,
399
             params=params,
433
             params=params,
400
         ).json_body   # nopep8
434
         ).json_body   # nopep8
401
         # TODO - G.M - 30-05-2018 - Check this test
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
     def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
451
     def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
405
         """
452
         """
407
         (archived, deleted, active) result should be empty list.
454
         (archived, deleted, active) result should be empty list.
408
         """
455
         """
409
         params = {
456
         params = {
410
-            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
457
+            'parent_id': 0,
411
             'show_archived': 0,
458
             'show_archived': 0,
412
             'show_deleted': 0,
459
             'show_deleted': 0,
413
             'show_active': 0,
460
             'show_active': 0,
415
         self.testapp.authorization = (
462
         self.testapp.authorization = (
416
             'Basic',
463
             'Basic',
417
             (
464
             (
418
-                'admin@admin.admin',
419
-                'admin@admin.admin'
465
+                'bob@fsf.local',
466
+                'foobarbaz'
420
             )
467
             )
421
         )
468
         )
422
         res = self.testapp.get(
469
         res = self.testapp.get(
423
-            '/api/v2/workspaces/1/contents',
470
+            '/api/v2/workspaces/3/contents',
424
             status=200,
471
             status=200,
425
             params=params,
472
             params=params,
426
         ).json_body  # nopep8
473
         ).json_body  # nopep8
434
          Check obtain workspace folder all contents
481
          Check obtain workspace folder all contents
435
          """
482
          """
436
         params = {
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
             'show_archived': 1,
485
             'show_archived': 1,
439
             'show_deleted': 1,
486
             'show_deleted': 1,
440
             'show_active': 1,
487
             'show_active': 1,
447
             )
494
             )
448
         )
495
         )
449
         res = self.testapp.get(
496
         res = self.testapp.get(
450
-            '/api/v2/workspaces/1/contents',
497
+            '/api/v2/workspaces/2/contents',
451
             status=200,
498
             status=200,
452
             params=params,
499
             params=params,
453
         ).json_body   # nopep8
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
         content = res[0]
502
         content = res[0]
457
-        assert content['id'] == 11
503
+        assert content['content_type_slug'] == 'page'
504
+        assert content['id'] == 12
458
         assert content['is_archived'] is False
505
         assert content['is_archived'] is False
459
         assert content['is_deleted'] is False
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
         assert content['status_slug'] == 'open'
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
          Check obtain workspace folder active contents
543
          Check obtain workspace folder active contents
472
          """
544
          """
488
             status=200,
560
             status=200,
489
             params=params,
561
             params=params,
490
         ).json_body   # nopep8
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
          Check obtain workspace folder archived contents
579
          Check obtain workspace folder archived contents
497
          """
580
          """
513
             status=200,
596
             status=200,
514
             params=params,
597
             params=params,
515
         ).json_body   # nopep8
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
          Check obtain workspace folder deleted contents
615
          Check obtain workspace folder deleted contents
522
          """
616
          """
538
             status=200,
632
             status=200,
539
             params=params,
633
             params=params,
540
         ).json_body   # nopep8
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
         Check obtain workspace folder content who does not match any type
652
         Check obtain workspace folder content who does not match any type
547
         (archived, deleted, active) result should be empty list.
653
         (archived, deleted, active) result should be empty list.