Browse Source

add WIP tests for get contents_types and contents

Guénaël Muller 6 years ago
parent
commit
76418729bc
2 changed files with 384 additions and 1 deletions
  1. 46 1
      tracim/tests/functional/test_system.py
  2. 338 0
      tracim/tests/functional/test_workspaces.py

+ 46 - 1
tracim/tests/functional/test_system.py View File

@@ -59,7 +59,7 @@ class TestApplicationsEndpoint(FunctionalTest):
59 59
         assert application['is_active'] is True
60 60
         assert 'config' in application
61 61
 
62
-    def test_api__get_workspace__err_401__unregistered_user(self):
62
+    def test_api__get_applications__err_401__unregistered_user(self):
63 63
         """
64 64
         Get applications list with an unregistered user (bad auth)
65 65
         """
@@ -75,3 +75,48 @@ class TestApplicationsEndpoint(FunctionalTest):
75 75
         assert 'code' in res.json.keys()
76 76
         assert 'message' in res.json.keys()
77 77
         assert 'details' in res.json.keys()
78
+
79
+
80
+class TestContentsTypesEndpoint(FunctionalTest):
81
+    """
82
+    Tests for /api/v2/system/content_types
83
+    """
84
+
85
+    def test_api__get_content_types__ok_200__nominal_case(self):
86
+        """
87
+        Get system content_types list with a registered user.
88
+        """
89
+        self.testapp.authorization = (
90
+            'Basic',
91
+            (
92
+                'admin@admin.admin',
93
+                'admin@admin.admin'
94
+            )
95
+        )
96
+        res = self.testapp.get('/api/v2/system/content_types', status=200)
97
+        res = res.json_body
98
+        content_type = res[0]
99
+        assert content_type['slug'] == 'pagehtml'
100
+        assert content_type['icon'] == 'file-text-o'
101
+        assert content_type['hexcolor'] == '#3f52e3'
102
+        assert content_type['label'] == 'Text Documents'
103
+        assert content_type['creation_label'] == 'Write a document'
104
+        assert 'available_statuses' in content_type
105
+        # TODO - G.M - 29-05-2018 - Better check for available_statuses
106
+
107
+    def test_api__get_content_types__err_401__unregistered_user(self):
108
+        """
109
+        Get system content_types list with an unregistered user (bad auth)
110
+        """
111
+        self.testapp.authorization = (
112
+            'Basic',
113
+            (
114
+                'john@doe.doe',
115
+                'lapin'
116
+            )
117
+        )
118
+        res = self.testapp.get('/api/v2/system/content_types', status=401)
119
+        assert isinstance(res.json, dict)
120
+        assert 'code' in res.json.keys()
121
+        assert 'message' in res.json.keys()
122
+        assert 'details' in res.json.keys()

+ 338 - 0
tracim/tests/functional/test_workspaces.py View File

@@ -215,3 +215,341 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
215 215
         assert 'code' in res.json.keys()
216 216
         assert 'message' in res.json.keys()
217 217
         assert 'details' in res.json.keys()
