Browse Source

add content_api_test for SameValue case

Guénaël Muller 6 years ago
parent
commit
16e8b6deaa
1 changed files with 116 additions and 0 deletions
  1. 116 0
      tracim/tracim/tests/library/test_content_api.py

+ 116 - 0
tracim/tracim/tests/library/test_content_api.py View File

11
 from tracim.lib.content import ContentApi
11
 from tracim.lib.content import ContentApi
12
 from tracim.lib.group import GroupApi
12
 from tracim.lib.group import GroupApi
13
 from tracim.lib.user import UserApi
13
 from tracim.lib.user import UserApi
14
+from tracim.lib.utils import SameValueError
14
 from tracim.lib.workspace import RoleApi
15
 from tracim.lib.workspace import RoleApi
15
 from tracim.lib.workspace import WorkspaceApi
16
 from tracim.lib.workspace import WorkspaceApi
16
 from tracim.model import DBSession, new_revision, User
17
 from tracim.model import DBSession, new_revision, User
829
         eq_('new content', updated.description)
830
         eq_('new content', updated.description)
830
         eq_(ActionDescription.EDITION, updated.revision_type)
831
         eq_(ActionDescription.EDITION, updated.revision_type)
831
 
832
 
833
+    @raises(SameValueError)
834
+    def test_update_no_change(self):
835
+        uapi = UserApi(None)
836
+        groups = [
837
+            GroupApi(None).get_one(Group.TIM_USER),
838
+            GroupApi(None).get_one(Group.TIM_MANAGER),
839
+            GroupApi(None).get_one(Group.TIM_ADMIN)
840
+        ]
841
+
842
+        user1 = uapi.create_user(
843
+            email='this.is@user',
844
+            groups=groups,
845
+            save_now=True,
846
+        )
847
+
848
+        workspace = WorkspaceApi(user1).create_workspace(
849
+            'test workspace',
850
+            save_now=True
851
+        )
852
+
853
+        user2 = uapi.create_user()
854
+        user2.email = 'this.is@another.user'
855
+        uapi.save(user2)
856
+
857
+        RoleApi(user1).create_one(
858
+            user2,
859
+            workspace,
860
+            UserRoleInWorkspace.CONTENT_MANAGER,
861
+            with_notif=False,
862
+            flush=True
863
+        )
864
+        api = ContentApi(user1)
865
+        with DBSession.no_autoflush:
866
+            page = api.create(
867
+                content_type=ContentType.Page,
868
+                workspace=workspace,
869
+                label="same_content",
870
+                do_save=False
871
+            )
872
+            page.description = "Same_content_here"
873
+        api.save(page, ActionDescription.CREATION, do_notify=True)
874
+        transaction.commit()
875
+
876
+        api2 = ContentApi(user2)
877
+        content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
878
+        with new_revision(content2):
879
+            api2.update_content(
880
+                item=content2,
881
+                new_label='same_content',
882
+                new_content='Same_content_here'
883
+            )
884
+        api2.save(content2)
885
+        transaction.commit()
886
+
832
     def test_update_file_data(self):
887
     def test_update_file_data(self):
833
         uapi = UserApi(None)
888
         uapi = UserApi(None)
834
         groups = [GroupApi(None).get_one(Group.TIM_USER),
889
         groups = [GroupApi(None).get_one(Group.TIM_USER),
896
         eq_(b'<html>hello world</html>', updated.depot_file.file.read())
951
         eq_(b'<html>hello world</html>', updated.depot_file.file.read())
897
         eq_(ActionDescription.REVISION, updated.revision_type)
952
         eq_(ActionDescription.REVISION, updated.revision_type)
898
 
953
 
954
+    @raises(SameValueError)
955
+    def test_update_no_change(self):
956
+        uapi = UserApi(None)
957
+        groups = [
958
+            GroupApi(None).get_one(Group.TIM_USER),
959
+            GroupApi(None).get_one(Group.TIM_MANAGER),
960
+            GroupApi(None).get_one(Group.TIM_ADMIN)
961
+        ]
962
+
963
+        user1 = uapi.create_user(
964
+            email='this.is@user',
965
+            groups=groups,
966
+            save_now=True,
967
+        )
968
+
969
+        workspace = WorkspaceApi(user1).create_workspace(
970
+            'test workspace',
971
+            save_now=True
972
+        )
973
+
974
+        user2 = uapi.create_user()
975
+        user2.email = 'this.is@another.user'
976
+        uapi.save(user2)
977
+
978
+        RoleApi(user1).create_one(
979
+            user2,
980
+            workspace,
981
+            UserRoleInWorkspace.CONTENT_MANAGER,
982
+            with_notif=False,
983
+            flush=True
984
+        )
985
+        api = ContentApi(user1)
986
+        with DBSession.no_autoflush:
987
+            page = api.create(
988
+                content_type=ContentType.Page,
989
+                workspace=workspace,
990
+                label="same_content",
991
+                do_save=False
992
+            )
993
+            api.update_file_data(
994
+                page,
995
+                'index.html',
996
+                'text/html',
997
+                b'<html>Same Content Here</html>'
998
+            )
999
+        api.save(page, ActionDescription.CREATION, do_notify=True)
1000
+        transaction.commit()
1001
+
1002
+        api2 = ContentApi(user2)
1003
+        content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1004
+        with new_revision(content2):
1005
+            api2.update_file_data(
1006
+                page,
1007
+                'index.html',
1008
+                'text/html',
1009
+                b'<html>Same Content Here</html>'
1010
+            )
1011
+        api2.save(content2)
1012
+        transaction.commit()
1013
+
1014
+
899
     def test_archive_unarchive(self):
1015
     def test_archive_unarchive(self):
900
         uapi = UserApi(None)
1016
         uapi = UserApi(None)
901
         groups = [GroupApi(None).get_one(Group.TIM_USER),
1017
         groups = [GroupApi(None).get_one(Group.TIM_USER),