コード例 #1
0
    def test_logs_are_chunked(self, mock_post):
        post_output_log(MOCK_LOG_URL, 'test', 'abcdefg', chunk_size=2)

        assert mock_post.call_count == 4

        mock_post.assert_any_call(MOCK_LOG_URL,
                                  json={
                                      'source': 'test',
                                      'output': b64string('ab')
                                  })
        mock_post.assert_any_call(MOCK_LOG_URL,
                                  json={
                                      'source': 'test',
                                      'output': b64string('cd')
                                  })
        mock_post.assert_any_call(MOCK_LOG_URL,
                                  json={
                                      'source': 'test',
                                      'output': b64string('ef')
                                  })
        mock_post.assert_any_call(MOCK_LOG_URL,
                                  json={
                                      'source': 'test',
                                      'output': b64string('g')
                                  })
コード例 #2
0
 def test_it_works(self, mock_post):
     post_output_log(MOCK_LOG_URL, 'test', 'test output')
     mock_post.assert_called_once_with(MOCK_LOG_URL,
                                       json={
                                           'source': 'test',
                                           'output':
                                           b64string('test output'),
                                       })
コード例 #3
0
def run_task(ctx,
             task_name,
             private_values,
             log_callback,
             flags_dict=None,
             env=None):
    '''
    Uses `ctx.run` to call the specified `task_name` with the
    argument flags given in `flags_dict` and `env`, if specified.

    The result's stdout is posted to log_callback, with `private_values`
    removed.
    '''
    flag_args = []
    if flags_dict:
        for flag, val in flags_dict.items():
            # quote val to prevent bash-breaking characters like '
            quoted_val = shlex.quote(val)
            flag_args.append(f"{flag}={quoted_val}")

    command = f'inv {task_name} {" ".join(flag_args)}'

    run_kwargs = {}
    if env:
        run_kwargs['env'] = env

    result = ctx.run(command, **run_kwargs)

    # Add both STDOUT and STDERR to the output logs
    output = format_output(result.stdout, result.stderr)

    # Replace instances of any private_values that may be present
    output = replace_private_values(output, private_values)

    post_output_log(log_callback, source=task_name, output=output)

    return result
コード例 #4
0
 def test_it_does_not_post_if_SKIP_LOGGING(self, mock_post, monkeypatch):
     monkeypatch.setenv('SKIP_LOGGING', 'true')
     post_output_log(MOCK_LOG_URL, 'test', 'test output')
     mock_post.assert_not_called()