Browse Source

fix move content to root case

Guénaël Muller 6 years ago
parent
commit
f5b7e9b92c
2 changed files with 93 additions and 2 deletions
  1. 4 2
      tracim/lib/core/content.py
  2. 89 0
      tracim/tests/functional/test_workspaces.py

+ 4 - 2
tracim/lib/core/content.py View File

@@ -876,12 +876,14 @@ class ContentApi(object):
876 876
         item.parent = new_parent
877 877
         if new_workspace:
878 878
             item.workspace = new_workspace
879
-            if new_parent.workspace_id != new_workspace.workspace_id:
879
+            if new_parent and \
880
+                    new_parent.workspace_id != new_workspace.workspace_id:
880 881
                 raise NotSameWorkspace(
881 882
                     'new parent workspace and new workspace should be the same.'
882 883
                 )
883 884
         else:
884
-            item.workspace = new_parent.workspace
885
+            if new_parent:
886
+                item.workspace = new_parent.workspace
885 887
 
886 888
         item.revision_type = ActionDescription.MOVE
887 889
 

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

@@ -814,6 +814,50 @@ class TestWorkspaceContents(FunctionalTest):
814 814
         assert not [content for content in new_folder1_contents if content['id'] == 8]  # nopep8
815 815
         assert [content for content in new_folder2_contents if content['id'] == 8]  # nopep8
816 816
 
817
+    def test_api_put_move_content__ok_200__to_root(self):
818
+        """
819
+        Move content
820
+        move Apple_Pie (content_id: 8)
821
+        from Desserts folder(content_id: 3) to root (content_id: 0)
822
+        of workspace Recipes.
823
+        """
824
+        self.testapp.authorization = (
825
+            'Basic',
826
+            (
827
+                'admin@admin.admin',
828
+                'admin@admin.admin'
829
+            )
830
+        )
831
+        params = {
832
+            'new_parent_id': '0',  # root
833
+        }
834
+        params_folder1 = {
835
+            'parent_id': 3,
836
+            'show_archived': 0,
837
+            'show_deleted': 0,
838
+            'show_active': 1,
839
+        }
840
+        params_folder2 = {
841
+            'parent_id': 0,
842
+            'show_archived': 0,
843
+            'show_deleted': 0,
844
+            'show_active': 1,
845
+        }
846
+        folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
847
+        folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
848
+        assert [content for content in folder1_contents if content['id'] == 8]  # nopep8
849
+        assert not [content for content in folder2_contents if content['id'] == 8]  # nopep8
850
+        # TODO - G.M - 2018-06-163 - Check content
851
+        res = self.testapp.put_json(
852
+            '/api/v2/workspaces/2/contents/8/move',
853
+            params=params,
854
+            status=200
855
+        )
856
+        new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
857
+        new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
858
+        assert not [content for content in new_folder1_contents if content['id'] == 8]  # nopep8
859
+        assert [content for content in new_folder2_contents if content['id'] == 8]  # nopep8
860
+
817 861
     def test_api_put_move_content__ok_200__with_workspace_id(self):
818 862
         """
819 863
         Move content
@@ -903,6 +947,51 @@ class TestWorkspaceContents(FunctionalTest):
903 947
         assert not [content for content in new_folder1_contents if content['id'] == 8]  # nopep8
904 948
         assert [content for content in new_folder2_contents if content['id'] == 8]  # nopep8
905 949
 
950
+    def test_api_put_move_content__ok_200__to_another_workspace_root(self):
951
+        """
952
+        Move content
953
+        move Apple_Pie (content_id: 8)
954
+        from Desserts folder(content_id: 3) to root (content_id: 0)
955
+        of workspace Business.
956
+        """
957
+        self.testapp.authorization = (
958
+            'Basic',
959
+            (
960
+                'admin@admin.admin',
961
+                'admin@admin.admin'
962
+            )
963
+        )
964
+        params = {
965
+            'new_parent_id': '0', # root
966
+            'new_workspace_id': '1',
967
+        }
968
+        params_folder1 = {
969
+            'parent_id': 3,
970
+            'show_archived': 0,
971
+            'show_deleted': 0,
972
+            'show_active': 1,
973
+        }
974
+        params_folder2 = {
975
+            'parent_id': 0,
976
+            'show_archived': 0,
977
+            'show_deleted': 0,
978
+            'show_active': 1,
979
+        }
980
+        folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
981
+        folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
982
+        assert [content for content in folder1_contents if content['id'] == 8]  # nopep8
983
+        assert not [content for content in folder2_contents if content['id'] == 8]  # nopep8
984
+        # TODO - G.M - 2018-06-163 - Check content
985
+        res = self.testapp.put_json(
986
+            '/api/v2/workspaces/2/contents/8/move',
987
+            params=params,
988
+            status=200
989
+        )
990
+        new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
991
+        new_folder2_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_folder2, status=200).json_body  # nopep8
992
+        assert not [content for content in new_folder1_contents if content['id'] == 8]  # nopep8
993
+        assert [content for content in new_folder2_contents if content['id'] == 8]  # nopep8
994
+
906 995
     def test_api_put_move_content__err_400__wrong_workspace_id(self):
907 996
         """
908 997
         Move content