| @@ 2935-2985 (lines=51) @@ | ||
| 2932 | """ |
|
| 2933 | fixtures = [BaseFixture] |
|
| 2934 | ||
| 2935 | def test_api__get_user__ok_200__admin(self): |
|
| 2936 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2937 | admin = dbsession.query(models.User) \ |
|
| 2938 | .filter(models.User.email == '[email protected]') \ |
|
| 2939 | .one() |
|
| 2940 | uapi = UserApi( |
|
| 2941 | current_user=admin, |
|
| 2942 | session=dbsession, |
|
| 2943 | config=self.app_config, |
|
| 2944 | ) |
|
| 2945 | gapi = GroupApi( |
|
| 2946 | current_user=admin, |
|
| 2947 | session=dbsession, |
|
| 2948 | config=self.app_config, |
|
| 2949 | ) |
|
| 2950 | groups = [gapi.get_one_with_name('users')] |
|
| 2951 | test_user = uapi.create_user( |
|
| 2952 | email='[email protected]', |
|
| 2953 | password='pass', |
|
| 2954 | name='bob', |
|
| 2955 | groups=groups, |
|
| 2956 | timezone='Europe/Paris', |
|
| 2957 | lang='fr', |
|
| 2958 | do_save=True, |
|
| 2959 | do_notify=False, |
|
| 2960 | ) |
|
| 2961 | uapi.save(test_user) |
|
| 2962 | transaction.commit() |
|
| 2963 | user_id = int(test_user.user_id) |
|
| 2964 | ||
| 2965 | self.testapp.authorization = ( |
|
| 2966 | 'Basic', |
|
| 2967 | ( |
|
| 2968 | '[email protected]', |
|
| 2969 | '[email protected]' |
|
| 2970 | ) |
|
| 2971 | ) |
|
| 2972 | res = self.testapp.get( |
|
| 2973 | '/api/v2/users/{}'.format(user_id), |
|
| 2974 | status=200 |
|
| 2975 | ) |
|
| 2976 | res = res.json_body |
|
| 2977 | assert res['user_id'] == user_id |
|
| 2978 | assert res['created'] |
|
| 2979 | assert res['is_active'] is True |
|
| 2980 | assert res['profile'] == 'users' |
|
| 2981 | assert res['email'] == '[email protected]' |
|
| 2982 | assert res['public_name'] == 'bob' |
|
| 2983 | assert res['timezone'] == 'Europe/Paris' |
|
| 2984 | assert res['is_deleted'] is False |
|
| 2985 | assert res['lang'] == 'fr' |
|
| 2986 | ||
| 2987 | def test_api__get_user__ok_200__user_itself(self): |
|
| 2988 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| @@ 2987-3036 (lines=50) @@ | ||
| 2984 | assert res['is_deleted'] is False |
|
| 2985 | assert res['lang'] == 'fr' |
|
| 2986 | ||
| 2987 | def test_api__get_user__ok_200__user_itself(self): |
|
| 2988 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 2989 | admin = dbsession.query(models.User) \ |
|
| 2990 | .filter(models.User.email == '[email protected]') \ |
|
| 2991 | .one() |
|
| 2992 | uapi = UserApi( |
|
| 2993 | current_user=admin, |
|
| 2994 | session=dbsession, |
|
| 2995 | config=self.app_config, |
|
| 2996 | ) |
|
| 2997 | gapi = GroupApi( |
|
| 2998 | current_user=admin, |
|
| 2999 | session=dbsession, |
|
| 3000 | config=self.app_config, |
|
| 3001 | ) |
|
| 3002 | groups = [gapi.get_one_with_name('users')] |
|
| 3003 | test_user = uapi.create_user( |
|
| 3004 | email='[email protected]', |
|
| 3005 | password='pass', |
|
| 3006 | name='bob', |
|
| 3007 | groups=groups, |
|
| 3008 | timezone='Europe/Paris', |
|
| 3009 | lang='fr', |
|
| 3010 | do_save=True, |
|
| 3011 | do_notify=False, |
|
| 3012 | ) |
|
| 3013 | uapi.save(test_user) |
|
| 3014 | transaction.commit() |
|
| 3015 | user_id = int(test_user.user_id) |
|
| 3016 | ||
| 3017 | self.testapp.authorization = ( |
|
| 3018 | 'Basic', |
|
| 3019 | ( |
|
| 3020 | '[email protected]', |
|
| 3021 | 'pass' |
|
| 3022 | ) |
|
| 3023 | ) |
|
| 3024 | res = self.testapp.get( |
|
| 3025 | '/api/v2/users/{}'.format(user_id), |
|
| 3026 | status=200 |
|
| 3027 | ) |
|
| 3028 | res = res.json_body |
|
| 3029 | assert res['user_id'] == user_id |
|
| 3030 | assert res['created'] |
|
| 3031 | assert res['is_active'] is True |
|
| 3032 | assert res['profile'] == 'users' |
|
| 3033 | assert res['email'] == '[email protected]' |
|
| 3034 | assert res['public_name'] == 'bob' |
|
| 3035 | assert res['timezone'] == 'Europe/Paris' |
|
| 3036 | assert res['is_deleted'] is False |
|
| 3037 | ||
| 3038 | def test_api__get_user__err_403__other_normal_user(self): |
|
| 3039 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|