Browse Source

Better tests for workspaces put/post endpoints + add MarkdownPaga as displayable content

Guénaël Muller 6 years ago
parent
commit
772d2f7f22
3 changed files with 122 additions and 17 deletions
  1. 1 0
      tracim/lib/core/content.py
  2. 1 0
      tracim/models/contents.py
  3. 120 17
      tracim/tests/functional/test_workspaces.py

+ 1 - 0
tracim/lib/core/content.py View File

105
         ContentType.Comment,
105
         ContentType.Comment,
106
         ContentType.Thread,
106
         ContentType.Thread,
107
         ContentType.Page,
107
         ContentType.Page,
108
+        ContentType.MarkdownPage,
108
     )
109
     )
109
 
110
 
110
     def __init__(
111
     def __init__(

+ 1 - 0
tracim/models/contents.py View File

201
     File = file_type.slug
201
     File = file_type.slug
202
     Thread = thread_type.slug
202
     Thread = thread_type.slug
203
     Page = htmlpage_type.slug
203
     Page = htmlpage_type.slug
204
+    MarkdownPage = markdownpluspage_type.slug
204
 
205
 
205
     def __init__(self, slug: str):
206
     def __init__(self, slug: str):
206
         for content_type in CONTENT_DEFAULT_TYPE:
207
         for content_type in CONTENT_DEFAULT_TYPE:

+ 120 - 17
tracim/tests/functional/test_workspaces.py View File

728
         assert 'message' in res.json.keys()
728
         assert 'message' in res.json.keys()
729
         assert 'details' in res.json.keys()
729
         assert 'details' in res.json.keys()
730
 
730
 
731
-    def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None:
731
+    def test_api__post_content_create_generic_content__ok_200__nominal_case(self) -> None:  # nopep8
732
         """
732
         """
733
         Create generic content
733
         Create generic content
734
         """
734
         """
760
         assert res.json_body['parent_id'] is None
760
         assert res.json_body['parent_id'] is None
761
         assert res.json_body['show_in_ui'] is True
761
         assert res.json_body['show_in_ui'] is True
762
         assert res.json_body['sub_content_type_slug']
762
         assert res.json_body['sub_content_type_slug']
763
+        params_active = {
764
+            'parent_id': 0,
765
+            'show_archived': 0,
766
+            'show_deleted': 0,
767
+            'show_active': 1,
768
+        }
769
+        # INFO - G.M - 2018-06-165 - Verify if new content is correctly created
770
+        active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body  # nopep8
771
+        assert res.json_body in active_contents
763
 
772
 
764
     def test_api_put_move_content__ok_200__nominal_case(self):
773
     def test_api_put_move_content__ok_200__nominal_case(self):
765
         """
774
         """
766
         Move content
775
         Move content
776
+        move Apple_Pie (content_id: 8)
777
+        from Desserts folder(content_id: 3) to Salads subfolder (content_id: 4)
778
+        of workspace Recipes.
767
         """
779
         """
768
         self.testapp.authorization = (
780
         self.testapp.authorization = (
769
             'Basic',
781
             'Basic',
775
         params = {
787
         params = {
776
             'new_parent_id': '4',  # Salads
788
             'new_parent_id': '4',  # Salads
777
         }
789
         }
790
+        params_folder1 = {
791
+            'parent_id': 3,
792
+            'show_archived': 0,
793
+            'show_deleted': 0,
794
+            'show_active': 1,
795
+        }
796
+        params_folder2 = {
797
+            'parent_id': 4,
798
+            'show_archived': 0,
799
+            'show_deleted': 0,
800
+            'show_active': 1,
801
+        }
802
+        folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
803
+        folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
804
+        assert [content for content in folder1_contents if content['id'] == 8]  # nopep8
805
+        assert not [content for content in folder2_contents if content['id'] == 8]  # nopep8
778
         # TODO - G.M - 2018-06-163 - Check content
806
         # TODO - G.M - 2018-06-163 - Check content
779
         res = self.testapp.put_json(
807
         res = self.testapp.put_json(
780
-            # INFO - G.M - 2018-06-163 - move Apple_Pie
781
-            # from Desserts to Salads subfolder of workspace Recipes
782
             '/api/v2/workspaces/2/contents/8/move',
808
             '/api/v2/workspaces/2/contents/8/move',
783
             params=params,
809
             params=params,
784
             status=200
810
             status=200
785
         )
811
         )
786
-        # TODO - G.M - 2018-06-163 - Recheck content
812
+        new_folder1_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder1, status=200).json_body  # nopep8
813
+        new_folder2_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_folder2, status=200).json_body  # nopep8
814
+        assert not [content for content in new_folder1_contents if content['id'] == 8]  # nopep8
815
+        assert [content for content in new_folder2_contents if content['id'] == 8]  # nopep8
787
 
816
 
788
     def test_api_put_delete_content__ok_200__nominal_case(self):
817
     def test_api_put_delete_content__ok_200__nominal_case(self):
789
         """
818
         """
790
-        Move content
819
+        delete content
820
+        delete Apple_pie ( content_id: 8, parent_id: 3)
791
         """
821
         """
792
         self.testapp.authorization = (
822
         self.testapp.authorization = (
793
             'Basic',
823
             'Basic',
796
                 'admin@admin.admin'
826
                 'admin@admin.admin'
797
             )
827
             )
798
         )
828
         )
