示例#1
0
    def __handle_response(self, response):
        '''
        Returns a service result, by which we can check later if it's a success or not
        '''
        if response.ok:
            return ServiceResult.success(response.json()['id'])

        return ServiceResult.failure(response.json()['errors'])
示例#2
0
    def __handle_response(self, response):
        '''
        Returns a service result, by which we can check later if it's a success or not
        '''
        if response.ok:
            return ServiceResult.success(response.json()['gqueries'])

        try:
            # Check if ETE returned any errors
            return ServiceResult.failure(response.json()['errors'])
        except JSONDecodeError:
            return ServiceResult.failure(
                [f'ETEngine returned a {response.status_code}'])
示例#3
0
    def __handle_response(self, response):
        '''
        Returns a service result, by which we can check later if it's
        a success or not
        '''
        if response.ok:
            if 'file' in response.json():
                return ServiceResult.success(response.json()['file'])
            return ServiceResult.failure(['No ESDL file found'])

        if response.status_code == 422:
            return ServiceResult.failure(response.json()['errors'])

        print(f'ETEngine returned a {response.status_code}')
        return ServiceResult.failure(['Something went wrong'])
示例#4
0
    def __handle_response(self, response):
        '''
        Returns a service result, by which we can check later if it's
        a success or not
        '''
        if response.ok:
            return ServiceResult.success()

        if response.status_code == 422:
            return ServiceResult.failure(response.json()['errors'])

        if response.status_code == 413:
            return ServiceResult.failure(['File is too large'])

        return ServiceResult.failure(
            [f'ETEngine returned a {response.status_code}'])
示例#5
0
def test_fail_with_with_429_from_engine():
    result = ServiceResult.failure(['ETEngine returned a 429'])

    with pytest.raises(ETMParseError) as excinfo:
        fail_with(result)

    assert excinfo.value.status_code == 429
示例#6
0
 def __handle_response(self, response, *inputs):
     '''
     Returns a service result, by which we can check later if it's a success or not
     '''
     if response.ok:
         filtered_inputs = {
             k: v
             for k, v in response.json()['inputs'].items() if k in inputs
         }
         return ServiceResult.success(filtered_inputs)
     try:
         # Check if ETE returned any errors
         return ServiceResult.failure(response.json()['errors'])
     except JSONDecodeError:
         return ServiceResult.failure(
             [f'ETEngine returned a {response.status_code}'])
示例#7
0
def test_process(happy_values):
    inputs = ['input1', 'input2']
    happy_result = ServiceResult.success(happy_values['inputs'])

    processed = context.process(happy_result)

    assert processed
    assert all((key in processed for key in inputs))
    assert processed[inputs[0]]['future'] == 3167.0
    assert processed[inputs[0]]['present'] == 3167.0
示例#8
0
def test_process_with_only_one_input():
    happy_result = ServiceResult.success({
        'happy_input': {
            "min": 0.0,
            "max": 60680.50675542846,
            "default": 3167.0,
            "user": 3167.0,
            "step": 1.0,
            "code": 'happy_input',
            "unit": "MW"
        }
    })

    processed = context.process(happy_result)

    assert processed
    assert processed['happy_input']['future'] == 3167.0
    assert processed['happy_input']['present'] == 3167.0
示例#9
0
def test_successful_result_without_value():
    result = ServiceResult.success()
    assert result.successful
示例#10
0
def test_failure_with_errors():
    result = ServiceResult.failure(errors=['Something went wrong', 'Oh no'])
    assert not result.successful
    assert len(result.errors) == 2
    assert 'Oh no' in result.errors
示例#11
0
def test_failure_without_errors():
    result = ServiceResult.failure()
    assert not result.successful
示例#12
0
def test_successful_result_with_value():
    result = ServiceResult.success('We did it!')
    assert result.successful
    assert result.value == 'We did it!'