| @@ 1278-1380 (lines=103) @@ | ||
| 1275 | assert res[0]['public_name'] == test_user.display_name |
|
| 1276 | assert res[0]['avatar_url'] is None |
|
| 1277 | ||
| 1278 | def test_api__get_user__ok_200__admin__by_name_exclude_workspace_and_user(self): |
|
| 1279 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 1280 | admin = dbsession.query(models.User) \ |
|
| 1281 | .filter(models.User.email == '[email protected]') \ |
|
| 1282 | .one() |
|
| 1283 | uapi = UserApi( |
|
| 1284 | current_user=admin, |
|
| 1285 | session=dbsession, |
|
| 1286 | config=self.app_config, |
|
| 1287 | ) |
|
| 1288 | gapi = GroupApi( |
|
| 1289 | current_user=admin, |
|
| 1290 | session=dbsession, |
|
| 1291 | config=self.app_config, |
|
| 1292 | ) |
|
| 1293 | groups = [gapi.get_one_with_name('users')] |
|
| 1294 | test_user = uapi.create_user( |
|
| 1295 | email='[email protected]', |
|
| 1296 | password='pass', |
|
| 1297 | name='bob', |
|
| 1298 | groups=groups, |
|
| 1299 | timezone='Europe/Paris', |
|
| 1300 | lang='fr', |
|
| 1301 | do_save=True, |
|
| 1302 | do_notify=False, |
|
| 1303 | ) |
|
| 1304 | test_user2 = uapi.create_user( |
|
| 1305 | email='[email protected]', |
|
| 1306 | password='pass', |
|
| 1307 | name='bob2', |
|
| 1308 | groups=groups, |
|
| 1309 | timezone='Europe/Paris', |
|
| 1310 | lang='fr', |
|
| 1311 | do_save=True, |
|
| 1312 | do_notify=False, |
|
| 1313 | ) |
|
| 1314 | test_user3 = uapi.create_user( |
|
| 1315 | email='[email protected]', |
|
| 1316 | password='pass', |
|
| 1317 | name='bob3', |
|
| 1318 | groups=groups, |
|
| 1319 | timezone='Europe/Paris', |
|
| 1320 | lang='fr', |
|
| 1321 | do_save=True, |
|
| 1322 | do_notify=False, |
|
| 1323 | ) |
|
| 1324 | workspace_api = WorkspaceApi( |
|
| 1325 | current_user=admin, |
|
| 1326 | session=dbsession, |
|
| 1327 | config=self.app_config |
|
| 1328 | ||
| 1329 | ) |
|
| 1330 | workspace = WorkspaceApi( |
|
| 1331 | current_user=admin, |
|
| 1332 | session=dbsession, |
|
| 1333 | config=self.app_config, |
|
| 1334 | ).create_workspace( |
|
| 1335 | 'test workspace', |
|
| 1336 | save_now=True |
|
| 1337 | ) |
|
| 1338 | workspace2 = WorkspaceApi( |
|
| 1339 | current_user=admin, |
|
| 1340 | session=dbsession, |
|
| 1341 | config=self.app_config, |
|
| 1342 | ).create_workspace( |
|
| 1343 | 'test workspace2', |
|
| 1344 | save_now=True |
|
| 1345 | ) |
|
| 1346 | role_api = RoleApi( |
|
| 1347 | current_user=admin, |
|
| 1348 | session=dbsession, |
|
| 1349 | config=self.app_config, |
|
| 1350 | ) |
|
| 1351 | role_api.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
| 1352 | role_api.create_one(test_user2, workspace2, UserRoleInWorkspace.READER, False) |
|
| 1353 | role_api.create_one(test_user3, workspace, UserRoleInWorkspace.READER, False) |
|
| 1354 | uapi.save(test_user) |
|
| 1355 | uapi.save(test_user2) |
|
| 1356 | transaction.commit() |
|
| 1357 | user_id = int(admin.user_id) |
|
| 1358 | ||
| 1359 | self.testapp.authorization = ( |
|
| 1360 | 'Basic', |
|
| 1361 | ( |
|
| 1362 | '[email protected]', |
|
| 1363 | '[email protected]' |
|
| 1364 | ) |
|
| 1365 | ) |
|
| 1366 | params = { |
|
| 1367 | 'acp': 'bob', |
|
| 1368 | 'exclude_workspace_ids': [workspace2.workspace_id], |
|
| 1369 | 'exclude_user_ids': [test_user3.user_id] |
|
| 1370 | } |
|
| 1371 | res = self.testapp.get( |
|
| 1372 | '/api/v2/users/me/known_members', |
|
| 1373 | status=200, |
|
| 1374 | params=params, |
|
| 1375 | ) |
|
| 1376 | res = res.json_body |
|
| 1377 | assert len(res) == 1 |
|
| 1378 | assert res[0]['user_id'] == test_user.user_id |
|
| 1379 | assert res[0]['public_name'] == test_user.display_name |
|
| 1380 | assert res[0]['avatar_url'] is None |
|
| 1381 | ||
| 1382 | def test_api__get_user__ok_200__admin__by_name__deactivated_members(self): |
|
| 1383 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 4013-4115 (lines=103) @@ | ||
| 4010 | assert res[0]['public_name'] == test_user.display_name |
|
| 4011 | assert res[0]['avatar_url'] is None |
|
| 4012 | ||
| 4013 | def test_api__get_user__ok_200__admin__by_name_exclude_workspace_and_user(self): |
|
| 4014 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 4015 | admin = dbsession.query(models.User) \ |
|
| 4016 | .filter(models.User.email == '[email protected]') \ |
|
| 4017 | .one() |
|
| 4018 | uapi = UserApi( |
|
| 4019 | current_user=admin, |
|
| 4020 | session=dbsession, |
|
| 4021 | config=self.app_config, |
|
| 4022 | ) |
|
| 4023 | gapi = GroupApi( |
|
| 4024 | current_user=admin, |
|
| 4025 | session=dbsession, |
|
| 4026 | config=self.app_config, |
|
| 4027 | ) |
|
| 4028 | groups = [gapi.get_one_with_name('users')] |
|
| 4029 | test_user = uapi.create_user( |
|
| 4030 | email='[email protected]', |
|
| 4031 | password='pass', |
|
| 4032 | name='bob', |
|
| 4033 | groups=groups, |
|
| 4034 | timezone='Europe/Paris', |
|
| 4035 | lang='fr', |
|
| 4036 | do_save=True, |
|
| 4037 | do_notify=False, |
|
| 4038 | ) |
|
| 4039 | test_user2 = uapi.create_user( |
|
| 4040 | email='[email protected]', |
|
| 4041 | password='pass', |
|
| 4042 | name='bob2', |
|
| 4043 | groups=groups, |
|
| 4044 | timezone='Europe/Paris', |
|
| 4045 | lang='fr', |
|
| 4046 | do_save=True, |
|
| 4047 | do_notify=False, |
|
| 4048 | ) |
|
| 4049 | test_user3 = uapi.create_user( |
|
| 4050 | email='[email protected]', |
|
| 4051 | password='pass', |
|
| 4052 | name='bob3', |
|
| 4053 | groups=groups, |
|
| 4054 | timezone='Europe/Paris', |
|
| 4055 | lang='fr', |
|
| 4056 | do_save=True, |
|
| 4057 | do_notify=False, |
|
| 4058 | ) |
|
| 4059 | workspace_api = WorkspaceApi( |
|
| 4060 | current_user=admin, |
|
| 4061 | session=dbsession, |
|
| 4062 | config=self.app_config |
|
| 4063 | ||
| 4064 | ) |
|
| 4065 | workspace = WorkspaceApi( |
|
| 4066 | current_user=admin, |
|
| 4067 | session=dbsession, |
|
| 4068 | config=self.app_config, |
|
| 4069 | ).create_workspace( |
|
| 4070 | 'test workspace', |
|
| 4071 | save_now=True |
|
| 4072 | ) |
|
| 4073 | workspace2 = WorkspaceApi( |
|
| 4074 | current_user=admin, |
|
| 4075 | session=dbsession, |
|
| 4076 | config=self.app_config, |
|
| 4077 | ).create_workspace( |
|
| 4078 | 'test workspace2', |
|
| 4079 | save_now=True |
|
| 4080 | ) |
|
| 4081 | role_api = RoleApi( |
|
| 4082 | current_user=admin, |
|
| 4083 | session=dbsession, |
|
| 4084 | config=self.app_config, |
|
| 4085 | ) |
|
| 4086 | role_api.create_one(test_user, workspace, UserRoleInWorkspace.READER, False) |
|
| 4087 | role_api.create_one(test_user2, workspace2, UserRoleInWorkspace.READER, False) |
|
| 4088 | role_api.create_one(test_user3, workspace, UserRoleInWorkspace.READER, False) |
|
| 4089 | uapi.save(test_user) |
|
| 4090 | uapi.save(test_user2) |
|
| 4091 | transaction.commit() |
|
| 4092 | user_id = int(admin.user_id) |
|
| 4093 | ||
| 4094 | self.testapp.authorization = ( |
|
| 4095 | 'Basic', |
|
| 4096 | ( |
|
| 4097 | '[email protected]', |
|
| 4098 | '[email protected]' |
|
| 4099 | ) |
|
| 4100 | ) |
|
| 4101 | params = { |
|
| 4102 | 'acp': 'bob', |
|
| 4103 | 'exclude_workspace_ids': [workspace2.workspace_id], |
|
| 4104 | 'exclude_user_ids': [test_user3.user_id] |
|
| 4105 | } |
|
| 4106 | res = self.testapp.get( |
|
| 4107 | '/api/v2/users/{user_id}/known_members'.format(user_id=user_id), |
|
| 4108 | status=200, |
|
| 4109 | params=params, |
|
| 4110 | ) |
|
| 4111 | res = res.json_body |
|
| 4112 | assert len(res) == 1 |
|
| 4113 | assert res[0]['user_id'] == test_user.user_id |
|
| 4114 | assert res[0]['public_name'] == test_user.display_name |
|
| 4115 | assert res[0]['avatar_url'] is None |
|
| 4116 | ||
| 4117 | def test_api__get_user__ok_200__admin__by_name__deactivated_members(self): |
|
| 4118 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|