829
+        params_active = {
830
+            'parent_id': 3,
831
+            'show_archived': 0,
832
+            'show_deleted': 0,
833
+            'show_active': 1,
834
+        }
835
+        params_deleted = {
836
+            'parent_id': 3,
837
+            'show_archived': 0,
838
+            'show_deleted': 1,
839
+            'show_active': 0,
840
+        }
841
+        active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
842
+        deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
843
+        assert [content for content in active_contents if content['id'] == 8]  # nopep8
844
+        assert not [content for content in deleted_contents if content['id'] == 8]  # nopep8
799
         # TODO - G.M - 2018-06-163 - Check content
845
         # TODO - G.M - 2018-06-163 - Check content
800
         res = self.testapp.put_json(
846
         res = self.testapp.put_json(
801
             # INFO - G.M - 2018-06-163 - delete Apple_Pie
847
             # INFO - G.M - 2018-06-163 - delete Apple_Pie
802
             '/api/v2/workspaces/2/contents/8/delete',
848
             '/api/v2/workspaces/2/contents/8/delete',
803
             status=200
849
             status=200
804
         )
850
         )
805
-        # TODO - G.M - 2018-06-163 - Recheck content
851
+        new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
852
+        new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
853
+        assert not [content for content in new_active_contents if content['id'] == 8]  # nopep8
854
+        assert [content for content in new_deleted_contents if content['id'] == 8]  # nopep8
806
 
855
 
807
     def test_api_put_archive_content__ok_200__nominal_case(self):
856
     def test_api_put_archive_content__ok_200__nominal_case(self):
808
         """
857
         """
809
         archive content
858
         archive content
859
+        archive Apple_pie ( content_id: 8, parent_id: 3)
810
         """
860
         """
811
         self.testapp.authorization = (
861
         self.testapp.authorization = (
812
             'Basic',
862
             'Basic',
815
                 'admin@admin.admin'
865
                 'admin@admin.admin'
816
             )
866
             )
817
         )
867
         )
818
-        # TODO - G.M - 2018-06-163 - Check content
868
+        params_active = {
869
+            'parent_id': 3,
870
+            'show_archived': 0,
871
+            'show_deleted': 0,
872
+            'show_active': 1,
873
+        }
874
+        params_archived = {
875
+            'parent_id': 3,
876
+            'show_archived': 1,
877
+            'show_deleted': 0,
878
+            'show_active': 0,
879
+        }
880
+        active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
881
+        archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
882
+        assert [content for content in active_contents if content['id'] == 8]  # nopep8
883
+        assert not [content for content in archived_contents if content['id'] == 8]  # nopep8
819
         res = self.testapp.put_json(
884
         res = self.testapp.put_json(
820
-            # INFO - G.M - 2018-06-163 - archive Apple_Pie
821
             '/api/v2/workspaces/2/contents/8/archive',
885
             '/api/v2/workspaces/2/contents/8/archive',
822
             status=200
886
             status=200
823
         )
887
         )
