|
16 | 16 | from zope.component import getUtility |
17 | 17 | from zope.intid.interfaces import IIntIds |
18 | 18 | from zope.lifecycleevent import modified |
| 19 | +from DateTime import DateTime |
19 | 20 |
|
20 | 21 | import json |
21 | 22 | import os |
@@ -865,3 +866,176 @@ def test_export_blob_as_download_urls(self): |
865 | 866 | info["file"]["download"], "http://nohost/plone/file1/@@download/file" |
866 | 867 | ) |
867 | 868 | self.assertEqual(info["file"]["size"], 8561) |
| 869 | + |
| 870 | + def test_export_modified_items(self): |
| 871 | + """test that we can export items modified after a given datetime""" |
| 872 | + app = self.layer["app"] |
| 873 | + portal = self.layer["portal"] |
| 874 | + login(app, SITE_OWNER_NAME) |
| 875 | + folder1 = api.content.create( |
| 876 | + container=portal, type="Folder", id="folder1", title="Folder 1" |
| 877 | + ) |
| 878 | + folder1.modification_date = DateTime("2000-01-01", fmt="international") |
| 879 | + doc1 = api.content.create( |
| 880 | + container=portal, type="Document", id="doc1", title="Document 1" |
| 881 | + ) |
| 882 | + doc1.modification_date = DateTime("2000-01-02", fmt="international") |
| 883 | + doc2 = api.content.create( |
| 884 | + container=portal, type="Document", id="doc2", title="Document 2" |
| 885 | + ) |
| 886 | + doc2.modification_date = DateTime("2000-01-03", fmt="international") |
| 887 | + |
| 888 | + doc3 = api.content.create( |
| 889 | + container=portal, type="Document", id="doc3", title="Document 3" |
| 890 | + ) |
| 891 | + doc3.modification_date = DateTime("2000-01-04", fmt="international") |
| 892 | + |
| 893 | + transaction.commit() |
| 894 | + |
| 895 | + # Now export complete portal. |
| 896 | + browser = self.open_page("@@export_content") |
| 897 | + portal_type = browser.getControl(name="portal_type") |
| 898 | + self.assertEqual(portal_type.value, []) |
| 899 | + portal_type.value = ["Folder", "Document"] |
| 900 | + |
| 901 | + path = browser.getControl(label="Path") |
| 902 | + self.assertEqual(path.value, "/plone") |
| 903 | + |
| 904 | + modification_date = browser.getControl(label="Modification date") |
| 905 | + modification_date.value = "2000-01-03" |
| 906 | + |
| 907 | + depth = browser.getControl(name="depth") |
| 908 | + self.assertEqual(depth.value, ["-1"]) |
| 909 | + |
| 910 | + try: |
| 911 | + # Plone 5.2 |
| 912 | + browser.getControl("Export").click() |
| 913 | + contents = browser.contents |
| 914 | + except LookupError: |
| 915 | + # Plone 5.1 and lower |
| 916 | + browser.getForm(index=1).submit() |
| 917 | + if not browser.contents: |
| 918 | + contents = DATA[-1] |
| 919 | + |
| 920 | + # We should have gotten json. |
| 921 | + data = json.loads(contents) |
| 922 | + self.assertEqual(len(data), 2) |
| 923 | + |
| 924 | + # Check a few important keys. |
| 925 | + info = data[0] |
| 926 | + self.assertEqual(info["@id"], portal.absolute_url() + "/doc2") |
| 927 | + self.assertEqual(info["@type"], "Document") |
| 928 | + self.assertEqual(info["title"], doc2.Title()) |
| 929 | + |
| 930 | + info = data[1] |
| 931 | + self.assertEqual(info["@id"], portal.absolute_url() + "/doc3") |
| 932 | + self.assertEqual(info["@type"], "Document") |
| 933 | + self.assertEqual(info["title"], doc3.Title()) |
| 934 | + |
| 935 | + def test_wrong_modified_format(self): |
| 936 | + """test that if we enter an invalid datetime we get all the items""" |
| 937 | + app = self.layer["app"] |
| 938 | + portal = self.layer["portal"] |
| 939 | + login(app, SITE_OWNER_NAME) |
| 940 | + folder1 = api.content.create( |
| 941 | + container=portal, type="Folder", id="folder1", title="Folder 1" |
| 942 | + ) |
| 943 | + folder1.modification_date = DateTime("2000-01-01", fmt="international") |
| 944 | + doc1 = api.content.create( |
| 945 | + container=portal, type="Document", id="doc1", title="Document 1" |
| 946 | + ) |
| 947 | + doc1.modification_date = DateTime("2000-01-02", fmt="international") |
| 948 | + doc2 = api.content.create( |
| 949 | + container=portal, type="Document", id="doc2", title="Document 2" |
| 950 | + ) |
| 951 | + doc2.modification_date = DateTime("2000-01-03", fmt="international") |
| 952 | + |
| 953 | + doc3 = api.content.create( |
| 954 | + container=portal, type="Document", id="doc3", title="Document 3" |
| 955 | + ) |
| 956 | + doc3.modification_date = DateTime("2000-01-04", fmt="international") |
| 957 | + |
| 958 | + transaction.commit() |
| 959 | + |
| 960 | + # Now export complete portal. |
| 961 | + browser = self.open_page("@@export_content") |
| 962 | + portal_type = browser.getControl(name="portal_type") |
| 963 | + self.assertEqual(portal_type.value, []) |
| 964 | + portal_type.value = ["Folder", "Document"] |
| 965 | + |
| 966 | + path = browser.getControl(label="Path") |
| 967 | + self.assertEqual(path.value, "/plone") |
| 968 | + |
| 969 | + modification_date = browser.getControl(label="Modification date") |
| 970 | + modification_date.value = "2000-25-01" |
| 971 | + |
| 972 | + depth = browser.getControl(name="depth") |
| 973 | + self.assertEqual(depth.value, ["-1"]) |
| 974 | + |
| 975 | + try: |
| 976 | + # Plone 5.2 |
| 977 | + browser.getControl("Export").click() |
| 978 | + contents = browser.contents |
| 979 | + except LookupError: |
| 980 | + # Plone 5.1 and lower |
| 981 | + browser.getForm(index=1).submit() |
| 982 | + if not browser.contents: |
| 983 | + contents = DATA[-1] |
| 984 | + |
| 985 | + # We should have gotten json. |
| 986 | + data = json.loads(contents) |
| 987 | + self.assertEqual(len(data), 4) |
| 988 | + |
| 989 | + def test_non_datetime_modified_format(self): |
| 990 | + """test that if we enter a non-datetime value in modified field we get all the items""" |
| 991 | + app = self.layer["app"] |
| 992 | + portal = self.layer["portal"] |
| 993 | + login(app, SITE_OWNER_NAME) |
| 994 | + folder1 = api.content.create( |
| 995 | + container=portal, type="Folder", id="folder1", title="Folder 1" |
| 996 | + ) |
| 997 | + folder1.modification_date = DateTime("2000-01-01", fmt="international") |
| 998 | + doc1 = api.content.create( |
| 999 | + container=portal, type="Document", id="doc1", title="Document 1" |
| 1000 | + ) |
| 1001 | + doc1.modification_date = DateTime("2000-01-02", fmt="international") |
| 1002 | + doc2 = api.content.create( |
| 1003 | + container=portal, type="Document", id="doc2", title="Document 2" |
| 1004 | + ) |
| 1005 | + doc2.modification_date = DateTime("2000-01-03", fmt="international") |
| 1006 | + |
| 1007 | + doc3 = api.content.create( |
| 1008 | + container=portal, type="Document", id="doc3", title="Document 3" |
| 1009 | + ) |
| 1010 | + doc3.modification_date = DateTime("2000-01-04", fmt="international") |
| 1011 | + |
| 1012 | + transaction.commit() |
| 1013 | + |
| 1014 | + # Now export complete portal. |
| 1015 | + browser = self.open_page("@@export_content") |
| 1016 | + portal_type = browser.getControl(name="portal_type") |
| 1017 | + self.assertEqual(portal_type.value, []) |
| 1018 | + portal_type.value = ["Folder", "Document"] |
| 1019 | + |
| 1020 | + path = browser.getControl(label="Path") |
| 1021 | + self.assertEqual(path.value, "/plone") |
| 1022 | + |
| 1023 | + modification_date = browser.getControl(label="Modification date") |
| 1024 | + modification_date.value = "Plone" |
| 1025 | + |
| 1026 | + depth = browser.getControl(name="depth") |
| 1027 | + self.assertEqual(depth.value, ["-1"]) |
| 1028 | + |
| 1029 | + try: |
| 1030 | + # Plone 5.2 |
| 1031 | + browser.getControl("Export").click() |
| 1032 | + contents = browser.contents |
| 1033 | + except LookupError: |
| 1034 | + # Plone 5.1 and lower |
| 1035 | + browser.getForm(index=1).submit() |
| 1036 | + if not browser.contents: |
| 1037 | + contents = DATA[-1] |
| 1038 | + |
| 1039 | + # We should have gotten json. |
| 1040 | + data = json.loads(contents) |
| 1041 | + self.assertEqual(len(data), 4) |
0 commit comments