Exemplo n.º 1
0
    def test_validate_token(self, session):
        """
        Test validate_token
        """
        token = "OFNdaosofjnoasdjngonabgo"
        with pytest.raises(ApiException) as err:
            result = validate_token(None)
        assert err.value.message == "Invalid token."

        token = "OFNdaosofjnoasdjngonabgo"
        with pytest.raises(ApiException) as err:
            result = validate_token(token)
        assert err.value.message == "Invalid token."

        token = self.token_list[0].token
        with pytest.raises(ApiException) as err:
            result = validate_token(token)
        assert err.value.message == "Invalid token."

        token = self.token_list[1].token
        with pytest.raises(ApiException) as err:
            result = validate_token(token)
        assert err.value.message["token"] != token
        token = UserToken.query.filter_by(
            user_id=self.token_list[1].user_id).order_by(
                UserToken.id.desc()).first()
        assert err.value.message["token"] == token.token

        self.user_list[1].activated = True
        session.commit()

        result = validate_token(token.token)
        assert result != None
        assert result == token.token
Exemplo n.º 2
0
def get_all_packages():
    """
    Return all packages
    """
    token = request.args.get('token')
    validate_token(token)
    return response_ok_list(Package.get_all_packages())
Exemplo n.º 3
0
def save_package():
    """
    Saves package (create or update)
    """
    data = request.get_json()
    validate_data(data, {'token'})
    validate_token(data['token'])
    package = Package.save_or_create(data)
    return response_ok_obj(package)
Exemplo n.º 4
0
def get_project_permission_by_project_id_action(id):
    """
    Get project permission by it's projects id
        :param id:
    """
    token = request.args.get('token')
    validate_token(token)
    #check permissions in the future
    data = ProjectPerm.get_project_perm_all_by_project_id(ProjectPerm, id)
    return response_ok_obj(data)
Exemplo n.º 5
0
def get_module_permission_by_id_action(id):
    """
    Get module permission by it's id
        :param id:
    """
    token = request.args.get('token')
    validate_token(token)
    #check permissions in the future
    data = ModulePerm.get_module_perm_by_id(ModulePerm, id)
    return response_ok_obj(data)
Exemplo n.º 6
0
def get_module_by_name_action(name):
    """
    Get module data by it's name
    """
    token = request.args.get('token')
    name = request.args.get('name')
    validate_token(token)
    #check permissions in the future
    data = Module.get_module_by_name(name)
    return response_ok_obj(data)
Exemplo n.º 7
0
def get_module_all_by_project_id_action(id):
    """
    Get data for all modules in project
        :param id: Project ID
    """
    token = request.args.get('token')
    id = request.args.get('id')
    validate_token(token)
    #check permissions in the future
    data = Module.get_module_all_by_project_id(id)
    return response_ok_obj(data)
Exemplo n.º 8
0
def get_module_all_action():
    """
    Get data for all modules
    """
    data = request.get_json()
    if data == None or data == {}:
        raise ApiException(404, "No data suplied")
    if ('token' not in data) or (data['token'] == None):
        raise ApiException(403, "Invalid token")
    token = data['token']
    validate_token(token)
    #check permissions in the future
    resp = Module.get_module_all()
    return response_ok_list(resp)
Exemplo n.º 9
0
def build_module_action():
    """
    Update or create module
    """
    data = request.get_json()
    if data == None:
        raise ApiException(400, "data")
    if (data['token'] == None):
        raise ApiException(403, "Invalid token")
    if (('module_id' not in data) or (data['module_id'] == None)):
        raise ApiException(403, "Invalid module_id")
    else:
        moduleId = data['module_id']
    validate_token(data['token'])
    #check permissions in the future
    
    data = Module.get_module_by_id(moduleId).build_module()

    return response_ok(data)
Exemplo n.º 10
0
def update_or_create_module_action():
    """
    Update or create module
    """
    data = request.get_json()
    if data == None:
        raise ApiException(400, "data")
    if (data['token'] == None):
        raise ApiException(403, "Invalid token")
    if (('module_id' not in data) or (data['module_id'] == None)):
        moduleId = None
    else:
        moduleId = data['module_id']
    validate_token(data['token'])
    #check permissions in the future
    data = Module.create_or_update_module_by_id_from_array(moduleId, data['data'])
    if (data == None):
        raise ApiException(400, "Name already in use.")
    return response_ok_obj(data)