824
-        # TODO - G.M - 2018-06-163 - Recheck content
888
+        new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
889
+        new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
890
+        assert not [content for content in new_active_contents if content['id'] == 8]  # nopep8
891
+        assert [content for content in new_archived_contents if content['id'] == 8]  # nopep8
825
 
892
 
826
     def test_api_put_undelete_content__ok_200__nominal_case(self):
893
     def test_api_put_undelete_content__ok_200__nominal_case(self):
827
         """
894
         """
828
-        Delete content
895
+        Undelete content
896
+        undelete Bad_Fruit_Salad ( content_id: 14, parent_id: 10)
829
         """
897
         """
830
         self.testapp.authorization = (
898
         self.testapp.authorization = (
831
             'Basic',
899
             'Basic',
834
                 'foobarbaz'
902
                 'foobarbaz'
835
             )
903
             )
836
         )
904
         )
837
-        # TODO - G.M - 2018-06-163 - Check content
905
+        params_active = {
906
+            'parent_id': 10,
907
+            'show_archived': 0,
908
+            'show_deleted': 0,
909
+            'show_active': 1,
910
+        }
911
+        params_deleted = {
912
+            'parent_id': 10,
913
+            'show_archived': 0,
914
+            'show_deleted': 1,
915
+            'show_active': 0,
916
+        }
917
+        active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
918
+        deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
919
+        assert not [content for content in active_contents if content['id'] == 14]  # nopep8
920
+        assert [content for content in deleted_contents if content['id'] == 14]  # nopep8
838
         res = self.testapp.put_json(
921
         res = self.testapp.put_json(
839
-            # INFO - G.M - 2018-06-163 - delete Apple_Pie
840
             '/api/v2/workspaces/2/contents/14/undelete',
922
             '/api/v2/workspaces/2/contents/14/undelete',
841
             status=200
923
             status=200
842
         )
924
         )
843
-        # TODO - G.M - 2018-06-163 - Recheck content
925
+        new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
926
+        new_deleted_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_deleted, status=200).json_body  # nopep8
927
+        assert [content for content in new_active_contents if content['id'] == 14]  # nopep8
928
+        assert not [content for content in new_deleted_contents if content['id'] == 14]  # nopep8
844
 
929
 
845
     def test_api_put_unarchive_content__ok_200__nominal_case(self):
930
     def test_api_put_unarchive_content__ok_200__nominal_case(self):
846
         """
931
         """
847
-        Delete content
932
+        unarchive content,
933
+        unarchive Fruit_salads ( content_id: 13, parent_id: 10)
848
         """
934
         """
849
         self.testapp.authorization = (
935
         self.testapp.authorization = (
850
             'Basic',
936
             'Basic',
853
                 'foobarbaz'
939
                 'foobarbaz'
854
             )
940
             )
855
         )
941
         )
856
-        # TODO - G.M - 2018-06-163 - Check content
942
+        params_active = {
943
+            'parent_id': 10,
944
+            'show_archived': 0,
945
+            'show_deleted': 0,
946
+            'show_active': 1,
947
+        }
948
+        params_archived = {
949
+            'parent_id': 10,
950
+            'show_archived': 1,
951
+            'show_deleted': 0,
952
+            'show_active': 0,
953
+        }
954
+        active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
955
+        archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
956
+        assert not [content for content in active_contents if content['id'] == 13]  # nopep8
957
+        assert [content for content in archived_contents if content['id'] == 13]  # nopep8
857
         res = self.testapp.put_json(
958
         res = self.testapp.put_json(
858
-            # INFO - G.M - 2018-06-163 - delete Apple_Pie
859
             '/api/v2/workspaces/2/contents/13/unarchive',
959
             '/api/v2/workspaces/2/contents/13/unarchive',
860
             status=200
960
             status=200
861
         )
961
         )
862
-        # TODO - G.M - 2018-06-163 - Recheck content
962
+        new_active_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_active, status=200).json_body  # nopep8
963
+        new_archived_contents = self.testapp.get('/api/v2/workspaces/2/contents', params=params_archived, status=200).json_body  # nopep8
964
+        assert [content for content in new_active_contents if content['id'] == 13]  # nopep8
965
+        assert not [content for content in new_archived_contents if content['id'] == 13]  # nopep8