Browse Source

Merge branch 'develop' of github.com:tracim/tracim_v2 into develop

AlexiCauvin 5 years ago
parent
commit
e1c97b5bcb

+ 1 - 1
backend/tracim_backend/models/context_models.py View File

@@ -291,7 +291,7 @@ class ContentCreation(object):
291 291
     ) -> None:
292 292
         self.label = label
293 293
         self.content_type = content_type
294
-        self.parent_id = parent_id
294
+        self.parent_id = parent_id or None
295 295
 
296 296
 
297 297
 class CommentCreation(object):

+ 65 - 0
backend/tracim_backend/tests/functional/test_workspaces.py View File

@@ -1436,6 +1436,7 @@ class TestWorkspaceContents(FunctionalTest):
1436 1436
             )
1437 1437
         )
1438 1438
         params = {
1439
+            'parent_id': None,
1439 1440
             'label': 'GenericCreatedContent',
1440 1441
             'content_type': 'markdownpage',
1441 1442
         }
@@ -1466,6 +1467,70 @@ class TestWorkspaceContents(FunctionalTest):
1466 1467
         active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body  # nopep8
1467 1468
         assert res.json_body in active_contents
1468 1469
 
1470
+    def test_api__post_content_create_generic_content__ok_200__no_parent_id_param(self) -> None:  # nopep8
1471
+        """
1472
+        Create generic content
1473
+        """
1474
+        self.testapp.authorization = (
1475
+            'Basic',
1476
+            (
1477
+                'admin@admin.admin',
1478
+                'admin@admin.admin'
1479
+            )
1480
+        )
1481
+        params = {
1482
+            'label': 'GenericCreatedContent',
1483
+            'content_type': 'markdownpage',
1484
+        }
1485
+        res = self.testapp.post_json(
1486
+            '/api/v2/workspaces/1/contents',
1487
+            params=params,
1488
+            status=200
1489
+        )
1490
+        assert res
1491
+        assert res.json_body
1492
+        assert res.json_body['status'] == 'open'
1493
+        assert res.json_body['content_id']
1494
+        assert res.json_body['content_type'] == 'markdownpage'
1495
+        assert res.json_body['is_archived'] is False
1496
+        assert res.json_body['is_deleted'] is False
1497
+        assert res.json_body['workspace_id'] == 1
1498
+        assert res.json_body['slug'] == 'genericcreatedcontent'
1499
+        assert res.json_body['parent_id'] is None
1500
+        assert res.json_body['show_in_ui'] is True
1501
+        assert res.json_body['sub_content_types']
1502
+        params_active = {
1503
+            'parent_id': 0,
1504
+            'show_archived': 0,
1505
+            'show_deleted': 0,
1506
+            'show_active': 1,
1507
+        }
1508
+        # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
1509
+        active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body  # nopep8
1510
+        assert res.json_body in active_contents
1511
+
1512
+    def test_api__post_content_create_generic_content__err_400__parent_id_0(self) -> None:  # nopep8
1513
+        """
1514
+        Create generic content
1515
+        """
1516
+        self.testapp.authorization = (
1517
+            'Basic',
1518
+            (
1519
+                'admin@admin.admin',
1520
+                'admin@admin.admin'
1521
+            )
1522
+        )
1523
+        params = {
1524
+            'parent_id': 0,
1525
+            'label': 'GenericCreatedContent',
1526
+            'content_type': 'markdownpage',
1527
+        }
1528
+        res = self.testapp.post_json(
1529
+            '/api/v2/workspaces/1/contents',
1530
+            params=params,
1531
+            status=400
1532
+        )
1533
+
1469 1534
     def test_api__post_content_create_generic_content__ok_200__in_folder(self) -> None:  # nopep8
1470 1535
         """
1471 1536
         Create generic content in folder

+ 5 - 2
backend/tracim_backend/views/core_api/schemas.py View File

@@ -650,12 +650,15 @@ class ContentCreationSchema(marshmallow.Schema):
650 650
     )
651 651
     parent_id = marshmallow.fields.Integer(
652 652
         example=35,
653
-        description='content_id of parent content, if content should be placed in a folder, this should be folder content_id.'
653
+        description='content_id of parent content, if content should be placed in a folder, this should be folder content_id.', # nopep8
654
+        allow_none=True,
655
+        default=None,
656
+        validate=Range(min=1, error="Value must be positive"),
654 657
     )
655 658
 
656 659
 
657 660
     @post_load
658
-    def make_content_filter(self, data):
661
+    def make_content_creation(self, data):
659 662
         return ContentCreation(**data)
660 663
 
661 664