@@ 2978-3028 (lines=51) @@ | ||
2975 | """ |
|
2976 | fixtures = [BaseFixture] |
|
2977 | ||
2978 | def test_api__get_user__ok_200__admin(self): |
|
2979 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2980 | admin = dbsession.query(models.User) \ |
|
2981 | .filter(models.User.email == '[email protected]') \ |
|
2982 | .one() |
|
2983 | uapi = UserApi( |
|
2984 | current_user=admin, |
|
2985 | session=dbsession, |
|
2986 | config=self.app_config, |
|
2987 | ) |
|
2988 | gapi = GroupApi( |
|
2989 | current_user=admin, |
|
2990 | session=dbsession, |
|
2991 | config=self.app_config, |
|
2992 | ) |
|
2993 | groups = [gapi.get_one_with_name('users')] |
|
2994 | test_user = uapi.create_user( |
|
2995 | email='[email protected]', |
|
2996 | password='pass', |
|
2997 | name='bob', |
|
2998 | groups=groups, |
|
2999 | timezone='Europe/Paris', |
|
3000 | lang='fr', |
|
3001 | do_save=True, |
|
3002 | do_notify=False, |
|
3003 | ) |
|
3004 | uapi.save(test_user) |
|
3005 | transaction.commit() |
|
3006 | user_id = int(test_user.user_id) |
|
3007 | ||
3008 | self.testapp.authorization = ( |
|
3009 | 'Basic', |
|
3010 | ( |
|
3011 | '[email protected]', |
|
3012 | '[email protected]' |
|
3013 | ) |
|
3014 | ) |
|
3015 | res = self.testapp.get( |
|
3016 | '/api/v2/users/{}'.format(user_id), |
|
3017 | status=200 |
|
3018 | ) |
|
3019 | res = res.json_body |
|
3020 | assert res['user_id'] == user_id |
|
3021 | assert res['created'] |
|
3022 | assert res['is_active'] is True |
|
3023 | assert res['profile'] == 'users' |
|
3024 | assert res['email'] == '[email protected]' |
|
3025 | assert res['public_name'] == 'bob' |
|
3026 | assert res['timezone'] == 'Europe/Paris' |
|
3027 | assert res['is_deleted'] is False |
|
3028 | assert res['lang'] == 'fr' |
|
3029 | ||
3030 | def test_api__get_user__ok_200__user_itself(self): |
|
3031 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
@@ 3030-3079 (lines=50) @@ | ||
3027 | assert res['is_deleted'] is False |
|
3028 | assert res['lang'] == 'fr' |
|
3029 | ||
3030 | def test_api__get_user__ok_200__user_itself(self): |
|
3031 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
3032 | admin = dbsession.query(models.User) \ |
|
3033 | .filter(models.User.email == '[email protected]') \ |
|
3034 | .one() |
|
3035 | uapi = UserApi( |
|
3036 | current_user=admin, |
|
3037 | session=dbsession, |
|
3038 | config=self.app_config, |
|
3039 | ) |
|
3040 | gapi = GroupApi( |
|
3041 | current_user=admin, |
|
3042 | session=dbsession, |
|
3043 | config=self.app_config, |
|
3044 | ) |
|
3045 | groups = [gapi.get_one_with_name('users')] |
|
3046 | test_user = uapi.create_user( |
|
3047 | email='[email protected]', |
|
3048 | password='pass', |
|
3049 | name='bob', |
|
3050 | groups=groups, |
|
3051 | timezone='Europe/Paris', |
|
3052 | lang='fr', |
|
3053 | do_save=True, |
|
3054 | do_notify=False, |
|
3055 | ) |
|
3056 | uapi.save(test_user) |
|
3057 | transaction.commit() |
|
3058 | user_id = int(test_user.user_id) |
|
3059 | ||
3060 | self.testapp.authorization = ( |
|
3061 | 'Basic', |
|
3062 | ( |
|
3063 | '[email protected]', |
|
3064 | 'pass' |
|
3065 | ) |
|
3066 | ) |
|
3067 | res = self.testapp.get( |
|
3068 | '/api/v2/users/{}'.format(user_id), |
|
3069 | status=200 |
|
3070 | ) |
|
3071 | res = res.json_body |
|
3072 | assert res['user_id'] == user_id |
|
3073 | assert res['created'] |
|
3074 | assert res['is_active'] is True |
|
3075 | assert res['profile'] == 'users' |
|
3076 | assert res['email'] == '[email protected]' |
|
3077 | assert res['public_name'] == 'bob' |
|
3078 | assert res['timezone'] == 'Europe/Paris' |
|
3079 | assert res['is_deleted'] is False |
|
3080 | ||
3081 | def test_api__get_user__err_403__other_normal_user(self): |
|
3082 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
@@ 997-1046 (lines=50) @@ | ||
994 | """ |
|
995 | fixtures = [BaseFixture] |
|
996 | ||
997 | def test_api__get_user__ok_200__nominal(self): |
|
998 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
999 | admin = dbsession.query(models.User) \ |
|
1000 | .filter(models.User.email == '[email protected]') \ |
|
1001 | .one() |
|
1002 | uapi = UserApi( |
|
1003 | current_user=admin, |
|
1004 | session=dbsession, |
|
1005 | config=self.app_config, |
|
1006 | ) |
|
1007 | gapi = GroupApi( |
|
1008 | current_user=admin, |
|
1009 | session=dbsession, |
|
1010 | config=self.app_config, |
|
1011 | ) |
|
1012 | groups = [gapi.get_one_with_name('users')] |
|
1013 | test_user = uapi.create_user( |
|
1014 | email='[email protected]', |
|
1015 | password='pass', |
|
1016 | name='bob', |
|
1017 | groups=groups, |
|
1018 | timezone='Europe/Paris', |
|
1019 | lang='fr', |
|
1020 | do_save=True, |
|
1021 | do_notify=False, |
|
1022 | ) |
|
1023 | uapi.save(test_user) |
|
1024 | transaction.commit() |
|
1025 | user_id = int(test_user.user_id) |
|
1026 | ||
1027 | self.testapp.authorization = ( |
|
1028 | 'Basic', |
|
1029 | ( |
|
1030 | '[email protected]', |
|
1031 | 'pass' |
|
1032 | ) |
|
1033 | ) |
|
1034 | res = self.testapp.get( |
|
1035 | '/api/v2/users/me', |
|
1036 | status=200 |
|
1037 | ) |
|
1038 | res = res.json_body |
|
1039 | assert res['user_id'] == user_id |
|
1040 | assert res['created'] |
|
1041 | assert res['is_active'] is True |
|
1042 | assert res['profile'] == 'users' |
|
1043 | assert res['email'] == '[email protected]' |
|
1044 | assert res['public_name'] == 'bob' |
|
1045 | assert res['timezone'] == 'Europe/Paris' |
|
1046 | assert res['is_deleted'] is False |
|
1047 | ||
1048 | ||
1049 | class TestAccountKnownMembersEndpoint(FunctionalTest): |