コード例 #1
0
 def test_permission_add(self, config_valid, admin_access_token,
                         permission_edit_books_valid):
     _response = requests.delete(
         url=
         f'{config_valid["root_url"]}/api/auth/permissions/{permission_edit_books_valid["name"]}',
         headers={
             'Content-Type': 'application/json',
             'Authorization': f'Bearer {admin_access_token}'
         },
         timeout=5,
         data=to_json(permission_edit_books_valid).encode('utf-8'))
     assert _response.status_code == 204
     _response = requests.post(
         url=f'{config_valid["root_url"]}/api/auth/permissions',
         headers={
             'Content-Type': 'application/json',
             'Authorization': f'Bearer {admin_access_token}'
         },
         timeout=5,
         data=to_json(permission_edit_books_valid).encode('utf-8'))
     print(_response.content)
     assert _response.status_code == 200
     data = from_json(_response.content.decode('utf-8'))
     assert data['name'] == permission_edit_books_valid['name']
     assert data['id'] == permission_edit_books_valid['id']
コード例 #2
0
ファイル: app_old.py プロジェクト: adriandolha/cloud-demo
def get_config():
    LOGGER.debug(app.config)
    LOGGER.debug(request.headers)
    public_config = {
        k: v
        for (k, v) in app_context().config.items() if 'password' not in k
    }
    return response({"status_code": '200', 'body': to_json(public_config)})
コード例 #3
0
    def add_user(self, user: dict, admin_access_token, config_valid):
        username = user['username']
        _response = requests.delete(url=f'{config_valid["root_url"]}/api/users/{username}',
                                    headers={'Content-Type': 'application/json',
                                             'Authorization': f'Bearer {admin_access_token}'}, timeout=3)
        assert _response.status_code == 204

        _response = requests.post(url=f'{config_valid["root_url"]}/api/auth/signup',
                                  headers={'Content-Type': 'application/json'}, timeout=5,
                                  data=to_json(user).encode('utf-8'))
        print(_response.content)
        assert _response.status_code == 200
        headers = {'Authorization': f'Bearer {admin_access_token}'}
        _response = requests.get(url=f'{config_valid["root_url"]}/api/users/{username}',
                                 headers=headers, timeout=5,
                                 data=to_json(user).encode('utf-8'))
        assert _response.status_code == 200
        return from_json(_response.content.decode('utf-8'))
コード例 #4
0
 def test_register(self, config_valid, user_valid1):
     _response = requests.post(url=f'{config_valid["root_url"]}/api/auth/signup',
                               headers={'Content-Type': 'application/json'}, timeout=5,
                               data=to_json(user_valid1).encode('utf-8'))
     print(_response.content)
     assert _response.status_code == 200
     _response_data = from_json(_response.content.decode('utf-8'))
     print(_response_data)
     assert _response_data['access_token']
     assert _response_data['roles'] == ['ROLE_USER']
コード例 #5
0
ファイル: app_old.py プロジェクト: adriandolha/cloud-demo
def get_all_users():
    LOGGER.debug('Get all users...')
    LOGGER.debug(request.headers)
    _limit = int(request.args.get('limit', 1))
    result = app_context().user_service.get_all(limit=_limit)
    return response({
        "status_code":
        '200',
        'body':
        to_json({
            "items": result['items'],
            "total": result['total']
        })
    })
コード例 #6
0
ファイル: app_old.py プロジェクト: adriandolha/cloud-demo
def metrics():
    fields = request.args.get('fields')
    if fields is None:
        fields = ''

    LOGGER.info('Metrics...')
    metrics = {}
    try:
        metrics = to_json(app_context().metrics_service.metrics(
            fields.split(',')))
    except:
        e = sys.exc_info()[0]
        LOGGER.exception('Could not get metrics...')
        print(e)
    return response({'body': metrics, 'status_code': '200'})
コード例 #7
0
    def test_update_user(self, config_valid, user_valid2, role_editor_valid, admin_access_token):
        _user = self.add_user(user_valid2, admin_access_token, config_valid)
        username = user_valid2['username']
        headers = {'Authorization': f'Bearer {admin_access_token}'}

        _user['role'] = role_editor_valid
        _response = requests.put(url=f'{config_valid["root_url"]}/api/users/{username}',
                                 headers=headers, timeout=5,
                                 data=to_json(_user).encode('utf-8'))
        print(_response.content)
        assert _response.status_code == 200
        _updated_user = from_json(_response.content.decode('utf-8'))
        print(_updated_user)
        assert _updated_user['role']['name'] == role_editor_valid['name']
        assert _updated_user['role']['default'] == role_editor_valid['default']
        for perm in _updated_user['role']['permissions']:
            assert perm in role_editor_valid['permissions']
コード例 #8
0
ファイル: app_old.py プロジェクト: adriandolha/cloud-demo
def get_user(username):
    LOGGER.debug('Get user...')
    result = app_context().user_service.get(username)
    return response({"status_code": '200', 'body': to_json(result)})
コード例 #9
0
ファイル: app_old.py プロジェクト: adriandolha/cloud-demo
def validate_user():
    LOGGER.info('Validating user...')
    _request = from_json(request.data.decode('utf-8'))
    result = app_context().user_service.validate(_request)
    return response({"status_code": '200', 'body': to_json(result)})