Exemplo n.º 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'])
Exemplo n.º 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}'])
Exemplo n.º 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'])
Exemplo n.º 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}'])
Exemplo n.º 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
Exemplo n.º 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}'])
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 9
0
def test_successful_result_without_value():
    result = ServiceResult.success()
    assert result.successful
Exemplo n.º 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
Exemplo n.º 11
0
def test_failure_without_errors():
    result = ServiceResult.failure()
    assert not result.successful
Exemplo n.º 12
0
def test_successful_result_with_value():
    result = ServiceResult.success('We did it!')
    assert result.successful
    assert result.value == 'We did it!'