|
@@ 2203-2299 (lines=97) @@
|
| 2200 |
|
assert res.json_body[1]['content_id'] == main_folder.content_id |
| 2201 |
|
assert res.json_body[1]['read_by_user'] is True |
| 2202 |
|
|
| 2203 |
|
def test_api_set_content_as_read__ok__200__user_itself(self): |
| 2204 |
|
# init DB |
| 2205 |
|
dbsession = get_tm_session(self.session_factory, transaction.manager) |
| 2206 |
|
admin = dbsession.query(models.User) \ |
| 2207 |
|
.filter(models.User.email == '[email protected]') \ |
| 2208 |
|
.one() |
| 2209 |
|
workspace_api = WorkspaceApi( |
| 2210 |
|
current_user=admin, |
| 2211 |
|
session=dbsession, |
| 2212 |
|
config=self.app_config |
| 2213 |
|
|
| 2214 |
|
) |
| 2215 |
|
workspace = WorkspaceApi( |
| 2216 |
|
current_user=admin, |
| 2217 |
|
session=dbsession, |
| 2218 |
|
config=self.app_config, |
| 2219 |
|
).create_workspace( |
| 2220 |
|
'test workspace', |
| 2221 |
|
save_now=True |
| 2222 |
|
) |
| 2223 |
|
uapi = UserApi( |
| 2224 |
|
current_user=admin, |
| 2225 |
|
session=dbsession, |
| 2226 |
|
config=self.app_config, |
| 2227 |
|
) |
| 2228 |
|
gapi = GroupApi( |
| 2229 |
|
current_user=admin, |
| 2230 |
|
session=dbsession, |
| 2231 |
|
config=self.app_config, |
| 2232 |
|
) |
| 2233 |
|
groups = [gapi.get_one_with_name('users')] |
| 2234 |
|
test_user = uapi.create_user( |
| 2235 |
|
email='[email protected]', |
| 2236 |
|
password='pass', |
| 2237 |
|
name='bob', |
| 2238 |
|
groups=groups, |
| 2239 |
|
timezone='Europe/Paris', |
| 2240 |
|
lang='fr', |
| 2241 |
|
do_save=True, |
| 2242 |
|
do_notify=False, |
| 2243 |
|
) |
| 2244 |
|
rapi = RoleApi( |
| 2245 |
|
current_user=admin, |
| 2246 |
|
session=dbsession, |
| 2247 |
|
config=self.app_config, |
| 2248 |
|
) |
| 2249 |
|
rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
| 2250 |
|
api = ContentApi( |
| 2251 |
|
current_user=admin, |
| 2252 |
|
session=dbsession, |
| 2253 |
|
config=self.app_config, |
| 2254 |
|
) |
| 2255 |
|
api2 = ContentApi( |
| 2256 |
|
current_user=test_user, |
| 2257 |
|
session=dbsession, |
| 2258 |
|
config=self.app_config, |
| 2259 |
|
) |
| 2260 |
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
| 2261 |
|
# creation order test |
| 2262 |
|
firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
| 2263 |
|
api.mark_unread(main_folder) |
| 2264 |
|
api.mark_unread(firstly_created) |
| 2265 |
|
api2.mark_unread(main_folder) |
| 2266 |
|
api2.mark_unread(firstly_created) |
| 2267 |
|
dbsession.flush() |
| 2268 |
|
transaction.commit() |
| 2269 |
|
|
| 2270 |
|
self.testapp.authorization = ( |
| 2271 |
|
'Basic', |
| 2272 |
|
( |
| 2273 |
|
'[email protected]', |
| 2274 |
|
'pass' |
| 2275 |
|
) |
| 2276 |
|
) |
| 2277 |
|
res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
| 2278 |
|
user_id=test_user.user_id, |
| 2279 |
|
workspace_id=workspace.workspace_id |
| 2280 |
|
), status=200) |
| 2281 |
|
assert res.json_body[0]['content_id'] == firstly_created.content_id |
| 2282 |
|
assert res.json_body[0]['read_by_user'] is False |
| 2283 |
|
assert res.json_body[1]['content_id'] == main_folder.content_id |
| 2284 |
|
assert res.json_body[1]['read_by_user'] is False |
| 2285 |
|
self.testapp.put( |
| 2286 |
|
'/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8 |
| 2287 |
|
workspace_id=workspace.workspace_id, |
| 2288 |
|
content_id=firstly_created.content_id, |
| 2289 |
|
user_id=test_user.user_id, |
| 2290 |
|
) |
| 2291 |
|
) |
| 2292 |
|
res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
| 2293 |
|
user_id=test_user.user_id, |
| 2294 |
|
workspace_id=workspace.workspace_id |
| 2295 |
|
), status=200) |
| 2296 |
|
assert res.json_body[0]['content_id'] == firstly_created.content_id |
| 2297 |
|
assert res.json_body[0]['read_by_user'] is True |
| 2298 |
|
assert res.json_body[1]['content_id'] == main_folder.content_id |
| 2299 |
|
assert res.json_body[1]['read_by_user'] is True |
| 2300 |
|
|
| 2301 |
|
def test_api_set_content_as_read__err__403__other_user(self): |
| 2302 |
|
# init DB |
|
@@ 2105-2201 (lines=97) @@
|
| 2102 |
|
""" |
| 2103 |
|
Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/read |
| 2104 |
|
""" |
| 2105 |
|
def test_api_set_content_as_read__ok__200__admin(self): |
| 2106 |
|
# init DB |
| 2107 |
|
dbsession = get_tm_session(self.session_factory, transaction.manager) |
| 2108 |
|
admin = dbsession.query(models.User) \ |
| 2109 |
|
.filter(models.User.email == '[email protected]') \ |
| 2110 |
|
.one() |
| 2111 |
|
workspace_api = WorkspaceApi( |
| 2112 |
|
current_user=admin, |
| 2113 |
|
session=dbsession, |
| 2114 |
|
config=self.app_config |
| 2115 |
|
|
| 2116 |
|
) |
| 2117 |
|
workspace = WorkspaceApi( |
| 2118 |
|
current_user=admin, |
| 2119 |
|
session=dbsession, |
| 2120 |
|
config=self.app_config, |
| 2121 |
|
).create_workspace( |
| 2122 |
|
'test workspace', |
| 2123 |
|
save_now=True |
| 2124 |
|
) |
| 2125 |
|
uapi = UserApi( |
| 2126 |
|
current_user=admin, |
| 2127 |
|
session=dbsession, |
| 2128 |
|
config=self.app_config, |
| 2129 |
|
) |
| 2130 |
|
gapi = GroupApi( |
| 2131 |
|
current_user=admin, |
| 2132 |
|
session=dbsession, |
| 2133 |
|
config=self.app_config, |
| 2134 |
|
) |
| 2135 |
|
groups = [gapi.get_one_with_name('users')] |
| 2136 |
|
test_user = uapi.create_user( |
| 2137 |
|
email='[email protected]', |
| 2138 |
|
password='pass', |
| 2139 |
|
name='bob', |
| 2140 |
|
groups=groups, |
| 2141 |
|
timezone='Europe/Paris', |
| 2142 |
|
lang='fr', |
| 2143 |
|
do_save=True, |
| 2144 |
|
do_notify=False, |
| 2145 |
|
) |
| 2146 |
|
rapi = RoleApi( |
| 2147 |
|
current_user=admin, |
| 2148 |
|
session=dbsession, |
| 2149 |
|
config=self.app_config, |
| 2150 |
|
) |
| 2151 |
|
rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
| 2152 |
|
api = ContentApi( |
| 2153 |
|
current_user=admin, |
| 2154 |
|
session=dbsession, |
| 2155 |
|
config=self.app_config, |
| 2156 |
|
) |
| 2157 |
|
api2 = ContentApi( |
| 2158 |
|
current_user=test_user, |
| 2159 |
|
session=dbsession, |
| 2160 |
|
config=self.app_config, |
| 2161 |
|
) |
| 2162 |
|
main_folder = api.create(CONTENT_TYPES.Folder.slug, workspace, None, 'this is randomized folder', '', True) # nopep8 |
| 2163 |
|
# creation order test |
| 2164 |
|
firstly_created = api.create(CONTENT_TYPES.Page.slug, workspace, main_folder, 'creation_order_test', '', True) # nopep8 |
| 2165 |
|
api.mark_unread(main_folder) |
| 2166 |
|
api.mark_unread(firstly_created) |
| 2167 |
|
api2.mark_unread(main_folder) |
| 2168 |
|
api2.mark_unread(firstly_created) |
| 2169 |
|
dbsession.flush() |
| 2170 |
|
transaction.commit() |
| 2171 |
|
|
| 2172 |
|
self.testapp.authorization = ( |
| 2173 |
|
'Basic', |
| 2174 |
|
( |
| 2175 |
|
'[email protected]', |
| 2176 |
|
'[email protected]' |
| 2177 |
|
) |
| 2178 |
|
) |
| 2179 |
|
res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
| 2180 |
|
user_id=test_user.user_id, |
| 2181 |
|
workspace_id=workspace.workspace_id |
| 2182 |
|
), status=200) |
| 2183 |
|
assert res.json_body[0]['content_id'] == firstly_created.content_id |
| 2184 |
|
assert res.json_body[0]['read_by_user'] is False |
| 2185 |
|
assert res.json_body[1]['content_id'] == main_folder.content_id |
| 2186 |
|
assert res.json_body[1]['read_by_user'] is False |
| 2187 |
|
self.testapp.put( |
| 2188 |
|
'/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8 |
| 2189 |
|
workspace_id=workspace.workspace_id, |
| 2190 |
|
content_id=firstly_created.content_id, |
| 2191 |
|
user_id=test_user.user_id, |
| 2192 |
|
) |
| 2193 |
|
) |
| 2194 |
|
res = self.testapp.get('/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/read_status'.format( # nopep8 |
| 2195 |
|
user_id=test_user.user_id, |
| 2196 |
|
workspace_id=workspace.workspace_id |
| 2197 |
|
), status=200) |
| 2198 |
|
assert res.json_body[0]['content_id'] == firstly_created.content_id |
| 2199 |
|
assert res.json_body[0]['read_by_user'] is True |
| 2200 |
|
assert res.json_body[1]['content_id'] == main_folder.content_id |
| 2201 |
|
assert res.json_body[1]['read_by_user'] is True |
| 2202 |
|
|
| 2203 |
|
def test_api_set_content_as_read__ok__200__user_itself(self): |
| 2204 |
|
# init DB |