218
+
219
+
220
+class TestWorkspaceContents(FunctionalTest):
221
+    """
222
+    Tests for /api/v2/workspaces/{workspace_id}/contents endpoint
223
+    """
224
+
225
+    fixtures = [BaseFixture, ContentFixtures]
226
+
227
+    def test_api__get_workspace_content__ok_200__get_default(self):
228
+        """
229
+        Check obtain workspace contents with defaults filters
230
+        """
231
+        self.testapp.authorization = (
232
+            'Basic',
233
+            (
234
+                'admin@admin.admin',
235
+                'admin@admin.admin'
236
+            )
237
+        )
238
+        res = self.testapp.get('/api/v2/workspaces/1/contents', status=200).json_body   # nopep8
239
+        # TODO - G.M - 30-05-2018 - Check this test
240
+        raise NotImplementedError()
241
+
242
+    # Root related
243
+
244
+    def test_api__get_workspace_content__ok_200__get_all_root_content(self):
245
+        """
246
+        Check obtain workspace all root contents
247
+        """
248
+        params = {
249
+            'parent_id': 0,
250
+            'show_archived': 1,
251
+            'show_deleted': 1,
252
+            'show_active': 1,
253
+        }
254
+        self.testapp.authorization = (
255
+            'Basic',
256
+            (
257
+                'admin@admin.admin',
258
+                'admin@admin.admin'
259
+            )
260
+        )
261
+        res = self.testapp.get(
262
+            '/api/v2/workspaces/1/contents',
263
+            status=200,
264
+            params=params,
265
+        ).json_body  # nopep8
266
+        # TODO - G.M - 30-05-2018 - Check this test
267
+        raise NotImplementedError()
268
+
269
+    def test_api__get_workspace_content__ok_200__get_only_active_root_content(self):
270
+        """
271
+        Check obtain workspace root active contents
272
+        """
273
+        params = {
274
+            'parent_id': 0,
275
+            'show_archived': 0,
276
+            'show_deleted': 0,
277
+            'show_active': 1,
278
+        }
279
+        self.testapp.authorization = (
280
+            'Basic',
281
+            (
282
+                'admin@admin.admin',
283
+                'admin@admin.admin'
284
+            )
285
+        )
286
+        res = self.testapp.get(
287
+            '/api/v2/workspaces/1/contents',
288
+            status=200,
289
+            params=params,
290
+        ).json_body   # nopep8
291
+        # TODO - G.M - 30-05-2018 - Check this test
292
+        raise NotImplementedError()
293
+
294
+    def test_api__get_workspace_content__ok_200__get_only_archived_root_content(self):
295
+        """
296
+        Check obtain workspace root archived contents
297
+        """
298
+        params = {
299
+            'parent_id': 0,
300
+            'show_archived': 1,
301
+            'show_deleted': 0,
302
+            'show_active': 0,
303
+        }
304
+        self.testapp.authorization = (
305
+            'Basic',
306
+            (
307
+                'admin@admin.admin',
308
+                'admin@admin.admin'
309
+            )
310
+        )
311
+        res = self.testapp.get(
312
+            '/api/v2/workspaces/1/contents',
313
+            status=200,
314
+            params=params,
315
+        ).json_body   # nopep8
316
+        # TODO - G.M - 30-05-2018 - Check this test
317
+        raise NotImplementedError()
318
+
319
+    def test_api__get_workspace_content__ok_200__get_only_deleted_root_content(self):
320
+        """
321
+         Check obtain workspace root deleted contents
322
+         """
323
+        params = {
324
+            'parent_id': 0,
325
+            'show_archived': 0,
326
+            'show_deleted': 1,
327
+            'show_active': 0,
328
+        }
329
+        self.testapp.authorization = (
330
+            'Basic',
331
+            (
332
+                'admin@admin.admin',
333
+                'admin@admin.admin'
334
+            )
335
+        )
336
+        res = self.testapp.get(
337
+            '/api/v2/workspaces/1/contents',
338
+            status=200,
339
+            params=params,
340
+        ).json_body   # nopep8
341
+        # TODO - G.M - 30-05-2018 - Check this test
342
+        raise NotImplementedError()
343
+
344
+    def test_api__get_workspace_content__ok_200__get_nothing_root_content(self):
345
+        """
346
+        Check obtain workspace root content who does not match any type
347
+        (archived, deleted, active) result should be empty list.
348
+        """
349
+        params = {
350
+            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
351
+            'show_archived': 0,
352
+            'show_deleted': 0,
353
+            'show_active': 0,
354
+        }
355
+        self.testapp.authorization = (
356
+            'Basic',
357
+            (
358
+                'admin@admin.admin',
359
+                'admin@admin.admin'
360
+            )
361
+        )
362
+        res = self.testapp.get(
363
+            '/api/v2/workspaces/1/contents',
364
+            status=200,
365
+            params=params,
366
+        ).json_body  # nopep8
367
+        # TODO - G.M - 30-05-2018 - Check this test
368
+        raise NotImplementedError()
369
+
370
+    # Folder related
371
+
372
+    def test_api__get_workspace_content__ok_200__get_all_folder_content(self):
373
+        """
374
+         Check obtain workspace folder all contents
375
+         """
376
+        params = {
377
+            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
378
+            'show_archived': 1,
379
+            'show_deleted': 1,
380
+            'show_active': 1,
381
+        }
382
+        self.testapp.authorization = (
383
+            'Basic',
384
+            (
385
+                'admin@admin.admin',
386
+                'admin@admin.admin'
387
+            )
388
+        )
389
+        res = self.testapp.get(
390
+            '/api/v2/workspaces/1/contents',
391
+            status=200,
392
+            params=params,
393
+        ).json_body   # nopep8
394
+        # TODO - G.M - 30-05-2018 - Check this test
395
+        raise NotImplementedError()
396
+
397
+    def test_api__get_workspace_content__ok_200__get_only_active_folder_content(self):
398
+        """
399
+         Check obtain workspace folder active contents
400
+         """
401
+        params = {
402
+            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
403
+            'show_archived': 0,
404
+            'show_deleted': 0,
405
+            'show_active': 1,
406
+        }
407
+        self.testapp.authorization = (
408
+            'Basic',
409
+            (
410
+                'admin@admin.admin',
411
+                'admin@admin.admin'
412
+            )
413
+        )
414
+        res = self.testapp.get(
415
+            '/api/v2/workspaces/1/contents',
416
+            status=200,
417
+            params=params,
418
+        ).json_body   # nopep8
419
+        # TODO - G.M - 30-05-2018 - Check this test
420
+        raise NotImplementedError()
421
+
422
+    def test_api__get_workspace_content__ok_200__get_only_archived_folder_content(self):
423
+        """
424
+         Check obtain workspace folder archived contents
425
+         """
426
+        params = {
427
+            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
428
+            'show_archived': 0,
429
+            'show_deleted': 0,
430
+            'show_active': 1,
431
+        }
432
+        self.testapp.authorization = (
433
+            'Basic',
434
+            (
435
+                'admin@admin.admin',
436
+                'admin@admin.admin'
437
+            )
438
+        )
439
+        res = self.testapp.get(
440
+            '/api/v2/workspaces/1/contents',
441
+            status=200,
442
+            params=params,
443
+        ).json_body   # nopep8
444
+        # TODO - G.M - 30-05-2018 - Check this test
445
+        raise NotImplementedError()
446
+
447
+    def test_api__get_workspace_content__ok_200__get_only_deleted_folder_content(self):
448
+        """
449
+         Check obtain workspace folder deleted contents
450
+         """
451
+        params = {
452
+            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
453
+            'show_archived': 0,
454
+            'show_deleted': 0,
455
+            'show_active': 1,
456
+        }
457
+        self.testapp.authorization = (
458
+            'Basic',
459
+            (
460
+                'admin@admin.admin',
461
+                'admin@admin.admin'
462
+            )
463
+        )
464
+        res = self.testapp.get(
465
+            '/api/v2/workspaces/1/contents',
466
+            status=200,
467
+            params=params,
468
+        ).json_body   # nopep8
469
+        # TODO - G.M - 30-05-2018 - Check this test
470
+        raise NotImplementedError()
471
+
472
+    def test_api__get_workspace_content__ok_200__get_nothing_folder_content(self):
473
+        """
474
+        Check obtain workspace folder content who does not match any type
475
+        (archived, deleted, active) result should be empty list.
476
+        """
477
+        params = {
478
+            'parent_id': 2,  # TODO - G.M - 30-05-2018 - Find a real id
479
+            'show_archived': 0,
480
+            'show_deleted': 0,
481
+            'show_active': 0,
482
+        }
483
+        self.testapp.authorization = (
484
+            'Basic',
485
+            (
486
+                'admin@admin.admin',
487
+                'admin@admin.admin'
488
+            )
489
+        )
490
+        res = self.testapp.get(
491
+            '/api/v2/workspaces/1/contents',
492
+            status=200,
493
+            params=params,
494
+        ).json_body   # nopep8
495
+        # TODO - G.M - 30-05-2018 - Check this test
496
+        raise NotImplementedError()
497
+
498
+    # Error case
499
+
500
+    def test_api__get_workspace_content__err_403__unallowed_user(self):
501
+        """
502
+        Check obtain workspace content list with an unreachable workspace for
503
+        user
504
+        """
505
+        self.testapp.authorization = (
506
+            'Basic',
507
+            (
508
+                'lawrence-not-real-email@fsf.local',
509
+                'foobarbaz'
510
+            )
511
+        )
512
+        res = self.testapp.get('/api/v2/workspaces/3/contents', status=403)
513
+        assert isinstance(res.json, dict)
514
+        assert 'code' in res.json.keys()
515
+        assert 'message' in res.json.keys()
516
+        assert 'details' in res.json.keys()
517
+
518
+    def test_api__get_workspace_content__err_401__unregistered_user(self):
519
+        """
520
+        Check obtain workspace content list with an unregistered user
521
+        """
522
+        self.testapp.authorization = (
523
+            'Basic',
524
+            (
525
+                'john@doe.doe',
526
+                'lapin'
527
+            )
528
+        )
529
+        res = self.testapp.get('/api/v2/workspaces/1/contents', status=401)
530
+        assert isinstance(res.json, dict)
531
+        assert 'code' in res.json.keys()
532
+        assert 'message' in res.json.keys()
533
+        assert 'details' in res.json.keys()
534
+
535
+    def test_api__get_workspace_content__err_403__workspace_does_not_exist(self):  # nopep8
536
+        """
537
+        Check obtain workspace contents list with an existing user but
538
+        an unexisting workspace
539
+        """
540
+        self.testapp.authorization = (
541
+            'Basic',
542
+            (
543
+                'admin@admin.admin',
544
+                'admin@admin.admin'
545
+            )
546
+        )
547
+        res = self.testapp.get('/api/v2/workspaces/5/contents', status=403)
548
+        assert isinstance(res.json, dict)
549
+        assert 'code' in res.json.keys()
550
+        assert 'message' in res.json.keys()
551
+        assert 'details' in res.json.keys()
552
+
553
+    def test_api_get_workspace_content__err_404__parent_id_does_not_exist(self):
554
+        # TODO - G.M - 30-05-2018 - Check this test
555
+        raise NotImplementedError()