|
@@ -1,5 +1,5 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
|
-
|
|
2
|
+import datetime
|
3
|
3
|
import transaction
|
4
|
4
|
import pytest
|
5
|
5
|
|
|
@@ -1977,6 +1977,285 @@ class TestContentApi(DefaultTest):
|
1977
|
1977
|
eq_(ActionDescription.UNDELETION, updated2.revision_type)
|
1978
|
1978
|
eq_(u1id, updated2.owner_id)
|
1979
|
1979
|
|
|
1980
|
+ def test_unit__get_last_active__ok__nominal_case(self):
|
|
1981
|
+ uapi = UserApi(
|
|
1982
|
+ session=self.session,
|
|
1983
|
+ config=self.app_config,
|
|
1984
|
+ current_user=None,
|
|
1985
|
+ )
|
|
1986
|
+ group_api = GroupApi(
|
|
1987
|
+ current_user=None,
|
|
1988
|
+ session=self.session,
|
|
1989
|
+ config=self.app_config,
|
|
1990
|
+ )
|
|
1991
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
1992
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
1993
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
1994
|
+
|
|
1995
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
1996
|
+ groups=groups, save_now=True)
|
|
1997
|
+ workspace = WorkspaceApi(
|
|
1998
|
+ current_user=user,
|
|
1999
|
+ session=self.session,
|
|
2000
|
+ config=self.app_config,
|
|
2001
|
+ ).create_workspace(
|
|
2002
|
+ 'test workspace',
|
|
2003
|
+ save_now=True
|
|
2004
|
+ )
|
|
2005
|
+ workspace2 = WorkspaceApi(
|
|
2006
|
+ current_user=user,
|
|
2007
|
+ session=self.session,
|
|
2008
|
+ config=self.app_config,
|
|
2009
|
+ ).create_workspace(
|
|
2010
|
+ 'test workspace2',
|
|
2011
|
+ save_now=True
|
|
2012
|
+ )
|
|
2013
|
+
|
|
2014
|
+ api = ContentApi(
|
|
2015
|
+ current_user=user,
|
|
2016
|
+ session=self.session,
|
|
2017
|
+ config=self.app_config,
|
|
2018
|
+ )
|
|
2019
|
+ main_folder_workspace2 = api.create(ContentType.Folder, workspace2, None, 'Hepla', '', True) # nopep8
|
|
2020
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
|
|
2021
|
+ # creation order test
|
|
2022
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
|
|
2023
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
|
|
2024
|
+ # update order test
|
|
2025
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
|
|
2026
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
|
|
2027
|
+ with new_revision(
|
|
2028
|
+ session=self.session,
|
|
2029
|
+ tm=transaction.manager,
|
|
2030
|
+ content=firstly_created_but_recently_updated,
|
|
2031
|
+ ):
|
|
2032
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
2033
|
+ api.save(firstly_created_but_recently_updated)
|
|
2034
|
+ # comment change order
|
|
2035
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
|
|
2036
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
|
|
2037
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
|
|
2038
|
+
|
|
2039
|
+ content_workspace_2 = api.create(ContentType.Page, workspace,main_folder_workspace2, 'content_workspace_2', '',True) # nopep8
|
|
2040
|
+ last_actives = api.get_last_active()
|
|
2041
|
+ assert len(last_actives) == 9
|
|
2042
|
+ # workspace_2 content
|
|
2043
|
+ assert last_actives[0] == content_workspace_2
|
|
2044
|
+ # comment is newest than page2
|
|
2045
|
+ assert last_actives[1] == firstly_created_but_recently_commented
|
|
2046
|
+ assert last_actives[2] == secondly_created_but_not_commented
|
|
2047
|
+ # last updated content is newer than other one despite creation
|
|
2048
|
+ # of the other is more recent
|
|
2049
|
+ assert last_actives[3] == firstly_created_but_recently_updated
|
|
2050
|
+ assert last_actives[4] == secondly_created_but_not_updated
|
|
2051
|
+ # creation order is inverted here as last created is last active
|
|
2052
|
+ assert last_actives[5] == secondly_created
|
|
2053
|
+ assert last_actives[6] == firstly_created
|
|
2054
|
+ # folder subcontent modification does not change folder order
|
|
2055
|
+ assert last_actives[7] == main_folder
|
|
2056
|
+ # folder subcontent modification does not change folder order
|
|
2057
|
+ # (workspace2)
|
|
2058
|
+ assert last_actives[8] == main_folder_workspace2
|
|
2059
|
+
|
|
2060
|
+ def test_unit__get_last_active__ok__workspace_filter_workspace_full(self):
|
|
2061
|
+ uapi = UserApi(
|
|
2062
|
+ session=self.session,
|
|
2063
|
+ config=self.app_config,
|
|
2064
|
+ current_user=None,
|
|
2065
|
+ )
|
|
2066
|
+ group_api = GroupApi(
|
|
2067
|
+ current_user=None,
|
|
2068
|
+ session=self.session,
|
|
2069
|
+ config=self.app_config,
|
|
2070
|
+ )
|
|
2071
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
2072
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
2073
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
2074
|
+
|
|
2075
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
2076
|
+ groups=groups, save_now=True)
|
|
2077
|
+ workspace = WorkspaceApi(
|
|
2078
|
+ current_user=user,
|
|
2079
|
+ session=self.session,
|
|
2080
|
+ config=self.app_config,
|
|
2081
|
+ ).create_workspace(
|
|
2082
|
+ 'test workspace',
|
|
2083
|
+ save_now=True
|
|
2084
|
+ )
|
|
2085
|
+
|
|
2086
|
+ api = ContentApi(
|
|
2087
|
+ current_user=user,
|
|
2088
|
+ session=self.session,
|
|
2089
|
+ config=self.app_config,
|
|
2090
|
+ )
|
|
2091
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
|
|
2092
|
+ # creation order test
|
|
2093
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
|
|
2094
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
|
|
2095
|
+ # update order test
|
|
2096
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
|
|
2097
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
|
|
2098
|
+ with new_revision(
|
|
2099
|
+ session=self.session,
|
|
2100
|
+ tm=transaction.manager,
|
|
2101
|
+ content=firstly_created_but_recently_updated,
|
|
2102
|
+ ):
|
|
2103
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
2104
|
+ api.save(firstly_created_but_recently_updated)
|
|
2105
|
+ # comment change order
|
|
2106
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
|
|
2107
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
|
|
2108
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
|
|
2109
|
+
|
|
2110
|
+ last_actives = api.get_last_active(workspace=workspace)
|
|
2111
|
+ assert len(last_actives) == 7
|
|
2112
|
+ # comment is newest than page2
|
|
2113
|
+ assert last_actives[0] == firstly_created_but_recently_commented
|
|
2114
|
+ assert last_actives[1] == secondly_created_but_not_commented
|
|
2115
|
+ # last updated content is newer than other one despite creation
|
|
2116
|
+ # of the other is more recent
|
|
2117
|
+ assert last_actives[2] == firstly_created_but_recently_updated
|
|
2118
|
+ assert last_actives[3] == secondly_created_but_not_updated
|
|
2119
|
+ # creation order is inverted here as last created is last active
|
|
2120
|
+ assert last_actives[4] == secondly_created
|
|
2121
|
+ assert last_actives[5] == firstly_created
|
|
2122
|
+ # folder subcontent modification does not change folder order
|
|
2123
|
+ assert last_actives[6] == main_folder
|
|
2124
|
+
|
|
2125
|
+ def test_unit__get_last_active__ok__workspace_filter_workspace_limit_2_multiples_times(self): # nopep8
|
|
2126
|
+ uapi = UserApi(
|
|
2127
|
+ session=self.session,
|
|
2128
|
+ config=self.app_config,
|
|
2129
|
+ current_user=None,
|
|
2130
|
+ )
|
|
2131
|
+ group_api = GroupApi(
|
|
2132
|
+ current_user=None,
|
|
2133
|
+ session=self.session,
|
|
2134
|
+ config=self.app_config,
|
|
2135
|
+ )
|
|
2136
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
2137
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
2138
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
2139
|
+
|
|
2140
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
2141
|
+ groups=groups, save_now=True)
|
|
2142
|
+ workspace = WorkspaceApi(
|
|
2143
|
+ current_user=user,
|
|
2144
|
+ session=self.session,
|
|
2145
|
+ config=self.app_config,
|
|
2146
|
+ ).create_workspace(
|
|
2147
|
+ 'test workspace',
|
|
2148
|
+ save_now=True
|
|
2149
|
+ )
|
|
2150
|
+
|
|
2151
|
+ api = ContentApi(
|
|
2152
|
+ current_user=user,
|
|
2153
|
+ session=self.session,
|
|
2154
|
+ config=self.app_config,
|
|
2155
|
+ )
|
|
2156
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
|
|
2157
|
+ # creation order test
|
|
2158
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
|
|
2159
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
|
|
2160
|
+ # update order test
|
|
2161
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
|
|
2162
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
|
|
2163
|
+ with new_revision(
|
|
2164
|
+ session=self.session,
|
|
2165
|
+ tm=transaction.manager,
|
|
2166
|
+ content=firstly_created_but_recently_updated,
|
|
2167
|
+ ):
|
|
2168
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
2169
|
+ api.save(firstly_created_but_recently_updated)
|
|
2170
|
+ # comment change order
|
|
2171
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
|
|
2172
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
|
|
2173
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
|
|
2174
|
+
|
|
2175
|
+ last_actives = api.get_last_active(workspace=workspace, limit=2, before_datetime=datetime.datetime.now()) # nopep8
|
|
2176
|
+ assert len(last_actives) == 2
|
|
2177
|
+ # comment is newest than page2
|
|
2178
|
+ assert last_actives[0] == firstly_created_but_recently_commented
|
|
2179
|
+ assert last_actives[1] == secondly_created_but_not_commented
|
|
2180
|
+
|
|
2181
|
+ last_actives = api.get_last_active(workspace=workspace, limit=2, before_datetime=last_actives[1].get_simple_last_activity_date()) # nopep8
|
|
2182
|
+ assert len(last_actives) == 2
|
|
2183
|
+ # last updated content is newer than other one despite creation
|
|
2184
|
+ # of the other is more recent
|
|
2185
|
+ assert last_actives[0] == firstly_created_but_recently_updated
|
|
2186
|
+ assert last_actives[1] == secondly_created_but_not_updated
|
|
2187
|
+
|
|
2188
|
+ last_actives = api.get_last_active(workspace=workspace, limit=2, before_datetime=last_actives[1].get_simple_last_activity_date()) # nopep8
|
|
2189
|
+ assert len(last_actives) == 2
|
|
2190
|
+ # creation order is inverted here as last created is last active
|
|
2191
|
+ assert last_actives[0] == secondly_created
|
|
2192
|
+ assert last_actives[1] == firstly_created
|
|
2193
|
+
|
|
2194
|
+ last_actives = api.get_last_active(workspace=workspace, limit=2, before_datetime=last_actives[1].get_simple_last_activity_date()) # nopep8
|
|
2195
|
+ assert len(last_actives) == 1
|
|
2196
|
+ # folder subcontent modification does not change folder order
|
|
2197
|
+ assert last_actives[0] == main_folder
|
|
2198
|
+
|
|
2199
|
+ def test_unit__get_last_active__ok__workspace_filter_workspace_empty(self):
|
|
2200
|
+ uapi = UserApi(
|
|
2201
|
+ session=self.session,
|
|
2202
|
+ config=self.app_config,
|
|
2203
|
+ current_user=None,
|
|
2204
|
+ )
|
|
2205
|
+ group_api = GroupApi(
|
|
2206
|
+ current_user=None,
|
|
2207
|
+ session=self.session,
|
|
2208
|
+ config=self.app_config,
|
|
2209
|
+ )
|
|
2210
|
+ groups = [group_api.get_one(Group.TIM_USER),
|
|
2211
|
+ group_api.get_one(Group.TIM_MANAGER),
|
|
2212
|
+ group_api.get_one(Group.TIM_ADMIN)]
|
|
2213
|
+
|
|
2214
|
+ user = uapi.create_minimal_user(email='this.is@user',
|
|
2215
|
+ groups=groups, save_now=True)
|
|
2216
|
+ workspace = WorkspaceApi(
|
|
2217
|
+ current_user=user,
|
|
2218
|
+ session=self.session,
|
|
2219
|
+ config=self.app_config,
|
|
2220
|
+ ).create_workspace(
|
|
2221
|
+ 'test workspace',
|
|
2222
|
+ save_now=True
|
|
2223
|
+ )
|
|
2224
|
+ workspace2 = WorkspaceApi(
|
|
2225
|
+ current_user=user,
|
|
2226
|
+ session=self.session,
|
|
2227
|
+ config=self.app_config,
|
|
2228
|
+ ).create_workspace(
|
|
2229
|
+ 'test workspace2',
|
|
2230
|
+ save_now=True
|
|
2231
|
+ )
|
|
2232
|
+ api = ContentApi(
|
|
2233
|
+ current_user=user,
|
|
2234
|
+ session=self.session,
|
|
2235
|
+ config=self.app_config,
|
|
2236
|
+ )
|
|
2237
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
|
|
2238
|
+ # creation order test
|
|
2239
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
|
|
2240
|
+ secondly_created = api.create(ContentType.Page, workspace, main_folder, 'another creation_order_test', '', True) # nopep8
|
|
2241
|
+ # update order test
|
|
2242
|
+ firstly_created_but_recently_updated = api.create(ContentType.Page, workspace, main_folder, 'update_order_test', '', True) # nopep8
|
|
2243
|
+ secondly_created_but_not_updated = api.create(ContentType.Page, workspace, main_folder, 'another update_order_test', '', True) # nopep8
|
|
2244
|
+ with new_revision(
|
|
2245
|
+ session=self.session,
|
|
2246
|
+ tm=transaction.manager,
|
|
2247
|
+ content=firstly_created_but_recently_updated,
|
|
2248
|
+ ):
|
|
2249
|
+ firstly_created_but_recently_updated.description = 'Just an update'
|
|
2250
|
+ api.save(firstly_created_but_recently_updated)
|
|
2251
|
+ # comment change order
|
|
2252
|
+ firstly_created_but_recently_commented = api.create(ContentType.Page, workspace, main_folder, 'this is randomized label content', '', True) # nopep8
|
|
2253
|
+ secondly_created_but_not_commented = api.create(ContentType.Page, workspace, main_folder, 'this is another randomized label content', '', True) # nopep8
|
|
2254
|
+ comments = api.create_comment(workspace, firstly_created_but_recently_commented, 'juste a super comment', True) # nopep8
|
|
2255
|
+
|
|
2256
|
+ last_actives = api.get_last_active(workspace=workspace2)
|
|
2257
|
+ assert len(last_actives) == 0
|
|
2258
|
+
|
1980
|
2259
|
def test_search_in_label(self):
|
1981
|
2260
|
# HACK - D.A. - 2015-03-09
|
1982
|
2261
|
# This test is based on a bug which does NOT return results found
|