|
@@ -875,6 +875,106 @@ class TestWorkspaceEndpoint(FunctionalTest):
|
875
|
875
|
assert 'details' in res.json.keys()
|
876
|
876
|
|
877
|
877
|
|
|
878
|
+class TestWorkspacesEndpoints(FunctionalTest):
|
|
879
|
+ """
|
|
880
|
+ Tests for /api/v2/workspaces
|
|
881
|
+ """
|
|
882
|
+ fixtures = [BaseFixture]
|
|
883
|
+
|
|
884
|
+ def test_api__get_workspaces__ok_200__nominal_case(self):
|
|
885
|
+ """
|
|
886
|
+ Check obtain all workspaces reachables for user with user auth.
|
|
887
|
+ """
|
|
888
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
889
|
+ admin = dbsession.query(models.User) \
|
|
890
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
891
|
+ .one()
|
|
892
|
+
|
|
893
|
+ workspace_api = WorkspaceApi(
|
|
894
|
+ session=dbsession,
|
|
895
|
+ current_user=admin,
|
|
896
|
+ config=self.app_config,
|
|
897
|
+ )
|
|
898
|
+ workspace_api.create_workspace('test', save_now=True) # nopep8
|
|
899
|
+ workspace_api.create_workspace('test2', save_now=True) # nopep8
|
|
900
|
+ workspace_api.create_workspace('test3', save_now=True) # nopep8
|
|
901
|
+ transaction.commit()
|
|
902
|
+ self.testapp.authorization = (
|
|
903
|
+ 'Basic',
|
|
904
|
+ (
|
|
905
|
+ 'admin@admin.admin',
|
|
906
|
+ 'admin@admin.admin'
|
|
907
|
+ )
|
|
908
|
+ )
|
|
909
|
+ res = self.testapp.get('/api/v2/workspaces', status=200)
|
|
910
|
+ res = res.json_body
|
|
911
|
+ assert len(res) == 3
|
|
912
|
+ workspace = res[0]
|
|
913
|
+ assert workspace['label'] == 'test'
|
|
914
|
+ assert workspace['slug'] == 'test'
|
|
915
|
+ workspace = res[1]
|
|
916
|
+ assert workspace['label'] == 'test2'
|
|
917
|
+ assert workspace['slug'] == 'test2'
|
|
918
|
+ workspace = res[2]
|
|
919
|
+ assert workspace['label'] == 'test3'
|
|
920
|
+ assert workspace['slug'] == 'test3'
|
|
921
|
+
|
|
922
|
+ def test_api__get_workspaces__err_403__unallowed_user(self):
|
|
923
|
+ """
|
|
924
|
+ Check obtain all workspaces reachables for one user
|
|
925
|
+ with another non-admin user auth.
|
|
926
|
+ """
|
|
927
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
928
|
+ admin = dbsession.query(models.User) \
|
|
929
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
930
|
+ .one()
|
|
931
|
+ uapi = UserApi(
|
|
932
|
+ current_user=admin,
|
|
933
|
+ session=dbsession,
|
|
934
|
+ config=self.app_config,
|
|
935
|
+ )
|
|
936
|
+ gapi = GroupApi(
|
|
937
|
+ current_user=admin,
|
|
938
|
+ session=dbsession,
|
|
939
|
+ config=self.app_config,
|
|
940
|
+ )
|
|
941
|
+ groups = [gapi.get_one_with_name('users')]
|
|
942
|
+ user = uapi.create_user('test@test.test', password='test@test.test',
|
|
943
|
+ do_save=True, do_notify=False,
|
|
944
|
+ groups=groups) # nopep8
|
|
945
|
+ transaction.commit()
|
|
946
|
+ self.testapp.authorization = (
|
|
947
|
+ 'Basic',
|
|
948
|
+ (
|
|
949
|
+ 'test@test.test',
|
|
950
|
+ 'test@test.test'
|
|
951
|
+ )
|
|
952
|
+ )
|
|
953
|
+ res = self.testapp.get('/api/v2/workspaces', status=403)
|
|
954
|
+ assert isinstance(res.json, dict)
|
|
955
|
+ assert 'code' in res.json.keys()
|
|
956
|
+ assert 'message' in res.json.keys()
|
|
957
|
+ assert 'details' in res.json.keys()
|
|
958
|
+
|
|
959
|
+ def test_api__get_workspaces__err_401__unregistered_user(self):
|
|
960
|
+ """
|
|
961
|
+ Check obtain all workspaces reachables for one user
|
|
962
|
+ without correct user auth (user unregistered).
|
|
963
|
+ """
|
|
964
|
+ self.testapp.authorization = (
|
|
965
|
+ 'Basic',
|
|
966
|
+ (
|
|
967
|
+ 'john@doe.doe',
|
|
968
|
+ 'lapin'
|
|
969
|
+ )
|
|
970
|
+ )
|
|
971
|
+ res = self.testapp.get('/api/v2/workspaces', status=401)
|
|
972
|
+ assert isinstance(res.json, dict)
|
|
973
|
+ assert 'code' in res.json.keys()
|
|
974
|
+ assert 'message' in res.json.keys()
|
|
975
|
+ assert 'details' in res.json.keys()
|
|
976
|
+
|
|
977
|
+
|
878
|
978
|
class TestWorkspaceMembersEndpoint(FunctionalTest):
|
879
|
979
|
"""
|
880
|
980
|
Tests for /api/v2/workspaces/{workspace_id}/members endpoint
|
|
@@ -945,6 +1045,143 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
945
|
1045
|
assert 'message' in res.json.keys()
|
946
|
1046
|
assert 'details' in res.json.keys()
|
947
|
1047
|
|
|
1048
|
+ def test_api__get_workspace_member__ok_200__self(self):
|
|
1049
|
+ """
|
|
1050
|
+ Check obtain workspace members list with a reachable workspace for user
|
|
1051
|
+ """
|
|
1052
|
+ self.testapp.authorization = (
|
|
1053
|
+ 'Basic',
|
|
1054
|
+ (
|
|
1055
|
+ 'admin@admin.admin',
|
|
1056
|
+ 'admin@admin.admin'
|
|
1057
|
+ )
|
|
1058
|
+ )
|
|
1059
|
+ res = self.testapp.get('/api/v2/workspaces/1/members/1', status=200).json_body # nopep8
|
|
1060
|
+ user_role = res
|
|
1061
|
+ assert user_role['role'] == 'workspace-manager'
|
|
1062
|
+ assert user_role['user_id'] == 1
|
|
1063
|
+ assert user_role['workspace_id'] == 1
|
|
1064
|
+ assert user_role['workspace']['workspace_id'] == 1
|
|
1065
|
+ assert user_role['workspace']['label'] == 'Business'
|
|
1066
|
+ assert user_role['workspace']['slug'] == 'business'
|
|
1067
|
+ assert user_role['user']['public_name'] == 'Global manager'
|
|
1068
|
+ assert user_role['user']['user_id'] == 1
|
|
1069
|
+ assert user_role['is_active'] is True
|
|
1070
|
+ assert user_role['do_notify'] is True
|
|
1071
|
+ # TODO - G.M - 24-05-2018 - [Avatar] Replace
|
|
1072
|
+ # by correct value when avatar feature will be enabled
|
|
1073
|
+ assert user_role['user']['avatar_url'] is None
|
|
1074
|
+
|
|
1075
|
+ def test_api__get_workspace_member__ok_200__other_user(self):
|
|
1076
|
+ """
|
|
1077
|
+ Check obtain workspace members list with a reachable workspace for user
|
|
1078
|
+ """
|
|
1079
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
1080
|
+ admin = dbsession.query(models.User) \
|
|
1081
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
1082
|
+ .one()
|
|
1083
|
+ uapi = UserApi(
|
|
1084
|
+ current_user=admin,
|
|
1085
|
+ session=dbsession,
|
|
1086
|
+ config=self.app_config,
|
|
1087
|
+ )
|
|
1088
|
+ gapi = GroupApi(
|
|
1089
|
+ current_user=admin,
|
|
1090
|
+ session=dbsession,
|
|
1091
|
+ config=self.app_config,
|
|
1092
|
+ )
|
|
1093
|
+ groups = [gapi.get_one_with_name('managers')]
|
|
1094
|
+ user = uapi.create_user('test@test.test', password='test@test.test', do_save=True, do_notify=False, groups=groups) # nopep8
|
|
1095
|
+ workspace_api = WorkspaceApi(
|
|
1096
|
+ current_user=admin,
|
|
1097
|
+ session=dbsession,
|
|
1098
|
+ config=self.app_config,
|
|
1099
|
+ )
|
|
1100
|
+ workspace = workspace_api.create_workspace('test_2', save_now=True) # nopep8
|
|
1101
|
+ rapi = RoleApi(
|
|
1102
|
+ current_user=admin,
|
|
1103
|
+ session=dbsession,
|
|
1104
|
+ config=self.app_config,
|
|
1105
|
+ )
|
|
1106
|
+ rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8
|
|
1107
|
+ transaction.commit()
|
|
1108
|
+ user_id = user.user_id
|
|
1109
|
+ workspace_id = workspace.workspace_id
|
|
1110
|
+ admin_id = admin.user_id
|
|
1111
|
+ self.testapp.authorization = (
|
|
1112
|
+ 'Basic',
|
|
1113
|
+ (
|
|
1114
|
+ 'admin@admin.admin',
|
|
1115
|
+ 'admin@admin.admin'
|
|
1116
|
+ )
|
|
1117
|
+ )
|
|
1118
|
+ print(str(user_id) + '##' + str(workspace_id))
|
|
1119
|
+ res = self.testapp.get('/api/v2/workspaces/{}/members/{}'.format(
|
|
1120
|
+ workspace_id,
|
|
1121
|
+ user_id
|
|
1122
|
+ ), status=200).json_body
|
|
1123
|
+ user_role = res
|
|
1124
|
+ assert user_role['role'] == 'reader'
|
|
1125
|
+ assert user_role['user_id'] == user_id
|
|
1126
|
+ assert user_role['workspace_id'] == workspace_id
|
|
1127
|
+ assert user_role['is_active'] is True
|
|
1128
|
+ assert user_role['do_notify'] is False
|
|
1129
|
+
|
|
1130
|
+ self.testapp.authorization = (
|
|
1131
|
+ 'Basic',
|
|
1132
|
+ (
|
|
1133
|
+ 'test@test.test',
|
|
1134
|
+ 'test@test.test'
|
|
1135
|
+ )
|
|
1136
|
+ )
|
|
1137
|
+ res = self.testapp.get('/api/v2/workspaces/{}/members/{}'.format(
|
|
1138
|
+ workspace_id,
|
|
1139
|
+ admin_id
|
|
1140
|
+ ), status=200).json_body
|
|
1141
|
+ user_role = res
|
|
1142
|
+ assert user_role['role'] == 'workspace-manager'
|
|
1143
|
+ assert user_role['user_id'] == admin_id
|
|
1144
|
+ assert user_role['workspace_id'] == workspace_id
|
|
1145
|
+ assert user_role['is_active'] is True
|
|
1146
|
+ assert user_role['do_notify'] is True
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+ def test_api__get_workspace_member__err_400__unallowed_user(self):
|
|
1150
|
+ """
|
|
1151
|
+ Check obtain workspace members info with an unreachable workspace for
|
|
1152
|
+ user
|
|
1153
|
+ """
|
|
1154
|
+ self.testapp.authorization = (
|
|
1155
|
+ 'Basic',
|
|
1156
|
+ (
|
|
1157
|
+ 'lawrence-not-real-email@fsf.local',
|
|
1158
|
+ 'foobarbaz'
|
|
1159
|
+ )
|
|
1160
|
+ )
|
|
1161
|
+ res = self.testapp.get('/api/v2/workspaces/3/members/1', status=400)
|
|
1162
|
+ assert isinstance(res.json, dict)
|
|
1163
|
+ assert 'code' in res.json.keys()
|
|
1164
|
+ assert 'message' in res.json.keys()
|
|
1165
|
+ assert 'details' in res.json.keys()
|
|
1166
|
+
|
|
1167
|
+ def test_api__get_workspace_member__err_401__unregistered_user(self):
|
|
1168
|
+ """
|
|
1169
|
+ Check obtain workspace member info with an unregistered user
|
|
1170
|
+ """
|
|
1171
|
+ self.testapp.authorization = (
|
|
1172
|
+ 'Basic',
|
|
1173
|
+ (
|
|
1174
|
+ 'john@doe.doe',
|
|
1175
|
+ 'lapin'
|
|
1176
|
+ )
|
|
1177
|
+ )
|
|
1178
|
+ res = self.testapp.get('/api/v2/workspaces/1/members/1', status=401)
|
|
1179
|
+ assert isinstance(res.json, dict)
|
|
1180
|
+ assert 'code' in res.json.keys()
|
|
1181
|
+ assert 'message' in res.json.keys()
|
|
1182
|
+ assert 'details' in res.json.keys()
|
|
1183
|
+
|
|
1184
|
+
|
948
|
1185
|
def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8
|
949
|
1186
|
"""
|
950
|
1187
|
Check obtain workspace members list with an existing user but
|
|
@@ -980,7 +1217,6 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
980
|
1217
|
'user_id': 2,
|
981
|
1218
|
'user_email_or_public_name': None,
|
982
|
1219
|
'role': 'content-manager',
|
983
|
|
- 'do_notify': False,
|
984
|
1220
|
}
|
985
|
1221
|
res = self.testapp.post_json(
|
986
|
1222
|
'/api/v2/workspaces/1/members',
|
|
@@ -1023,7 +1259,6 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1023
|
1259
|
'user_id': None,
|
1024
|
1260
|
'user_email_or_public_name': 'lawrence-not-real-email@fsf.local',
|
1025
|
1261
|
'role': 'content-manager',
|
1026
|
|
- 'do_notify': 'True',
|
1027
|
1262
|
}
|
1028
|
1263
|
res = self.testapp.post_json(
|
1029
|
1264
|
'/api/v2/workspaces/1/members',
|
|
@@ -1036,7 +1271,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1036
|
1271
|
assert user_role_found['workspace_id'] == 1
|
1037
|
1272
|
assert user_role_found['newly_created'] is False
|
1038
|
1273
|
assert user_role_found['email_sent'] is False
|
1039
|
|
- assert user_role_found['do_notify'] is True
|
|
1274
|
+ assert user_role_found['do_notify'] is False
|
1040
|
1275
|
|
1041
|
1276
|
res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
|
1042
|
1277
|
assert len(res) == 2
|
|
@@ -1066,7 +1301,6 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1066
|
1301
|
'user_id': None,
|
1067
|
1302
|
'user_email_or_public_name': 'Lawrence L.',
|
1068
|
1303
|
'role': 'content-manager',
|
1069
|
|
- 'do_notify': True,
|
1070
|
1304
|
}
|
1071
|
1305
|
res = self.testapp.post_json(
|
1072
|
1306
|
'/api/v2/workspaces/1/members',
|
|
@@ -1079,7 +1313,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1079
|
1313
|
assert user_role_found['workspace_id'] == 1
|
1080
|
1314
|
assert user_role_found['newly_created'] is False
|
1081
|
1315
|
assert user_role_found['email_sent'] is False
|
1082
|
|
- assert user_role_found['do_notify'] is True
|
|
1316
|
+ assert user_role_found['do_notify'] is False
|
1083
|
1317
|
|
1084
|
1318
|
res = self.testapp.get('/api/v2/workspaces/1/members', status=200).json_body # nopep8
|
1085
|
1319
|
assert len(res) == 2
|
|
@@ -1109,7 +1343,6 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1109
|
1343
|
'user_id': None,
|
1110
|
1344
|
'user_email_or_public_name': None,
|
1111
|
1345
|
'role': 'content-manager',
|
1112
|
|
- 'do_notify': True,
|
1113
|
1346
|
}
|
1114
|
1347
|
res = self.testapp.post_json(
|
1115
|
1348
|
'/api/v2/workspaces/1/members',
|
|
@@ -1134,7 +1367,6 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1134
|
1367
|
'user_id': 47,
|
1135
|
1368
|
'user_email_or_public_name': None,
|
1136
|
1369
|
'role': 'content-manager',
|
1137
|
|
- 'do_notify': True,
|
1138
|
1370
|
}
|
1139
|
1371
|
res = self.testapp.post_json(
|
1140
|
1372
|
'/api/v2/workspaces/1/members',
|
|
@@ -1159,7 +1391,6 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1159
|
1391
|
'user_id': None,
|
1160
|
1392
|
'user_email_or_public_name': 'nothing@nothing.nothing',
|
1161
|
1393
|
'role': 'content-manager',
|
1162
|
|
- 'do_notify': True,
|
1163
|
1394
|
}
|
1164
|
1395
|
res = self.testapp.post_json(
|
1165
|
1396
|
'/api/v2/workspaces/1/members',
|
|
@@ -1173,7 +1404,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1173
|
1404
|
assert user_role_found['workspace_id'] == 1
|
1174
|
1405
|
assert user_role_found['newly_created'] is True
|
1175
|
1406
|
assert user_role_found['email_sent'] is False
|
1176
|
|
- assert user_role_found['do_notify'] is True
|
|
1407
|
+ assert user_role_found['do_notify'] is False
|
1177
|
1408
|
|
1178
|
1409
|
res = self.testapp.get('/api/v2/workspaces/1/members',
|
1179
|
1410
|
status=200).json_body # nopep8
|
|
@@ -1205,10 +1436,10 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1205
|
1436
|
assert user_role['role'] == 'workspace-manager'
|
1206
|
1437
|
assert user_role['user_id'] == 1
|
1207
|
1438
|
assert user_role['workspace_id'] == 1
|
|
1439
|
+ assert user_role['do_notify'] is True
|
1208
|
1440
|
# update workspace role
|
1209
|
1441
|
params = {
|
1210
|
1442
|
'role': 'content-manager',
|
1211
|
|
- 'do_notify': False,
|
1212
|
1443
|
}
|
1213
|
1444
|
res = self.testapp.put_json(
|
1214
|
1445
|
'/api/v2/workspaces/1/members/1',
|
|
@@ -1224,7 +1455,7 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
1224
|
1455
|
assert len(res) == 1
|
1225
|
1456
|
user_role = res[0]
|
1226
|
1457
|
assert user_role['role'] == 'content-manager'
|
1227
|
|
- assert user_role['do_notify'] is False
|
|
1458
|
+ assert user_role['do_notify'] is True
|
1228
|
1459
|
assert user_role['user_id'] == 1
|
1229
|
1460
|
assert user_role['workspace_id'] == 1
|
1230
|
1461
|
|
|
@@ -1367,7 +1598,6 @@ class TestUserInvitationWithMailActivatedSync(FunctionalTest):
|
1367
|
1598
|
'user_id': None,
|
1368
|
1599
|
'user_email_or_public_name': 'bob@bob.bob',
|
1369
|
1600
|
'role': 'content-manager',
|
1370
|
|
- 'do_notify': True,
|
1371
|
1601
|
}
|
1372
|
1602
|
res = self.testapp.post_json(
|
1373
|
1603
|
'/api/v2/workspaces/1/members',
|
|
@@ -1381,7 +1611,7 @@ class TestUserInvitationWithMailActivatedSync(FunctionalTest):
|
1381
|
1611
|
assert user_role_found['workspace_id'] == 1
|
1382
|
1612
|
assert user_role_found['newly_created'] is True
|
1383
|
1613
|
assert user_role_found['email_sent'] is True
|
1384
|
|
- assert user_role_found['do_notify'] is True
|
|
1614
|
+ assert user_role_found['do_notify'] is False
|
1385
|
1615
|
|
1386
|
1616
|
# check mail received
|
1387
|
1617
|
response = requests.get('http://127.0.0.1:8025/api/v1/messages')
|
|
@@ -1418,7 +1648,6 @@ class TestUserInvitationWithMailActivatedASync(FunctionalTest):
|
1418
|
1648
|
'user_id': None,
|
1419
|
1649
|
'user_email_or_public_name': 'bob@bob.bob',
|
1420
|
1650
|
'role': 'content-manager',
|
1421
|
|
- 'do_notify': True,
|
1422
|
1651
|
}
|
1423
|
1652
|
res = self.testapp.post_json(
|
1424
|
1653
|
'/api/v2/workspaces/1/members',
|