|
@@ -945,6 +945,143 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
|
945
|
945
|
assert 'message' in res.json.keys()
|
946
|
946
|
assert 'details' in res.json.keys()
|
947
|
947
|
|
|
948
|
+ def test_api__get_workspace_member__ok_200__self(self):
|
|
949
|
+ """
|
|
950
|
+ Check obtain workspace members list with a reachable workspace for user
|
|
951
|
+ """
|
|
952
|
+ self.testapp.authorization = (
|
|
953
|
+ 'Basic',
|
|
954
|
+ (
|
|
955
|
+ 'admin@admin.admin',
|
|
956
|
+ 'admin@admin.admin'
|
|
957
|
+ )
|
|
958
|
+ )
|
|
959
|
+ res = self.testapp.get('/api/v2/workspaces/1/members/1', status=200).json_body # nopep8
|
|
960
|
+ user_role = res
|
|
961
|
+ assert user_role['role'] == 'workspace-manager'
|
|
962
|
+ assert user_role['user_id'] == 1
|
|
963
|
+ assert user_role['workspace_id'] == 1
|
|
964
|
+ assert user_role['workspace']['workspace_id'] == 1
|
|
965
|
+ assert user_role['workspace']['label'] == 'Business'
|
|
966
|
+ assert user_role['workspace']['slug'] == 'business'
|
|
967
|
+ assert user_role['user']['public_name'] == 'Global manager'
|
|
968
|
+ assert user_role['user']['user_id'] == 1
|
|
969
|
+ assert user_role['is_active'] is True
|
|
970
|
+ assert user_role['do_notify'] is True
|
|
971
|
+ # TODO - G.M - 24-05-2018 - [Avatar] Replace
|
|
972
|
+ # by correct value when avatar feature will be enabled
|
|
973
|
+ assert user_role['user']['avatar_url'] is None
|
|
974
|
+
|
|
975
|
+ def test_api__get_workspace_member__ok_200__other_user(self):
|
|
976
|
+ """
|
|
977
|
+ Check obtain workspace members list with a reachable workspace for user
|
|
978
|
+ """
|
|
979
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
980
|
+ admin = dbsession.query(models.User) \
|
|
981
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
982
|
+ .one()
|
|
983
|
+ uapi = UserApi(
|
|
984
|
+ current_user=admin,
|
|
985
|
+ session=dbsession,
|
|
986
|
+ config=self.app_config,
|
|
987
|
+ )
|
|
988
|
+ gapi = GroupApi(
|
|
989
|
+ current_user=admin,
|
|
990
|
+ session=dbsession,
|
|
991
|
+ config=self.app_config,
|
|
992
|
+ )
|
|
993
|
+ groups = [gapi.get_one_with_name('managers')]
|
|
994
|
+ user = uapi.create_user('test@test.test', password='test@test.test', do_save=True, do_notify=False, groups=groups) # nopep8
|
|
995
|
+ workspace_api = WorkspaceApi(
|
|
996
|
+ current_user=admin,
|
|
997
|
+ session=dbsession,
|
|
998
|
+ config=self.app_config,
|
|
999
|
+ )
|
|
1000
|
+ workspace = workspace_api.create_workspace('test_2', save_now=True) # nopep8
|
|
1001
|
+ rapi = RoleApi(
|
|
1002
|
+ current_user=admin,
|
|
1003
|
+ session=dbsession,
|
|
1004
|
+ config=self.app_config,
|
|
1005
|
+ )
|
|
1006
|
+ rapi.create_one(user, workspace, UserRoleInWorkspace.READER, False) # nopep8
|
|
1007
|
+ transaction.commit()
|
|
1008
|
+ user_id = user.user_id
|
|
1009
|
+ workspace_id = workspace.workspace_id
|
|
1010
|
+ admin_id = admin.user_id
|
|
1011
|
+ self.testapp.authorization = (
|
|
1012
|
+ 'Basic',
|
|
1013
|
+ (
|
|
1014
|
+ 'admin@admin.admin',
|
|
1015
|
+ 'admin@admin.admin'
|
|
1016
|
+ )
|
|
1017
|
+ )
|
|
1018
|
+ print(str(user_id) + '##' + str(workspace_id))
|
|
1019
|
+ res = self.testapp.get('/api/v2/workspaces/{}/members/{}'.format(
|
|
1020
|
+ workspace_id,
|
|
1021
|
+ user_id
|
|
1022
|
+ ), status=200).json_body
|
|
1023
|
+ user_role = res
|
|
1024
|
+ assert user_role['role'] == 'reader'
|
|
1025
|
+ assert user_role['user_id'] == user_id
|
|
1026
|
+ assert user_role['workspace_id'] == workspace_id
|
|
1027
|
+ assert user_role['is_active'] is True
|
|
1028
|
+ assert user_role['do_notify'] is False
|
|
1029
|
+
|
|
1030
|
+ self.testapp.authorization = (
|
|
1031
|
+ 'Basic',
|
|
1032
|
+ (
|
|
1033
|
+ 'test@test.test',
|
|
1034
|
+ 'test@test.test'
|
|
1035
|
+ )
|
|
1036
|
+ )
|
|
1037
|
+ res = self.testapp.get('/api/v2/workspaces/{}/members/{}'.format(
|
|
1038
|
+ workspace_id,
|
|
1039
|
+ admin_id
|
|
1040
|
+ ), status=200).json_body
|
|
1041
|
+ user_role = res
|
|
1042
|
+ assert user_role['role'] == 'workspace-manager'
|
|
1043
|
+ assert user_role['user_id'] == admin_id
|
|
1044
|
+ assert user_role['workspace_id'] == workspace_id
|
|
1045
|
+ assert user_role['is_active'] is True
|
|
1046
|
+ assert user_role['do_notify'] is True
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+ def test_api__get_workspace_member__err_400__unallowed_user(self):
|
|
1050
|
+ """
|
|
1051
|
+ Check obtain workspace members info with an unreachable workspace for
|
|
1052
|
+ user
|
|
1053
|
+ """
|
|
1054
|
+ self.testapp.authorization = (
|
|
1055
|
+ 'Basic',
|
|
1056
|
+ (
|
|
1057
|
+ 'lawrence-not-real-email@fsf.local',
|
|
1058
|
+ 'foobarbaz'
|
|
1059
|
+ )
|
|
1060
|
+ )
|
|
1061
|
+ res = self.testapp.get('/api/v2/workspaces/3/members/1', status=400)
|
|
1062
|
+ assert isinstance(res.json, dict)
|
|
1063
|
+ assert 'code' in res.json.keys()
|
|
1064
|
+ assert 'message' in res.json.keys()
|
|
1065
|
+ assert 'details' in res.json.keys()
|
|
1066
|
+
|
|
1067
|
+ def test_api__get_workspace_member__err_401__unregistered_user(self):
|
|
1068
|
+ """
|
|
1069
|
+ Check obtain workspace member info with an unregistered user
|
|
1070
|
+ """
|
|
1071
|
+ self.testapp.authorization = (
|
|
1072
|
+ 'Basic',
|
|
1073
|
+ (
|
|
1074
|
+ 'john@doe.doe',
|
|
1075
|
+ 'lapin'
|
|
1076
|
+ )
|
|
1077
|
+ )
|
|
1078
|
+ res = self.testapp.get('/api/v2/workspaces/1/members/1', status=401)
|
|
1079
|
+ assert isinstance(res.json, dict)
|
|
1080
|
+ assert 'code' in res.json.keys()
|
|
1081
|
+ assert 'message' in res.json.keys()
|
|
1082
|
+ assert 'details' in res.json.keys()
|
|
1083
|
+
|
|
1084
|
+
|
948
|
1085
|
def test_api__get_workspace_members__err_400__workspace_does_not_exist(self): # nopep8
|
949
|
1086
|
"""
|
950
|
1087
|
Check obtain workspace members list with an existing user but
|